Question: C++ Assuming that a year has 365 days, write a class named DayOfYearthat takes an integer representing a day of the year and translates it
C++
Assuming that a year has 365 days, write a class named DayOfYearthat takes an integer representing a day of the year and translates it to a string consisting of the month followed by day of the month. For example,
Day 2 would be January 2. Day 32 would be February 1. Day 365 would be December 31.
The constructor for the class should take as parameter an integer representing the day of the year, and the class should have a member function print() that prints the day in the monthday format. The class should have an integer member variable to represent the day and should have static member variables holding string objects that can be used to assist in the translation from the integer format to the month-day format.
Test your class by inputting various integers representing days and printing out their representation in the monthday format.
The program should reject values outside of the range of 1 and 365. DO NOT USE A LOOP, simply display an Invalid day entered message.
----------------------------------
#ifndef DAYOFYEAR_H #define DAYOFYEAR_H
#include
class DayOfYear{ private: static const string months[]; static const int range[]; int day_; public: DayOfYear(int); void print() const;
};
#endif
-----------------------------
#include
using namespace std;
int main(){ int response; cout << "Enter a day between 1 and 365: "; cin >> response; DayOfYear day = response; day.print(); return 0; }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
