Question: Month Class Design a class named Month. The class should have the following private members: Name : A string object that holds the name of

Month Class

Design a class named Month. The class should have the following private members:

Name: A string object that holds the name of a month, such as January, February, etc.

monthNumber: An integer variable that holds the number of the month. For example, January would be 1, February would be 2, etc. Valid values for this variable are 1 through 12.

In addition, provide the following member functions:

A default constructor that sets monthNumber to 1 and name to January.

A constructor that accepts the name of the month as an argument. It should set name to the value passed as the argument and set monthNumber to the correct value.

A constructor that accepts the number of the month as an argument. It should set monthNumber to the value passed as the argument and set name to the correct month name.

Appropriate set and get functions for the name and monthNumber member variables.

Prefix and postfix overloaded ++ operator functions that increment monthNumber and set name to the name of next month. If monthNumber is set to 12 when these functions execute, they should set monthNumber to 1 and name to January.

Overload the = operator. It should set both the monthName and monthNumber variables.

Overload cout s > operator to work with the Month class. Demonstrate the class in a program.

o >> cin s stream extraction operator. This operator should prompt the user for the name of a month. In the same operation, it should also set the monthName and monthNumber variables.

Requirements

You can assume the name of the month will be typed in with the first letter capitalized and all other letters lowercase.

The cins >> operator should read the months name (make sure you update the number).

Write the code for assigning to the month and monthNumber attributes in the set functions, and just call the appropriate set function from the constructors.

Use the main function below.

int main()

{

Month m1("February");

Month m2,m3, m4;

cout

cout

cout

cout

cout

cout

cout

cin >> m4;

cout

system ("Pause") return 0;

}

Figure 1 - Sample Output

 Month Class Design a class named Month. The class should have

February The name is February and the number is 2 The name is March and the number is 3 The name is March and the number is 3 The name is April and the number is 4 The name is March and the number is 3 Enter the name of a month: April The name is April and the number is 4 Press any key to continue

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!