14. Create a C++ class Date which contains: – day – month – year Write necessary member functions to accept and display a date using >> and << operators.


#include<iostream.h>
#include<conio.h>
class date
{
int day;
int month,year;
public:
friend istream &operator>>(istream &scan,date &d)
{
cout<<“Enter the date: DAY MONTH YEAR\n”;
scan>>d.day>>d.month>>d.year;
return scan;
}
friend ostream &operator<<(ostream &print,date &d)
{
print<<d.day<<“/”<<d.month<<“/”<<d.year;
return print;
}
};
void main()
{
date dd;
clrscr();
cin>>dd;
cout<<“\nDATE: “;
cout<<dd;
getch();
}

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s