Assignment: Write a C++ program that uses C++ classes. The program processes data for soccer players, inputs data from a file and outputs data to a file.
1. Submit a UML diagram of the class definition for the following problem defining a utility class named Month. You can draw the diagram using any tool or you can draw on paper, scan and send the image file.
2. Write a class named Month. The class should have an integer field named monthNumber that holds the number of the month (January is 1, February is 2, etc.). Also provide the following functions:
A default constructor that sets the monthNumber field to 1.
A constructor that accepts the number of month as an argument and sets the monthNumber field to the passed value. Set the monthNumber to 1 if the passed argument's value is not a value between 1 and 12.
A constructor that accepts the name of month, such as "January" as an argument and sets the monthNumber field to the correct corresponding value. Make sure this is not case sensitive, so entering January will return the same value as if JaNUary was entered. If an invalid month is entered, set the monthNumber to 1.
A setMonthNumber function that accepts an integer argument to assign to the monthNumber field. Set the monthNumber to 1 if the passed argument's value is not a value between 1 and 12.
A getMonthNumber function that returns the value in the monthNumber field.
A getMonthName function that returns the name of the month. For example, if the monthNumber field is 1, then this function will return "January". Note that this function does not accept any parameters. It looks up the monthNumber field to make its decision.
A function named print that prints the month number and the month name.
Write a main program that uses the class Month and test various operations on the objects of the class Month. Perform a series of operations to test each of the functions and the constructors. Make sure to prompt the user to enter a value for monthNumber as you test your code. As part of your testing, generate a set of random numbers for month number (between 1 and 12) and display the month number along with the month name.
Here is a possible sample run:
Using the default constructor - Month number = 1 Please enter a month number between 1 and 12: 9 Using the constructor with a parameter - Month number = 9 Now please enter a month name: aprillll Using the constructor that accepts a month name: January Enter a number representing a month number 12 Month number is: 12 Month name for the number you entered is: December Testing the print function 12 December Testing the functions to assign a month number and check month name Generating a random number between 1 and 12: 8 Month name is: August Generating a random number between 1 and 12: 2 Month name is: February Generating a random number between 1 and 12: 12 Month name is: December Generating a random number between 1 and 12: 4 Month name is: April
Another run:
Using the default constructor - Month number = 1 Please enter a month number between 1 and 12: 0 Using the constructor with a parameter - Month number = 1 Now please enter a month name: MAy Using the constructor that accepts a month name: May Enter a number representing a month number 123 Month number is: 1 Month name for the number you entered is: January Testing the print function 1 January Testing the functions to assign a month number and check month name Generating a random number between 1 and 12: 7 Month name is: July Generating a random number between 1 and 12: 3 Month name is: March Generating a random number between 1 and 12: 7 Month name is: July Generating a random number between 1 and 12: 5 Month name is: May
It is not our intention to break the school's academic policy. Posted solutions are meant to be used as a reference
and should not be submitted as is. We are not held liable for any misuse of the solutions.
Please see the frequently asked questions page
for further questions and inquiries.
Kindly complete the form.
Please provide a valid email address and we will get back to you within 24 hours.
Payment is through PayPal, Buy me a Coffee
or Cryptocurrency.
We are a nonprofit organization however we need funds to keep this organization operating
and to be able to complete our research and development projects.