Question

In: Computer Science

In this assignment you will build a small C# project that uses… • A struct •...

In this assignment you will build a small C# project that uses…
• A struct
• A method with a reference parameter
• A while-loop
• A switch statement and block

instructions:

Inside the StringHandler struct add a public void method named Abbreviate.
The Abbreviate method must take a string parameter that is passed by reference.
This method will take the name of a month (January, February, etc.) as its input and
convert it to a 3-letter abbreviation of the month (JAN, FEB, etc.).

Remember to use the ref keyword to specify a parameter that is passed by reference.

- Inside the Abbreviate method use a switch statement to change the month name to its
uppercase 3-letter abbreviation. (January becomes JAN, February becomes FEB, etc.)
-The Abbreviate method returns a void data type. So, we are not returning a value.
Instead we are changing the value of the input parameter that has been passed by
reference.
-If the value of the input parameter is not a valid month name, then do not change it.

-in the Program.Main() method, use a while-loop along with Console.Write() and
Console.ReadLine() to repeatedly ask the user to enter a month name.

-When they enter “January” the console should follow by writing “JAN”, when they enter
“February” it should follow by writing write “FEB”, etc. (See the screenshot below.)

- When the user enters “QUIT” the loop should exit.
-The abbreviations should always be uppercase, but the user should be able to enter the
month names in any combination of upper and lower case.

Do not write the code on paper, please type it out.
Thank you !

Solutions

Expert Solution

Please find the following program in c# to abbreviate the user entered month to console

Note: I have added screen shots and comments inline for better understanding.

Program:

using System;

public class Program
{
   public static void Main()
   {
   //infinite loop to iterate for ever, until user enters QUIT
   while (true)
   {
       StructHandler month;
      
       //read the month name
       Console.Write("Enter the month: ");
month.name = Console.ReadLine();
  
//check if the user entered string is "QUIT"
if(month.name.Equals("QUIT"))
{
break;
}
  
string temp = month.name;
//call the Abbreviate method to convert the months
month.Abbreviate(ref month.name);
  
//check if the month name is Abbreviated or not by comparing it with
// the temp string

if (month.name.Equals(temp))
{
Console.WriteLine("Invalid month and not Abbreviated");
}
else
{
       Console.WriteLine(month.name);
}
   }
   }
}


//StructHandler struct to handle conversion
struct StructHandler
{
public string name;

public void Abbreviate(ref string name)
{
//store the temp string with all upper case letters of name variable
string temp = name.ToUpper();
switch(temp)
{
//use switch statements to match the months name and assign only
//the first 3 characters of the month to name variable

case "JANUARY":
name="JAN";
break;
  
case "FEBRUARY":
name="FEB";
break;
  
case "MARCH":
name="MAR";
break;
  
case "APRIL":
name="APR";
break;
  
case "MAY":
name="MAY";
break;
  
case "JUNE":
name="JUN";
break;
  
case "JULY":
name="JUL";
break;
  
case "AUGUEST":
name="AUG";
break;
  
case "SEPTEMBER":
name="SEP";
break;
  
case "OCTOBER":
name="OCT";
break;
  
case "NOVEMBER":
name="NOV";
break;
  
case "DECEMBER":
name="DEC";
break;
//dont change the name variable if the months are Invalid
default:
break;
}
  
}
}

Output:


Screen Shot:



Related Solutions

This project requires the student to create a record (in C++ called a struct). The record...
This project requires the student to create a record (in C++ called a struct). The record should contain several fields of different data types and should allow the user to search the records to find the student with the highest grade. In this project the student should gain an understanding of the nature of records with multiple data types, how to save the records, search the records and retrieve them.  The special problems of maintaining records of multiple data types on...
Using C++ language, create a program that uses a struct with array variables that will loop...
Using C++ language, create a program that uses a struct with array variables that will loop at least 3 times and get the below information: First Name Last Name Job Title Employee Number Hours Worked Hourly Wage Number of Deductions Claimed Then, determine if the person is entitled to overtime and gross pay. Afterwards, determine the tax and net pay. Output everything to the screen. Use functions wherever possible. Bonus Points: Use an input file to read in an unknown...
HW_6d - Write a struct object to a binary file. Create a new C++ project and...
HW_6d - Write a struct object to a binary file. Create a new C++ project and name it as:   Cats Create a Source.cpp file. Declare a struct named Cat. (in the Source.cpp file, or in a separate header file) Each Cat object has a name and age. The name data member is a c_string. The age data member is an integer. Ask the user to enter 3 cats. Use a while loop to read the information about one cat entered...
In this assignment, you will be selecting a product of interestand you will build a...
In this assignment, you will be selecting a product of interest and you will build a sales strategy to improve the sales performance for that product. A product is only one of the four pillars of a marketing strategy, and so you will need to build a thorough understanding of how the price of this product is set, what channels are available for the physical housing and distribution of the product, and how this product will be promoted (commonly referred...
In this assignment you create a small project with a base class 'Account' which represents a...
In this assignment you create a small project with a base class 'Account' which represents a generic account independent of whether the account is a Client or Vendor or Bank account. Then we will define a derived class 'BankAccount' class that represents the bank account. The BankAccount class is derived from the Account class, and extends the Account class functionality. The functionality of the BankAccount class is to handle deposits and withdrawals. You create a base class called Account and...
C++ Simple Programming Assignment you need to build off of the code below: #include using namespace...
C++ Simple Programming Assignment you need to build off of the code below: #include using namespace std; // class definition class Fraction {         // two data members         // one representing numerator         int numerator;         // other, representing denominator         int denominator;         public:                 void set (int numerator, int denominator);                 Fraction addedTo (Fraction f);                 Fraction subtract (Fraction f);                 Fraction multipliedBy (Fraction f);                 Fraction dividedBy (Fraction f);                 bool isEqualTo (Fraction f);                 void print (); }; void Fraction :: set (int numerator, int denominator) {         this...
In this assignment, which continues to build on last week's assignment, you will create a mind...
In this assignment, which continues to build on last week's assignment, you will create a mind map identifying the steps in the training process for a CRM program to help you understand the important role training plays in an organization. It further helps you understand the importance of training as you explore how training is designed, delivered, and measured for success I need more info on what a CRM is and Which training evaluation methods would you recommend to assess...
For this assignment you will implement a dynamic array. You are to build a class called...
For this assignment you will implement a dynamic array. You are to build a class called MyDynamicArray. Your dynamic array class should manage the storage of an array that can grow and shrink. The public methods of your class should be the following: MyDynamicArray(); Default Constructor. The array should be of size 2. MyDynamicArray(int s); For this constructor the array should be of size s. ~MyDynamicArray(); Destructor for the class. int& operator[](int i); Traditional [] operator. Should print a message...
For this assignment you are required to build a system using BBC Micro:bit device. You will...
For this assignment you are required to build a system using BBC Micro:bit device. You will use the Micro:bit to gather data automatically using its sensors; and make it available on the internet. You are to deliver this data in a rigorous fashion to a PC attached via USB using the onboard Python, and then to run a local Python server on the PC with appropriate web pages to serve the result locally. Remote access to the PC is not...
(C++ ONLY) You will define your own data type. It will be a struct called Fraction....
(C++ ONLY) You will define your own data type. It will be a struct called Fraction. The struct will have 2 integer fields: numerator and denominator. You will write a function called reduce that takes a Fraction as a parameter and returns that Fraction in its reduced form. For example, if the fraction 2/4 is passed to the function, the fraction 1/2 will be returned. Consider any fraction with a denominator of 1 to be in reduced form. You will...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT