64,681
社区成员
发帖
与我相关
我的任务
分享
#include<iostream>
#include<string>
#ifndef CLASS_H
#define CLASS_H
using namespace std;
class Pay
{
public:
void input()
{
cout<<"Please input the num:";
cin>>num;
cout<<"Please input the name:";
cin>>name;
}
void display()
{
cout<<"num:"<<num<<endl;
cout<<"name:"<<name<<endl;
cout<<"salary:"<<salary<<endl;
}
protected:
int num;
string name;
int salary;
};
#endif
#include"class.h"
//经理
class Manager:virtual public Pay
{
public:
void calculate()
{
salary=8000;
}
};
//兼职技术人员
class Technician:public Pay
{
public:
void inputtime()
{
cout<<"Please input the worktime:";
cin>>worktime;
}
void calculate()
{
salary=worktime*100;
}
private:
int worktime;
};
//销售员
class Salesman:virtual public Pay
{
public:
void calculate()
{
salary=salesvolume*0.04;
}
void inputsalesvolume()
{
cout<<"Please input the salesvolume:";
cin>>salesvolume;
}
protected:
int salesvolume;
};
//销售经理(经理和销售员的派生类)
class Salesmanager:public Manager,public Salesman
{
public:
void calculate()
{
salary=salesvolume*0.05+5000;
}
};
#include "inheritance.cpp"
int main()
{
int choice;
do
{
cout<<"\n[salary calculator]\n";
cout<<"-------------------------------\n";
cout<<"Please choose the staff member:\n";
cout<<"<1> Manager\n";
cout<<"<2> Technician\n";
cout<<"<3> Salesman\n";
cout<<"<4> Salesmanager\n";
cout<<"-------------------------------\n";
cout<<"<0> Quit\n";
cin>>choice;
switch(choice)
{
case 1:
{Manager a;
a.input();
a.calculate();
a.display();
};break;
case 2:
{Technician b;
b.input();
b.inputtime();
b.calculate();
b.display();
};break;
case 3:
{Salesman c;
c.input();
c.inputsalesvolume();
c.calculate();
c.display();
};break;
case 4:
{Salesmanager d;
d.input();
d.calculate();
d.display();
};break;
}
}while (choice!=0);
return 0;
}
a.input();
a.calculate();
a.display();