#include<iostream> using namespace std; class ?Employee { protected: ?? ?char Name[30]; ?? ?char Num[5]; ?? ?int Work_Age; ?? ?double Total_Salary; public: ?? ?virtual void Get_Message(); ?? ?virtual void Pay() = 0 ; ?? ?void Show_Message(); }; class Manager :virtual ?public Employee { protected: ?? ?float Salary; public: ?? ?Manager() {}; ?? ?void Get_Message(); ?? ?void Pay(); ?? ?~Manager() {}; }; class Worker :public Employee { ?? ?float Salary; public: ?? ?Worker() {}; ?? ?void Get_Message() ; ?? ?void Pay() ; ?? ?~Worker() {} }; class Sell :virtual public Employee { protected: ?? ?float Sale; public: ?? ?Sell() {}; ?? ?void Get_Message() ; ?? ?void Pay() ; ?? ?~Sell() {}; }; void Employee::Get_Message() { ?? ?cout << "请输入姓名:"; ?? ?cin >> Name; ?? ?cout << "请输入编号:"; ?? ?cin >> Num; } void Employee::Show_Message() { ?? ?cout << "Name = " << Name << endl; ?? ?cout << "Num = " << Num << endl; ?? ?cout << "Total_Salary:" <<Total_Salary<< endl; } void Manager::Get_Message() { ?? ?Employee::Get_Message(); ?? ?cout << endl << "请输入固定工资:"; ?? ?cin >> Salary; ?? ?cout << endl << "请输入工龄:"; ?? ?cin >> Work_Age; ?? ?cout << endl; } void Manager::Pay() { ?? ?Total_Salary = Salary + 3 * 500; } void Worker::Get_Message() { ?? ?Employee::Get_Message(); ?? ?cout << endl << "请输入固定工资:"; ?? ??? ?cin >> Salary; ?? ??? ?cout << endl << "请输入工龄:"; ?? ??? ?cin >> Work_Age; ?? ??? ?cout << endl; } void Worker::Pay(){ ?? ?Total_Salary = Salary + 50 * Work_Age; } void Sell::Get_Message() { ?? ?Employee::Get_Message(); ?? ?cout << endl << "请输入工龄"; ?? ?cin >> Work_Age; ?? ?cout << endl << "请输入销售额:"; ?? ?cout << endl; } void Sell::Pay() { ?? ?Total_Salary = 1000 + Sale * 0.1; } int main() { ?? ?char yn; ?? ?int choose; ?? ?Employee* Employee[3]; ?? ?Employee[0] = new Manager; ?? ?Employee[1] = new Worker; ?? ?Employee[2] = new Sell; ?? ?while (1) { ?? ??? ?cout << "请选择要计算的类别:" << endl; ?? ??? ?cout << "0-经理" << endl; ?? ??? ?cout << "1-工人" << endl; ?? ??? ?cout << "2-销售员" << endl; ?? ??? ?cout << "请输入操作数:" << endl; ?? ??? ?cin >> choose; ?? ??? ?cout << endl; ?? ??? ?Employee[choose]->Get_Message(); ?? ??? ?Employee[choose]->Pay(); ?? ??? ?Employee[choose]->Show_Message(); ?? ??? ?cout << "是否继续(YES OR NO)" << endl; ?? ??? ?cin >> yn; ?? ??? ?if (yn != 'YES' && yn != 'yes') ?? ??? ??? ?break; ?? ?} ?? ?return 0;
}
?
|