Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Modify the DayofYear class, written in the earlierprogramming challenging, to ad

ID: 3644063 • Letter: M

Question

Modify the DayofYear class, written in the earlierprogramming challenging, to add a constructor that take twoparameter: a string representing a month and an integer in therange o through 31 representing the day of the month. Theconstructor should then initialize the integer member of the classto represent the day specified by the month and day of monthparameters. The constructor should terminate the program with anappropriate error message if the number enter for a day is outsidethe range of days for the month given.
Add the following overload operators:

++ prefix and postfixincrement operators. These operators should modifythe DayofYear object so that it represent the next day. If the dayis already the end of the year, the new value of the object willrespresent the first day of the year.



-- prefix and postfix decrement operators.These operator should modify the DayofYear object sothat it represent the previous day. If the day is already thefirst day of the year, the new value of the object will representthe last dayof the year.

Explanation / Answer

#include #include using namespace std; class dayOfYear { private: int userDay; // private class member to hold user input string month; public: dayOfYear(); //Constructor void setMonth(string); //set the month string setUserMonth(); // set user month void setDay(int); // Function to set day int getDay()const; // Function to recieve day for later functions void print() const; // Print() function for printing the month-day reps }; dayOfYear::dayOfYear() : userDay(0) { } //Constructor initializing userDay to 0, no other initializations. void dayOfYear::setMonth(string month) { this -> month = month; } void dayOfYear::setDay(int userDay) { this -> userDay = userDay; } // Setting user input to userDay int dayOfYear::getDay() const { return this -> userDay; } // Return this->userDay to calling function void dayOfYear::print() const { // Print out all relevant information static string months[] = {"", "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"}; int error = 0; /*********************************** | IF block to get month, and later | | to be used for the day calulation | ***********************************/ while(true) { if((month.compare(months[1]) == 0) && userDay 0) //January break; if((month.compare(months[2]) == 0) && userDay 0) break; if((month.compare(months[3]) == 0 )&& userDay 0) break; if((month.compare(months[4]) == 0) && userDay 0) break; if((month.compare(months[5]) == 0) && userDay 0) break; if((month.compare(months[6]) == 0) && userDay 0) break; if((month.compare(months[7]) == 0) && userDay 0) break; if((month.compare(months[8]) == 0) && userDay 0) break; if((month.compare(months[9]) == 0) && userDay 0) break; if((month.compare(months[10]) == 0) && userDay 0) break; D.setDay(getUserDay()); // Set the day by calling getUserDay, than transferring to setDay to do so. printC(D); // printC is passing the class dayOfYear which is D as it's argument so it can access the elements in the class return 0; }
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote