Write a program for a class Date, which has a parameterized constructor to accept
the year, month and day and initializes the data members of the data members of
the class. The class also has member function to display the date in dd/mm/yyyy
format.
Answers
Answer:#include<iostream.h>
#include<conio.h>
class date
{
int dd,mm,yy;
public:
date(int,int,int);
void show();
};
date::date(int d,int m,int y)
{
dd=d;
mm=m;
yy=y;
}
void date::show()
{
cout< switch(mm)
{
case 1 :cout<<" Jan / ";
break;
case 2 :cout<<" Feb / ";
break;
case 3 :cout<<" Mar / ";
break;
case 4 :cout<<" Apr / ";
break;
case 5 :cout<<" May / ";
break;
case 6 :cout<<" Jun / ";
break;
case 7 :cout<<" Jul / ";
break;
case 8 :cout<<" Aug / ";
break;
case 9 :cout<<" Sep / ";
break;
case 10 :cout<<" Oct / ";
break;
case 11 :cout<<" Nov / ";
break;
case 12 :cout<<" Dec / ";
break;
}
cout< }
void main()
{
int dd,mm,yy;
clrscr();
cout<<"\n Enter date : ";
cout<<"\n Day : ";
cin>>dd;
cout<<"\n Month : ";
cin>>mm;
cout<<"\n Year : ";
cin>>yy;
if(mm>12)
{
cout<<"\n Invalid Month entered...";
}
else
{
date d(dd,mm,yy);
d.show();
}
getch();
}
/* OUTPUT
Enter date :
Day : 2
Month : 2
Year : 1994
2 / Feb / 1994 */