Program Using Inheritance To get Data of a person
#include<iostream.h>
#include<conio.h>
#include<stdio.h>
class stu
{
int roll;
char name[30];
char sub[3];
int per;
public:
void getstu()
{
cout<<“enter students roll: “;
cin>>roll;
cout<<“enter his or her name: “;
gets(name);
cout<<“enter subjects opted in 11th: “;
gets(sub);
cout<<“enter percentage scored in class 10: “;
cin>>per;
}
void showstu()
{
cout<<“\nname: “<<name;
cout<<“\nroll: “<<roll;
cout<<“\nsubjects: “<<sub;
cout<<“\npercentage: “<<per;
}
};
class emp:public stu
{
int id;
int comp;
char post[30];
public:
void getemp()
{
getstu();
cout<<“enter employees id: “;
cin>>id;
cout<<“enter computer no. to be alloted: “;
cin>>comp;
cout<<“enter post to be assigned: “;
gets(post);
}
void showemp()
{
showstu();
cout<<“\nThe entered details are: “;
cout<<“\nemployee id: “<<id;
cout<<“\ncomp. assigned: “<<comp;
cout<<“\npost assigned: “<<post;
}
};
void main()
{
emp e1;
stu s1;
clrscr();
int i;
cout<<“enter 1 if the student is assigned job in our company “;
cin>>i;
if(i==1)
{
e1.getemp();
clrscr();
e1.showemp();
}
else
{
s1.getstu();
clrscr();
s1.showstu();
}
getch();
}
#include<conio.h>
#include<stdio.h>
class stu
{
int roll;
char name[30];
char sub[3];
int per;
public:
void getstu()
{
cout<<“enter students roll: “;
cin>>roll;
cout<<“enter his or her name: “;
gets(name);
cout<<“enter subjects opted in 11th: “;
gets(sub);
cout<<“enter percentage scored in class 10: “;
cin>>per;
}
void showstu()
{
cout<<“\nname: “<<name;
cout<<“\nroll: “<<roll;
cout<<“\nsubjects: “<<sub;
cout<<“\npercentage: “<<per;
}
};
class emp:public stu
{
int id;
int comp;
char post[30];
public:
void getemp()
{
getstu();
cout<<“enter employees id: “;
cin>>id;
cout<<“enter computer no. to be alloted: “;
cin>>comp;
cout<<“enter post to be assigned: “;
gets(post);
}
void showemp()
{
showstu();
cout<<“\nThe entered details are: “;
cout<<“\nemployee id: “<<id;
cout<<“\ncomp. assigned: “<<comp;
cout<<“\npost assigned: “<<post;
}
};
void main()
{
emp e1;
stu s1;
clrscr();
int i;
cout<<“enter 1 if the student is assigned job in our company “;
cin>>i;
if(i==1)
{
e1.getemp();
clrscr();
e1.showemp();
}
else
{
s1.getstu();
clrscr();
s1.showstu();
}
getch();
}
Comments
Post a Comment