Modification of Count of Days Program

Hi, I have written a working project 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.

Now I must modify it this program:

DayOfYear.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
class DayOfYear
{
    private:
        int day;
        static const string Month[12];                            //static member variables
        static const int MonthDay[12];

    public:
        //Convert constructor from int and modifies the static member variable
        DayOfYear()
        {
            day = 0;
        }
        DayOfYear(int d)
        {
            day = d;
        }
        int getDay()
        {
            return day;
        }

        //member function
        void printDayDate(int);
        
};

DayOfYear.cpp
1
2
3
4
5
6
//Set days of each month into an array
const int DayOfYear::MonthDay[] = {31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334, 365};

//Set the name of each month into an array
const string DayOfYear::Month[] = {"January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"};


Can someone please explain to me what is meant by "constructor taking in 2 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." Is it something like this:
1
2
3
4
5
6
7
8
9
10
11
12
13
        
        DayOfYear(string Month[],int d)
        {
            int index;
            string Month[index];
            day = d;
        }
        
        // overloaded arithmetic operators.
        DayOfYear operator++();
        DayOfYear operator++(int);
        DayOfYear operator--();
        DayOfYear operator--(int);


Plus I must also include ++ prefix and postfix increment operators that 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.
Last edited on
Can someone please explain to me what is meant by ...
You should be able write code like:
 
DayOfYear date1("January", 1);
but I don't know why the range is 0..31

The constructor you wrote above isn't quite right. It should take a string and an int, that's it.
Yeah they should be able to construct a DayOfYear object like this:
 
DayOfYear mydays("March",5);


Your constructor must take 2 arguments for the month and day:
 
DayOfYear (string month_,int day_);


Then it could possibly check the "month" string against your Month index, like this:
1
2
3
4
5
6
7
8
9
10
DayOfYear (string month_,int day_)
{
 int count=0;

while (month_ != Month[count])
{count++;}

int result = Monthday[count] + day_
day = result;
}


This would result in the coinciding MonthDay value being added to their day_ value, and finally assigned to the day class data member.
Hope that made sense >.>
flclempireIf you want to help with homework, you need to find a way to help without actually doing it.
Topic archived. No new replies allowed.