/*
Definition : Construct a class Month with data members as Month
number.Write down overloaded operator++ for the
increment the Month number by one.
Write a member function read() and display() to read
a number of Month and print a number of Month.
Input:
Enter Month number : 8
Output:
Next Month number is : 9
Input:
Enter Month number : 12
Output:
Next Month number is : 1
*/
#include<iostream.h>
#include<conio.h>
class Month
{
int mno;
public:
void getData()
{
cout<<"\nEnter valid month number : ";
cin>>mno;
}
void operator ++()
{
mno++;
if(mno>12)
mno=1;
}
void putData()
{
cout<<"\nNext month is : "<<mno;
}
};
int main()
{
clrscr();
Month m;
m.getData();
m.operator ++(); //m++ or ++m
m.putData();
getch();
return 0;
}
No comments:
Post a Comment