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

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...
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...
Note: This is a single file C++ project - No documentation is required on this assignment....
Note: This is a single file C++ project - No documentation is required on this assignment. Write a Fraction class whose objects will represent Fractions. Note: You should not simplify (reduce) fractions, you should not use "const," and all of your code should be in a single file. In this single file, the class declaration will come first, followed by the definitions of the class member functions, followed by the client program. You must provide the following member functions: A...
*********C++ Program************ This assignment is the continuation of project 4, with the modification and improvement with...
*********C++ Program************ This assignment is the continuation of project 4, with the modification and improvement with the following modifications: In Frac.h, replace the methods addition (const Fraction & ), subtraction( const Fraction& ), multiply( const Fraction & ), divide( const Fraction & ), void printFraction() by overloading operators +, -, *, /, << respectively. Add overloading operators > and < so that they can compare two Fractions. Write your own implementation file which is named Frac2.cpp to replace Frac.cpp and...
Project Assignment The purpose of this assignment is for you to gain practice in applying the...
Project Assignment The purpose of this assignment is for you to gain practice in applying the concepts and techniques we learned in class. In order to complete the assignment, please do the following: 1. find or create a data set containing values of at least one interval or ratio variable for at least one-hundred cases (n >= 100); 1 2. provide basic descriptive statistics to summarize the central tendency and variability of the data; 3. provide at least one table...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT