A C++ Program with Class
Let us now have a look at a C++ Program with a class. The following program show how the member function getdata () is defined within the class. The calss data in the program represented the day,month and year of the date. The function written to initialized the same is defined within the class.
#include<iostream.h>
#include<conio.h>
class data
{
private:
int day, mth, yr;
public:
void getdata(int dl, int ml, int yl)
{
day=dl;
mth=ml;
yr=yl;
}
void disp(void)
{
cout<<"Today's date is "<< day<<"/"<<mth<<"/"<<yr<<"\n"
}
};
void main()
{
class date today;
today.getdata(15,6.2017);
today.disp();
getche();
}
0 comments:
Post a Comment