USING ARRAYS AND IMPLEMENTING IN FUNCTION

So I have a function called parseDOB, DOB meaning date of birth that extracts each part of a date of birth such as day/month/year and it sets it to day month and year. Now I want to know how I can make that when I call the get month function it will give me the name of the month. This is what I have so far.

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
29
30
31
32
33
34
35
36
37
38
39
  void ATM::setMonth(int m)
    {

        if ((m<=12)&&(m>0)){
            month = m;

        }
            else {
            month = 1;
        }
int ATM::getMonth()
    {
        return month;


    }
void ATM::parseDOB(string dob)
    {
        string day = dob.substr(0,2);

        int d = stoi(day);
        ATM::setDay(d);

        string months[12];
        months[1] = "January";
        months[2] = "February";
        months[3] = "March";
        months[4] = "April";
        months[5] = "May";
        months[6] = "June";
        months[7] = "July";
        months[8] = "August";
        months[9] = "September";
        months[10] = "October";
        months[11] = "November";
        months[12] = "December";
        string month = dob.substr(3,2);
        int m = stoi(month);
        ATM::setMonth(m);
1
2
3
4
5
6
7
8
9
std::string ATM::month_string() const
{
    static std::string month_name[] = { "", "January", "February", "March", "April",
                                        "May", "June", "July", "August", "September",
                                        "October", "November", "December" } ;

    if( month < 1 || month > 12 ) return "invalid month " ;
    else return month_name[month] ;
}
Topic archived. No new replies allowed.