1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
|
#include <iostream>
#include <vector>
#include <cstdlib>
using namespace std;
class human{
string name;
public:
human(string name): name(name)
{cout << "A Human is created: NAME = " << name << endl;}
string getName(){return name;}
};
class student: virtual public human{
int id;
public:
student(string name, int id): human(name), id(id)
{cout << "A Student is created: NAME = " << getName() << " ID = " << id << endl;}
int getid(){return id;}
};
class employee: virtual public human{
double salary;
public:
employee(string name, double salary): human(name), salary(salary)
{cout << "An Employee is created: NAME = "
<< getName() << " SALARY = " << salary << endl;}
double getsalary(){return salary;}
};
class workingstudent: public student, public employee{
public:
workingstudent (string name, int id, double salary):
human(name), student(name, id), employee(name, salary)
{ cout << "A working student is created: Name = " << student::getName()
<< ". Id = " << getid() << ". Salary" << getsalary() << endl;}
void print()
{cout << "Name = " << getName() << ". Id = " << getid()
<< ". Salary = " << getsalary() << endl;}
};
int main() {
human h("Michael");
student* s = new student("Kelly", 111);
employee e("Dennis", 50000);
workingstudent w("john", 222, 90000009);
cout << h.getName() << endl
<< s->getName() << " " << s->getid()<< endl
<< e.getName() << " " << e.getsalary() << endl
<< w.print();
delete s;
}
|