Programming Homework Help

Programming Homework Help. DVC Private Variables Class Definition & Default Constructor C Programming Exercise

 

Assignment

Write a class called Month that represents a calendar month. The class should have the following data field:

  • An int representing the number of the month (1 for January, 2 for February, etc.).

Define and write the code for these member functions:

  • A constructor that sets the month from an integer parameter (if 1 is passed, “January” is set, etc.).
  • A constructor that sets the month from a string parameter (“January” as a string, etc.).
  • A default constructor that sets the month to a default month (any default of your choice).
  • An output function that returns the name of the month as a string.
  • An output function that returns the number of the month.

The file is included in this module. The starter file has the beginnings of the class definition at the top of the file.

For the constructors, if an invalid value is passed (month greater than 12, or less than 1, or an invalid string), set the month to a default value of your choice.

Testing Your Code

Write a short main() that creates an class of type Month, and sets the month with one of the constructors. Then, write a ‘cout’ statement that prints the month using the string output function you wrote above (no need to test the output function for a number — that one should be trivial!).

What to Submit in Canvas

To complete this lab, submit these files in Canvas:

  • Your .cpp file that contains your Month class definition and functions, and your test code in main().
  • Optionally, you can write your class in a separate file (.h), submit this as well. If you wrote both your class and test code in main() you will only need to submit one file.

Programming Homework Help