Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Day of the Year Modification Modify the DayOfYear class, written in Programming Challenge 2, to add a constructor that takes two parameters: a string representing

Day of the Year Modification

Modify the DayOfYear class, written in Programming Challenge 2, to add a constructor that takes two parameters: a string representing a month and an integer in the range 0 through 31 representing the day of the month. The constructor should then initialize the integer member of the class to represent the day specified by the month and day of month parameters. The constructor should terminate the program with an appropriate error message if the number entered for a day is outside the range of days for the month given.

Add the following overloaded operators:

++ prefix and postfix increment operators. These operators should modify the DayOfYear object so that it represents the next day. If the day is already the end of the year, the new value of the object will represent the first day of the year.

-- prefix and postfix decrement operators. These operators should modify the DayOfYear object so that it represents the previous day. If the day is already the first day of the year, the new value of the object will represent the last day of the year.

ANSWER IN C++ HERE IS MY CODE FROM THE LAST CHALLENGE

//HEADER FILE

#ifndef DAYOFYEAR_H #define DAYOFYEAR_H #include using namespace std; class DayOfYear { private: int day; public: static const int endOfMonth[]; static const string monthName[]; void print(); void setDay(int day) { this->day = day; } }; #endif #DAYOFYEAR_H

//IMPLEMENTATION FILE

#include "DayOfYear.h" #include using namespace std; const int DayOfYear::endOfMonth[] = { 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334, 365 }; const string DayOfYear::monthName[] = { "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" }; void DayOfYear::print() { int month = 0; while (endOfMonth[month] < day) { month = (month + 1) % 12; } // DaysAtEndOfMonth >= day if (month == 0) cout << "January " << day; else cout << DayOfYear::monthName[month] << " " << day - DayOfYear::endOfMonth[month - 1]; }

//Main FILE

#include using namespace std; #include "DayOfYear.h" int main() { for (int i = 0; i < 365; i++) { // Get user input cout << "Please enter a number to convert to month and day: "; int day; cin >> day; //validation if (day < 0 || day > 365) { cout << "Invalid range for a day. Please enter a number between 1 and 365: "; exit(1); } // Class, computation, print result DayOfYear dy; dy.setDay(day); dy.print(); cout << endl; } return 0; }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Concepts Of Database Management

Authors: Joy L. Starks, Philip J. Pratt, Mary Z. Last

9th Edition

1337093424, 978-1337093422

More Books

Students also viewed these Databases questions

Question

Distinguish between a current liability and a long term debt?

Answered: 1 week ago

Question

=+2. What do they like better about its competition?

Answered: 1 week ago

Question

=+a. What kind of personality does the brand have?

Answered: 1 week ago