| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 528 人关注过本帖
标题:高手帮帮忙啊,着急!
只看楼主 加入收藏
zjdqsp
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2008-6-27
收藏
 问题点数:0 回复次数:1 
高手帮帮忙啊,着急!
帮帮忙,我程序没错误就是输出内容的方法不对,我是新手,高手帮帮忙
 
 
  
 
 
 
#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;
}
搜索更多相关主题的帖子: public include 
2008-06-27 18:17
wuhan111
Rank: 1
来 自:广西
等 级:新手上路
帖 子:7
专家分:0
注 册:2008-6-27
收藏
得分:0 
这个是我改了以后可以打印教师信息的 其他的类可以差不多也可以这样打印出来
#include"iostream"
#include"string"
using namespace std;

class Employee
{
    friend class Teacher;
private:
    int ID;
    char name[8];
public:
    static int employee_count;
public:
    Employee()
    {

    }

    Employee(int Num,char Name[])
    {
        ID = Num;
        strcpy(name, Name);
    }


    static int employee();
};

int Employee::employee_count=0;

int Employee::employee()
{
    return employee_count;
}


class Teacher: virtual public Employee//教师类
{
protected:
    int total;//教师基本工资
    int classmoney;//教师课时费
public:
    int nID;
    char cName[8];
public:

    Teacher()
    {

    }

    Teacher(int Num,char Name[]):Employee(Num, Name)
    {
        classmoney=0;
        total = 0;

        nID = Num;
        strcpy(cName, Name);

        Employee::employee_count++;
    }

    void SetID(int _ID)
    {
        nID = _ID;
    }

    void SetName(char _Name[])
    {
        strcpy(cName, _Name);
    }
    int GetID()
    {
        return nID;
    }

    char* GetName()
    {
        return cName;
    }
    int GetT1()
    {
        return total;
    }

    int GetT2()
    {
        return classmoney;
    }

    int  gongzi()
    {
        return (total += classmoney);
    }


    void setT1(int Total1)
    {
        total=Total1;
    }

    void setT2(int number1)//计算教师课时费
    {
        classmoney=(number1-120)*20;
    }

};


void main()
{
    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);

    }

    for( i=0;i<2;i++)
    {    
            cout<<"编号:"<<arr[i].GetID()<<"  姓名:"<<arr[i].GetName()<<"  工资:"<< arr[i].gongzi()<<"   基本工资:"<<arr[i].GetT1()<<endl;
    }
    
    cout<<"总员工数"<<Employee::employee_count<<endl;

}
2008-06-29 00:42
快速回复:高手帮帮忙啊,着急!
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.063784 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved