使用以下程序中定义的教师类体系,编写程序,输入某月各种职称教师的工资信息,建立异质链表,输出每位教师的工资条,统计当月的总工资、平均工资、最高工资和最低工资。
#include <iostream>
using namespace std;
class staff
{
public:
staff ( double bSalary)
{
basicSalary=bSalary;
}
virtual void input() = 0;
virtual void output() = 0;
protected:
char name[30];
double basicSalary;
};
class teacher : public staff
{
public:
teacher( int basicsalary=3000 ) : staff( basicsalary ){ }
void input()
{
cout<<"姓名?";
cin>>name;
cout<<"职称 1,教授 2,副教授 3,讲师 (输入1,2 或 3):";
cin>>title;
cout<<"课时?";
cin>>coursetime;
}
void output()
{
double salary;
switch(title)
{
case 1: salary = basicSalary+coursetime *50; break;
case 2: salary=basicSalary+coursetime*30; break;
case 3: salary=basicSalary+coursetime*20;
}
cout<<"姓名:"<<name<<"\t本月工资:"<<salary<<endl;
}
protected:
int coursetime;
int title;
};
class manage : public staff
{
public:
manage( int basicsalary=2500 ) : staff( basicsalary ){ }
void input()
{
cout<<"姓名?";
cin>>name;
cout<<"职务工资? ";
cin>>jobSalary;
}
void output()
{
double salary;
salary = basicSalary+jobSalary;
cout<<"姓名:"<<name<<"\t本月工资:"<<salary<<endl;
}
protected:
double jobSalary;
};
class technician : public staff
{
public:
technician( int basicsalary=2000 ) : staff( basicsalary ){ }
void input()
{
cout<<"姓名?";
cin>>name;
cout<<"工作日?";
cin>>workdays;
}
void output()
{
double salary;
salary = basicSalary+workdays*20;
cout<<"姓名:"<<name<<"\t本月工资:"<<salary<<endl;
}
protected:
int workdays;
};
int main()
{
teacher t;
t.input();
t.output();
manage m;
m.input();
m.output();
technician h;
h.input();
h.output();
} 