What I am trying to achieve is to create a postfix and prefix overloaded ++ function that increments monthnumber and set name to the name of the next month. If monthnumber is set to 1 when the function execute, they should set monthNumber to 12 and name to "December". Any ideas? Please help me. Thanks in advance.
Months.cpp
//Don't Know if it's a correct prefix ++ operator overloading.
Month Month::operator++()
{ int temp=++monthnumber;
if(temp>12)
{
Month::setMonthNumber(1);
Month::setMonthName("January");
return *this;
}
else
{
Month::setMonthNumber(temp);
return *this;
}
}
//Don't Know if it's a correct postfix ++ operator overloading.
Month Month::operator++(int)
{
//Don't know what to do here.
}
Month.h
class Month
{
private:
string name;
int monthnumber;
public:
Month(string);
Month(int);
const char* getMonthName();
int getMonthNumber();
void setMonthName(string);
void setMonthNumber(int);
Month operator++();
Month operator++(int);
}
Main.cpp
int main()
{
Month m("April");
// Test the prefix ++ operator.
cout << ++m << endl;
// Test the postfix ++ operator.
cout << m++ << endl;
cout << m << endl << endl;
}