I need help! I am very confused on this section of C++ and have three problems d
ID: 3636713 • Letter: I
Question
I need help! I am very confused on this section of C++ and have three problems due. I don't know how to even begin let alone have a working program.Problem: Assuming that a year has 365 days, write a class named "DayOfYear" that 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, and Day 365 would be December 31.
The constructor of the class should take as parameter an integer representing the day of the year, and the clas should have a member function "print()" that prints the day in the month-day format. The class should have an integer member variable to represent the day, and should have static member variables holding strings that can be used to assist in the translation from the integer format to the month-day format.
Explanation / Answer
please rate - thanks
#include <iostream>
#include <string>
using namespace std;
class DayOfYear
{static string mth[12];
static int days[12];
private:
int doy;
public:
DayOfYear(int d)
{doy=d;
}
void DayOfYear::print()
{int i=0,d;
d=doy;
while(d>0)
{d-=days[i];
i++;
}
i--;
d+=days[i];
cout<<"day "<<doy<<" would be "<<mth[i]<<" "<<d<<endl;
}
};
string DayOfYear:: mth[12]={"January","February","March","April","May","June","July","August",
"September","October","November","December"};
int DayOfYear::days[12]={31,28,31,30,31,30,31,31,30,31,30,31};
int main()
{
int doy;
cout<<"Enter the day of year: ";
cin>>doy;
DayOfYear d(doy);
d.print();
system("pause");
return 0;
}