
Concept explainers
Define a class called Month that is an abstract data type for a month. Your class will have one member variable of type int to represent a month (1 for January, 2 for February, and so forth). Include all the following member functions: a constructor to set the month using the first three letters in the name of the month as three arguments, a constructor to set the month using an integer as an argument (1 for January, 2 for February, and so forth), a default constructor, an input function that reads the month as an integer, an input function that reads the month as the first three letters in the name of the month, an output function that outputs the month as an integer, an output function that outputs the month as the first three letters in the name of the month, and a member function that returns the next month as a value of type Month. Embed your class definition in a test

Program plan:
1 . The following variables are used in the program:
- monthvariable of integer data type is used to store the month.
2. The following methods are used in the program:
- Default constructor.
- Constructor having one integer argument.
- Constructor having three characters arguments.
- input() function to take the month number from the user.
- inputMonthLetter() function to take the month's first three letters from the user.
- getMonth() function to return the month number.
- outputMonthLetter() function to display the month first three-letter.
- nextMonth() function to return the next month.
Program description:
The main purpose of the program is to create the constructor to initialize the class member variable using the integer argument and the first three letters of the month. Also, display the next month. Test all the class member functions in a test program.
Explanation of Solution
Program:
//including essential header file #include <iostream> //using standard namespace using namespace std; //Month class class Month { public: int month; //default constructor Month() { //initialize the month to 1 month = 1; } //constructor to set the month by number Month(int monthNumber) { //set the month to the monthNumber month = monthNumber; } //constructor to set the month number using the Month letters Month (char monthLetter1, char monthLetter2, char monthLetter3) { //when the monthLetter is jan if ((monthLetter1 == 'j') && (monthLetter2 == 'a') && (monthLetter3 == 'n')) { //set the month to 1 month = 1; } //when the monthLetter is feb if ((monthLetter1 == 'f') && (monthLetter2 == 'e') && (monthLetter3 == 'b')) { //set the month to 2 month = 2; } //when the monthLetter is mar if ((monthLetter1 == 'm') && (monthLetter2 == 'a') && (monthLetter3 == 'r')) { //set the month to 3 month = 3; } //when the monthLetter is apr if ((monthLetter1 == 'a') && (monthLetter2 == 'p') && (monthLetter3 == 'r')) { //set the month to 4 month = 4; Month(month); getMonth(); } //when the monthLetter is may if ((monthLetter1 == 'm') && (monthLetter2 == 'a') && (monthLetter3 == 'y')) { //set the month to 5 month = 5; } //when the monthLetter is jun if ((monthLetter1 == 'j') && (monthLetter2 == 'u') && (monthLetter3 == 'n')) { //set the month to 6 month = 6; } //when the monthLetter is jul if ((monthLetter1 == 'j') && (monthLetter2 == 'u') && (monthLetter3 == 'l')) { //set the month to 7 month = 7; } //when the monthLetter is aug if ((monthLetter1 == 'a') && (monthLetter2 == 'u') && (monthLetter3 == 'g')) { //set the month to 8 month = 8; } //when the monthLetter is sep if ((monthLetter1 == 's') && (monthLetter2 == 'e') && (monthLetter3 == 'p')) { //set the month to 9 month = 9; } //when the monthLetter is oct if ((monthLetter1 == 'o') && (monthLetter2 == 'c') && (monthLetter3 == 't')) { //set the month to 10 month = 10; } //when the monthLetter is nov if ((monthLetter1 == 'n') && (monthLetter2 == 'o') && (monthLetter3 == 'v')) { //set the month to 11 month = 11; } //when the monthLetter is dec if ((monthLetter1 == 'd') && (monthLetter2 == 'e') && (monthLetter3 == 'c')) { //set the month to 12 month = 12; } } void input() { cout<<endl<< "Enter the month number: "; cin>> month; while (month < 1 || month > 12) { cout<< "Invalid month number. Month number must be between 1 to 12." <<endl; cout<< "Enter the month number again: "; cin>> month; } } void inputMonthLetter() { //char letter1, letter2, letter3; char letter[4]; cout<<endl<< "Enter the first three letters of the month: "; cin>> letter; Month (letter[0], letter[1], letter[2]); } int getMonth() { return month; } void outputMonthLetter() { if (month == 1) { cout<< "The month is Jan"; } if (month == 2) { cout<< "The month is Feb"; } if (month == 3) { cout<< "The month is Mar"; } if (month == 4) { cout<< "The month is April"; } if (month == 5) { cout<< "The month is May"; } if (month == 6) { cout<< "The month is June"; } if (month == 7) { cout<< "The month is July"; } if (month == 8) { cout<< "The month is August"; } if (month == 9) { cout<< "The month is Sep"; } if (month == 10) { cout<< "The month is Oct"; } if (month == 11) { cout<< "The month is Nov"; } if (month == 12) { cout<< "The month is Dec"; } } //member function to return the next month as Month type Month nextMonth() { int m = ((month % 12 ) + 1 ); return Month(m); } }; int main() { //create objects of the class Month m1, m3; m1.input(); m1.outputMonthLetter(); m3=m1.nextMonth(); cout<<endl<< "The next month is: "<<m3.getMonth(); Month m2, m4; m2.inputMonthLetter(); cout<<endl<< "month is: " << m2.getMonth(); m4 = m2.nextMonth(); cout<<endl<< "The next month is: " << m4.getMonth(); return 0; }
Explanation:
In the above program, a default constructor is created which initializes the variable month. Another constructor that takes an integer parameter also initializes the variable month. A third constructor takes three-character arguments. This constructor matches these arguments with the first three letters of each month and then initializes the variable month accordingly.
Inside the main() method, objects of the class Month are created. The input() method is used to take user input for the month in the form of an integer. The outputMonthLetter() is used to output the first three letters of the month corresponding to the user input. The nextMonth() function returns the month in the form of the object of the class Month. The inputMonthLetter() method is used to take user input for the first three letters of the name of the month. This method calls the parameterized constructor that takes three-character arguments.The getMonth() method returns the variable month. The nextMonth() function returns the month in the form of the object of the class Month.
Sample output:
Want to see more full solutions like this?
Chapter 7 Solutions
Absolute C++
Additional Engineering Textbook Solutions
Starting Out With Visual Basic (8th Edition)
Java How to Program, Early Objects (11th Edition) (Deitel: How to Program)
Electric Circuits. (11th Edition)
Management Information Systems: Managing The Digital Firm (16th Edition)
Web Development and Design Foundations with HTML5 (8th Edition)
Starting Out with Programming Logic and Design (5th Edition) (What's New in Computer Science)
- Can I get help with this case please, thank youarrow_forwardI need help to solve the following, thank youarrow_forwardreminder it an exercice not a grading work GETTING STARTED Open the file SC_EX19_EOM2-1_FirstLastNamexlsx, available for download from the SAM website. Save the file as SC_EX19_EOM2-1_FirstLastNamexlsx by changing the “1” to a “2”. If you do not see the .xlsx file extension in the Save As dialog box, do not type it. The program will add the file extension for you automatically. With the file SC_EX19_EOM2-1_FirstLastNamexlsx still open, ensure that your first and last name is displayed in cell B6 of the Documentation sheet. If cell B6 does not display your name, delete the file and download a new copy from the SAM website. Brad Kauffman is the senior director of projects for Rivera Engineering in Miami, Florida. The company performs engineering projects for public utilities and energy companies. Brad has started to create an Excel workbook to track estimated and actual hours and billing amounts for each project. He asks you to format the workbook to make the…arrow_forward
- Need help with coding in this in python!arrow_forwardIn the diagram, there is a green arrow pointing from Input C (complete data) to Transformer Encoder S_B, which I don’t understand. The teacher model is trained on full data, but S_B should instead receive missing data—this arrow should not point there. Please verify and recreate the diagram to fix this issue. Additionally, the newly created diagram should meet the same clarity standards as the second diagram (Proposed MSCATN). Finally provide the output image of the diagram in image format .arrow_forwardPlease provide me with the output image of both of them . below are the diagrams code make sure to update the code and mentionned clearly each section also the digram should be clearly describe like in the attached image. please do not provide the same answer like in other question . I repost this question because it does not satisfy the requirment I need in terms of clarifty the output of both code are not very well details I have two diagram : first diagram code graph LR subgraph Teacher Model (Pretrained) Input_Teacher[Input C (Complete Data)] --> Teacher_Encoder[Transformer Encoder T] Teacher_Encoder --> Teacher_Prediction[Teacher Prediction y_T] Teacher_Encoder --> Teacher_Features[Internal Features F_T] end subgraph Student_A_Model[Student Model A (Handles Missing Values)] Input_Student_A[Input M (Data with Missing Values)] --> Student_A_Encoder[Transformer Encoder E_A] Student_A_Encoder --> Student_A_Prediction[Student A Prediction y_A] Student_A_Encoder…arrow_forward
- C++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage LearningC++ for Engineers and ScientistsComputer ScienceISBN:9781133187844Author:Bronson, Gary J.Publisher:Course Technology PtrMicrosoft Visual C#Computer ScienceISBN:9781337102100Author:Joyce, Farrell.Publisher:Cengage Learning,
- EBK JAVA PROGRAMMINGComputer ScienceISBN:9781337671385Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENTProgramming Logic & Design ComprehensiveComputer ScienceISBN:9781337669405Author:FARRELLPublisher:CengageSystems ArchitectureComputer ScienceISBN:9781305080195Author:Stephen D. BurdPublisher:Cengage Learning




