Define a class called Month that is an abstract data type for a month. Your clas
ID: 3657804 • Letter: D
Question
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.Explanation / Answer
The "test program" is basically a driver. Your class itself won't do anything if you just run it on its own, so you create a program that actually uses the Month class to see if it behaves how you would expect.
What you should do is write a program that creates a Month object using all of the different constructors, and then uses those created objects to test all of the other functions you wrote. So maybe your main would contain something like this:
#Include "month.h"
int main () {
Month month1;
Month month2('j','u','n');
Month month3(3);
//Test functions here
return 0;
}
So you include your Month header file (or .cpp file if you have no header file) and then your test program (aka main() ) can create Month objects and then manipulate them.
I wasn't sure if your input/output functions did their input/output through main() or interacted directly with the user, so I didn't include them.
Does that help?
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.