Parent Constructor
#include<iostream.h>
#include<conio.h>
#include<string.h>
class emp
{
int empno;
char name[30];
public:
emp(){};
emp(int pno,char pname[30])
{
empno=pno;
strcpy(name,pname);
}
void getdetails()
{
cout<<"\n Enter The Number: ";
cin>>empno;
cout<<"\n Enter The Name: ";
cin>>name;
}
void display()
{
cout<<"\n Number= "<<empno;
cout<<"\n Name= "<<name;
}
};
class author:public emp
{
int publication;
public:
author(){};
author(int no,char name[30],int pubs):emp(no,name)
{
publication=pubs;
}
void getdetails()
{
emp::getdetails();
cout<<"\n publication: ";
cin>>publication;
}
void display()
{
emp::display();
cout<<"\n Publication= "<<publication<<endl;
}
};
void main()
{
clrscr();
emp e1;
e1.getdetails();
e1.display();
author a1;
a1.getdetails();
a1.display();
author a2(20,"Ritu",3);
a2.display();
getch();
}
Here is the output :)
No comments:
Post a Comment