Friday, January 9, 2015

Inheritance Example in C++

#include<iostream.h>
#include<conio.h>
#include<stdio.h>
#include<iomanip.h>
class person
{
protected:char *name;
int code;
public:void getdata()
{
cout<<"enter the person name";
name=new char[20];
gets(name);
cout<<"Enter the code";
cin>>code;
}
};
class account:public virtual person
{
protected: float pay;
public: void getpay()
{
cout<<"enter the person pay";
cin>>pay;
}
};
class admin:public virtual person
{
protected: int experience ;
public: void getexp()
{
cout<<"enter the person experience";
cin>>experience;
}
};
class master:public account, public admin
{
public: void display()
 {
cout<<"NAME:-"<<name<<setw(15)<<endl;
cout<<"CODE:-"<<code<<setw(15)<<endl;
cout<<"EXPERIENCE:-"<<experience<<setw(15)<<endl;
cout<<"PAY:-"<<pay<<setw(15)<<endl;
 }

};
void main()
{
master *p;
int n,i;
cout<<"enter the no. of persons";
cin>>n;
p=new master[n];
for(i=0;i<n;i++)
{
cout<<"enter data of person no.:-"<<(i+1)<<endl;
p[i].getdata();
p[i].getpay();
p[i].getexp();
}
for(i=0;i<n;i++)
{
cout<<"data of person no.:-"<<(i+1)<<endl;
p[i].display();
}
}


more more code you can visit http://codesofprogramming.blogspot.in/

No comments:

Post a Comment