Question
Please format the following code into a header file, implementation file, and main file. USING C++ ***********PLEASE MAKE SURE THE CODE COMPILES*************** I am having
Please format the following code into a header file, implementation file, and main file. USING C++
***********PLEASE MAKE SURE THE CODE COMPILES*************** I am having issues putting this code into separate files. Please help
#include
class DayOfYear { public: static const int daysAtEndOfMonth[]; static const string monthName[]; void print(); void setDay(int day) { this->day = day; }
private: int day;
};
const int DayOfYear::daysAtEndOfMonth[] = { 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" };
//****************************************************
// DayOfYear::print. Convert and print day of year *
//****************************************************
void DayOfYear::print() { int month = 0; while (daysAtEndOfMonth[month] < day)
month = (month + 1) % 12;
// DaysAtEndOfMonth >= day if (month == 0) cout << "January " << day; else cout << DayOfYear::monthName[month] << " " << day - DayOfYear::daysAtEndOfMonth[month - 1]; } //=================================== Main Program ============================================== int main() { // Tell user what program does cout << "This program converts a day given by a number 1 through 365" << " into a month and a day."; // Get user input cout << " Enter a number: "; int day; cin >> day;
if (day < 0 || day > 365) { cout << "Invalid range for a day."; exit(1); } // Do computation and print result DayOfYear dy; dy.setDay(day); dy.print(); return 0;
}
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started