operator overloading & conversions

I am attempting to convert from an integer called day and translate it to a string consisting of a month followed by a day. For example,
Day 2 would be January 2
Day 32 would be February 1
Day 365 would be December 31

How can I create static member variables that holds strings that can sort of assist in the translation from an into to this month-day format?
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
27
28
class DayOfYear
{
private:
  int day;
  static string monthday
  Void conversion();
public:
  DayOfYear()
  {
     day = 1;
  }
  DayOfYear(int d)
  {
     day = d;
  }
  operator string()
  {
    return day;
  }
  int getDay()
    return day;
  }
  string getMonthday()
  {
     return monthday;
  }

};

That is what I have so far in my header file.. I'm uncertain of how to use various static strings to do this month-date conversion.
Last edited on
What you are doing is what we call a 'Count of Days.' Think of how the addition of the months total days would relate to the number of days. For example a number less than a total of sum of months would give you the month, after the subtraction of two you have the final day. This would be two Arrays of 12 entries each, one array would have the month titles and the other would have the number of days in each month. This also could be a multi-dimensional array.

Loop through indexes of the months and test against the number. If you stop at the month that should make your total work. You have the index in the string array of the month.

As for a list of tranctions, you might look into a vector or list in the Libraries of C++. I don't know how much detail you want to store for a 'Transaction.' so I cant go much further than that.
Im not sure what you when by "a number less than a total of sum of months would give you the month, after the subtraction of two of have the final day."
Topic archived. No new replies allowed.