高手帮帮忙啊,着急!
帮帮忙,我程序没错误就是输出内容的方法不对,我是新手,高手帮帮忙#include"iostream"
#include"string"
#include"fstream"//输入输出流
#include"iomanip"
using namespace std;
ofstream outfile;//输出文件
ifstream infile;//输入文件
class Employee
{
protected:
int No_;
string name;
public:
static int employee_count;
public:
Employee(){}
Employee(int Num,string Name)
{No_=Num;
name=Name;
employee_count++;
}
};
int Employee::employee_count=0;
class Teacher:virtual public Employee//教师类
{
protected:
int total;//教师基本工资
int classmoney;//教师课时费
public:
Teacher(){}
Teacher(int Num,string Name):Employee(Num,Name){}
void setT1(int Total1)
{total=Total1;}
void setT2(int number1)//计算教师课时费
{classmoney=0;
cin>>number1;
classmoney=(number1-120)*20;
cout<<classmoney<<endl;
}
void save()
{
outfile.open("f1.dat",ios::app);//文件保存教师信息
outfile<<setw(10)<<No_<<setw(20)<<name<<setw(10)<<total<<setw(10)<<classmoney<<endl;
outfile.close();
}
};
class Officer:virtual public Employee//行政人员类
{
protected:
int total2;//行政人员基本工资
int money1;//行政人员补贴
public:
Officer(){}
Officer(int Num,string Name):Employee(Num,Name){}
void setT1(int Total2)
{total2=Total2;}
void setT3(int Money1)
{money1=Money1;}
void save()
{
outfile.open("f2.dat",ios::out);
outfile<<No_<<name<<total2<<setw(10)<<money1<<endl;
outfile.close();
}
};
class Expert:virtual public Employee//实验人员类
{
protected:
int total3;//实验人员基本工资
int money2;//实验人员补贴
public:
Expert(){}
Expert(int Num,string Name):Employee(Num,Name){}
void setT1(int Total3)
{total3=Total3;}
void setT4(int Money2)
{
money2=Money2;
}
void save()
{
outfile.open("f3.dat",ios::out);
outfile<<setw(10)<<No_<<setw(20)<<name<<setw(10)<<total3<<setw(10)<<money2<<endl;
outfile.close();
}
};
class TeacherExpert:public Teacher,public Expert
{
public:
TeacherExpert(int Num,string Name):Employee(Num,Name){}
void setT1(int Total4)
{total=Total4;}
void setT2(int number2)
{
cin>>number2;
classmoney=(number2-120)*20;
cout<<classmoney<<endl;
}
void setT4(int Money3)
{money2=Money3;}
void save()
{
outfile.open("f4.dat",ios::out);
outfile<<setw(10)<<No_<<setw(20)<<name<<setw(10)<<total<<setw(10)<<classmoney<<setw(10)<<money2<<endl;
outfile.close();
}
};
void main()
{
int rcount;//保存员工总数
int rno_;//保存员工号
string rname;//保存员工姓名
int rtotal;//保存各类工资
int rtotal2;
int rtotal3;
int rclassmoney;//保存课时费
int rmoney1;//保存补贴
int rmoney2;
outfile.open("f1.dat",ios::out);
outfile.close();
Teacher arr[2]={Teacher(1001,"王"),Teacher(1002,"李")};
cout<<"共有两名教师"<<endl;
{for(int i=0;i<2;i++)
{int N,t;
cout<<"输入第"<<i+1<<"号教师上学期工作量"<<endl;
cin>>N;
arr[i].setT2(N);
cout<<"输入第"<<i+1<<"号教师基本工资"<<endl;
cin>>t;
arr[i].setT1(t);
arr[i].save();
}
}
Officer man1(1003,"张");
cout<<"共有一名行政人员"<<endl;
{int t,M;
cout<<"输入行政人员补贴"<<endl;
cin>>M;
man1.setT3(M);
cout<<"输入行政人员基本工资"<<endl;
cin>>t;
man1.setT1(t);
man1.save();
}
Expert man2(1006,"孔");
cout<<"共有一名实验员"<<endl;
{int M,t;
cout<<"输入实验员补贴"<<endl;
cin>>M;
man2.setT4(M);
cout<<"输入实验员基本工资"<<endl;
cin>>t;
man2.setT1(t);
man2.save();
}
TeacherExpert drr[2]={TeacherExpert(1004,"沈"),TeacherExpert(1005,"孙")};
cout<<"共有两名教师并实验员"<<endl;
{for(int i=0;i<2;i++)
{int t,N,P;
cout<<"输入第"<<i+1<<"号输入教师并实验员上学期工作量"<<endl;
cin>>N;
drr[i].setT2(N);
cout<<"输入第"<<i+1<<"号输入教师并实验员基本工资"<<endl;
cin>>t;
drr[i].setT1(t);
cout<<"输入第"<<i+1<<"号输入教师并实验员补贴"<<endl;
cin>>P;
drr[i].setT4(P);
drr[i].save();
}
}
//以下读文件
cout<<"人员信息"<<endl;
infile.open("f1.dat",ios::in);
infile>>rno_>>rname>>rtotal>>rclassmoney>>rcount;//读教师信息
cout<<"教师:"<<endl;//输出教师信息
{for(int i=0;i<2;i++)
{infile>>rno_>>rname>>rtotal;
cout<<"编号:"<<rno_<<"姓名:"<<rname<<"基本工资:"<<rtotal<<"工资:"<<rtotal+rclassmoney<<endl;
}
}
cout<<"行政人员:"<<endl;//输出行政人员信息
infile.open("f2.dat",ios::in);
infile>>rno_>>rname>>rtotal2>>rmoney1;//读出行政人员信息
cout<<"编号:"<<rno_<<"姓名:"<<rname<<"基本工资:"<<rtotal2<<"工资:"<<rtotal2+rmoney1<<endl;
infile.close();
cout<<"实验员:"<<endl;//输出试验员信息
infile.open("f3.dat",ios::in);
infile>>rno_>>rname>>rtotal3>>rmoney2;//读实验员的信息
cout<<"编号:"<<rno_<<"姓名:"<<rname<<"基本工资:"<<rtotal3<<"工资:"<<rtotal3+rmoney2<<endl;
infile.close();
cout<<"教师并实验员:"<<endl;//输出教师并实验员信息
{for(int i=0;i<2;i++)
{infile.open("f4.dat",ios::in);
infile>>rno_>>rname>>rtotal>>rmoney2;//读教师并实验员的信息
cout<<"编号:"<<rno_<<"姓名:"<<rname<<"基本工资:"<<rtotal<<"工资:"<<rtotal+rclassmoney+rmoney2<<endl;
infile.close();
}
}
cout<<"总员工数"<<rcount<<endl;
}