I need help with my code, i can't figure it out by myself. If someone can do it for me, I CAN PAY but be reasonable. You can email me at desi_jatt92@yahoo.com
This is the question
You can assume the name of the
month will be typed in with the first letter capitalized and all other letters lowercase. The cin’s
">>" operator should read the month’s name (make sure you update the number). Write the code
for assigning to the month and monthNumber attributes in the set functions, and just call the
appropriate set function from the constructors.

#include <iomanip>
#include <cstring>
#include "Month.h"
using namespace std;



int main() 
{ 
 Month m1("February"); 
 Month m2,m3, m4; 

 cout <<m1.getMonthName() <<endl; 
 cout <<m1.getMonthNumber()<<endl; 

 cout<<endl; 
 cout <<m1; 

 cout<<endl; 
 m2 =++m1; 
 cout <<m1; 
 cout <<m2; 

 cout<<endl; 
 m3 =m1++; 
 cout <<m1; 
 cout <<m3; 

 cout<<endl; 
 cout<<"Enter the name of a month: "; 
 cin>> m4; 

 cout <<m4; 

 return 0; 
}

This is the Month.h file

#include <cstring>

class Month
{
private:
    char *monthName;
    int monthNumber;
public:

    Month(char *m, int num)
    {
        monthName = new char[strlen(m) + 1];
        strcpy(monthName, m);
        monthNumber = num;
    }

    Month(const Month &obj)
    {
        monthName = new char[strlen(obj.monthName) + 1];
        strcpy(monthName, obj.monthName);
        monthNumber = obj.monthNumber;
    }

    ~Month()
    {
        delete [] monthName;
    }

    const char *getMonthName()
    {
        return monthName;
    }

    const int getMonthNumber()
    {
        switch (monthNumber) {
            case 1:
                  printf("January");
                  break;
            case 2:
                  printf("February");
                  break;
            case 3:
                  printf("March");
                  break;
            case 4:
                  printf("April");
                  break;
            case 5:
                  printf("May");
                  break;
            case 6:
                  printf("June");
                  break;
            case 7:
                  printf("July");
                  break;
            case 8:
                  printf("August");
                  break;
            case 9:
                  printf("September");
                  break;
            case 10:
                  printf("October");
                  break;
            case 11:
                  printf("November");
                  break;
            case 12:
                  printf("December");
                  break;
            default:
                  printf("unknown month");
                  break;
      }

    }


};
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.