الاثنين، 25 نوفمبر 2013
11:59 ص

person(admin,account) Inheritance in ++C

4) Consider the class hierarchy in the figure below. The class master derives
information from both account and admin classes which in turn derive
information from the class person. Define all the four classes and write a
program to create, update and display the information contained in master
objects.

#include "stdafx.h"
#include<iostream>
#include<conio.h>
using namespace std;
class person
{
protected:
char name[20];
int code;
public:
void n_c()
{
cout<<"Name: ";
cin>>name;
cout<<"Code: ";
cin>>code;
}
void o_n_c()
{
cout<<"\n Name "<<name;
cout<<"\n Code "<<code;
}
};
class account:public person
{
protected:
float pay;
public:
void n_c_p()
{
n_c();
cout<<"Pay: ";
cin>>pay;
}
void o_n_c_p()
{
o_n_c();
cout<<"\n Pay  "<<pay;
}
};
class admin:public person
{
protected:
int exp;
public:
void e()
{
   cout<<"Experience: ";
cin>>exp;
}
void o_e()
{
cout<<"\n Experience  "<<exp;
}
};
class master:public admin,public account
{
public:
void input()
{
n_c_p();
e();
}
void output()
{
o_n_c_p();
o_e();
}
};
void main()
{
person p;
// account ac;
// admin ad;
master m;
m.input();
    m.output();
_getch();
}

0 التعليقات:

إرسال تعليق