| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 534 人关注过本帖
标题:谁能帮助我添加一个功能
只看楼主 加入收藏
leon57
Rank: 1
来 自:xznu
等 级:新手上路
帖 子:29
专家分:0
注 册:2008-7-19
收藏
 问题点数:0 回复次数:2 
谁能帮助我添加一个功能
高校有五类职工:教师,实验员,行政人员,教师兼职实验员,行政人员兼职教师。为了实现工资发放的自动功能,现要求编写程序来自动完成此功能。同时注意生成的相关数据结果以文件方式存放在硬盘中。程序应具备从键盘录入,文件的可继续录入,任意职工的工资查询(可由职工编号和职工姓名来实现),若有职工由于工作调动,则可进行相对应的调整动作。
我的程序最后一个功能既工作调动的功能无法实现,如果添加一个删除功能怎么添加?
程序源代码:
#include<iostream>
#include<string>
#include<fstream>
#include<iomanip>


using namespace std;
ofstream outfile;   //输出文件
ifstream infile;    //输入文件

class worker      //基类
{
public:
    int No_;
    string name;
protected:
    float bsalary;  //基本工资
    float salary;   //应发工资

public:
    void input()   //输入职工姓名和编号
    {
        cout<<"职工编号:";
        cin>>No_;
        cout<<"职工姓名:";
        cin>>name;
    }
    void output()  //输出职工编号,姓名及应发工资
    {
        cout<<"职工编号:";
        cout<<No_<<endl;
        cout<<"职工姓名:";
        cout<<name<<endl;
        cout<<"工资:";
        cout<<salary<<endl;
    }
};
class teacher:virtual public worker //教师类
{
protected:
    float tsalary;   //课时费
    int bwork;       //基本工作量
    int work;     //上学期工作量

public:
    teacher()   //给基本工作量和基本工资赋值
    {
        bwork=120;
        bsalary=800;
    }
    void inputt()   //输入上学期工作量
    {
        cout<<"上学期工作量:";
        cin>>work;
    }
    void settsalary()  //计算课时费
    {
        tsalary=(work-bwork)*20;
    }
    void set1()  //计算工资
    {
        salary=bsalary+tsalary;
    }
    void save1()  //保存教师信息与应发工资
    {
        outfile.open("f1.dat",ios::app);
        outfile<<setw(10)<<No_<<setw(20)<<name<<setw(10)<<salary<<endl;
        outfile.close();
    }
    void read1()  //读出教师信息与应发工资并分别赋值给No_,name,salary
    {
        infile.open("f1.dat",ios::in);
        infile>>No_>>name>>salary;
        infile.close();
    }
};
class researcher:virtual public worker  //实验员类
{
protected:
    float rsalary;  //实验室补助
public:
    researcher()  //给实验室补助和基本工资赋值
    {
        rsalary=150;
        bsalary=650;
    }
    void set2()    //计算工资
    {
        salary=rsalary+bsalary;
    }
    void save2()   //保存信息与应发工资
    {
        outfile.open("f2.dat",ios::app);
        outfile<<setw(10)<<No_<<setw(20)<<name<<setw(10)<<salary<<endl;
        outfile.close();
    }
    void read2()   //读出信息与应发工资
    {
        infile.open("f2.dat",ios::in);
        infile>>No_>>name>>salary;
        infile.close();
    }
};
class officer:virtual public worker   //行政人员类
{
protected:
    float osalary;  //行政人员补贴
public:
    officer()  //给行政人员补贴和基本工资赋值
    {
        osalary=250;
        bsalary=750;
    }
    void set3()    //计算工资
    {
        salary=osalary+bsalary;
    }
    void save3()   //保存信息与应发工资
    {
        outfile.open("f3.dat",ios::app);
        outfile<<setw(10)<<No_<<setw(20)<<name<<setw(10)<<salary<<endl;
        outfile.close();
    }
    void read3()    //读出信息与应发工资并分别赋值给No_,name,salary
    {
        infile.open("f3.dat",ios::in);
        infile>>No_>>name>>salary;
        infile.close();
    }
};
class tandr:virtual public teacher,public researcher   //教师兼职实验员类
{
public:
    tandr()    //给实验室补助和基本工资赋值
    {
        bsalary=800;
        rsalary=150;
    }
    void set4()    //计算工资
    {
        salary=bsalary+rsalary;
    }
    void save4()   //保存信息与应发工资
    {
        outfile.open("f4.dat",ios::app);
        outfile<<setw(10)<<No_<<setw(20)<<name<<setw(10)<<salary<<endl;
        outfile.close();
    }
    void read4()   //读出信息与应发工资并分别赋值给No_,name,salary
    {
        infile.open("f4.dat",ios::in);
        infile>>No_>>name>>salary;
        infile.close();
    }
};
class tando:virtual public teacher,public officer   //行政人员兼职教师类
{
public:
    tando()    //给行政人员补贴和基本工资赋值
    {
        bsalary=750;
        osalary=250;
    }
    void set5()    //计算工资
    {
        salary=bsalary+osalary+tsalary;
    }
    void save5()   //保存信息与应发工资
    {
        outfile.open("f5.dat",ios::app);
        outfile<<setw(10)<<No_<<setw(20)<<name<<setw(10)<<salary<<endl;
        outfile.close();
    }
    void read5()    //读出信息与应发工资并分别赋值给No_,name,salary
    {
        infile.open("f5.dat",ios::in);
        infile>>No_>>name>>salary;
        infile.close();
    }
};
void main()
{
    teacher t[100];
    researcher r[100];
    officer o[100];
    tandr tr[100];
    tando to[100];    //分别定义各类的对象数组,就相当于人员的容量,定义为100,表明能容100人
    int x,n,a=0,b=0,c=0,d=0,e=0,j=1,k=1;
    string m;
    cout<<"1:输入教师信息"<<endl;
    cout<<"2:输入实验员信息"<<endl;
    cout<<"3:输入行政人员信息"<<endl;
    cout<<"4:输入教师兼职实验员信息"<<endl;
    cout<<"5:输入行政人员兼职教师信息"<<endl;
    cout<<"6:以姓名输入查看人员工资"<<endl;
    cout<<"7:以编号输入查看人员工资"<<endl;
    cout<<"0:退出系统"<<endl;
    cout<<endl;
    
    while(x!=0)   //执行循环,只要X不为0就一直循环下去
    {
        cout<<"输入数字执行操作:";
        cin>>x;
        switch(x)  //执行switch语句,分别对输入的X值执行不同的操作
        {case 1:t[a].input();   //输入教师信息计算工资后保存
        t[a].inputt();
        t[a].settsalary();
        t[a].set1();
        t[a].save1();
        a++;
        break;
        case 2:r[b].input();  //输入实验员信息计算工资后保存
            r[b].set2();
            r[b].save2();
            b++;
            break;
        case 3:o[c].input();  //输入行政人员信息计算工资后保存
            o[c].set3();
            o[c].save3();
            c++;
            break;
        case 4:tr[d].input();  //输入教师兼职实验员信息计算工资后保存
        tr[d].inputt();
        tr[d].settsalary();
        tr[d].set4();
        tr[d].save4();
        d++;
        break;
        case 5:to[e].input();  //输入行政人员兼职教师信息计算工资后保存
        to[e].inputt();
        to[e].settsalary();
        to[e].set5();
        to[e].save5();
        e++;
        break;
        case 6:cout<<"输入姓名:";  //以姓名输入查看人员工资
            cin>>m;
            j=1;
              while(j==1)
              {
                  for(int i=0;i<a;i++)  //读出并检查教师类,如果符合if语句,执行输出函数
                {t[i].read1();
                    if(t[i].name==m)
                    {

                        t[i].output();
                        j=0;
                    
                    }
                }
                    for(i=0;i<b;i++)   //读出并检查实验员类,如果符合if语句,执行输出函数
                    {r[i].read2();    
                        if(r[i].name==m)
                        {
                            r[i].output();
                            j=0;
                        
                        }
                    }
                        for(i=0;i<c;i++)   //读出并检查行政人员类,如果符合if语句,执行输出函数
                        {o[i].read3();
                            if(o[i].name==m)
                            {
                                o[i].output();
                                j=0;
                            
                            }
                        }
                            for(i=0;i<d;i++)   //读出并检查教师兼职实验员类,如果符合if语句,执行输出函数
                            {tr[i].read4();
                            if(tr[i].name==m)
                            {
                                tr[i].output();
                                j=0;
                            
                            }
                            }
                            for(i=0;i<e;i++)   //读出并检查行政人员教师类,如果符合if语句,执行输出函数
                            {to[i].read5();
                            if(to[i].name==m)
                            {
                                to[i].output();
                                j=0;
                            
                            }
                            }
                            if(j==1)   //没找到
                            {cout<<"没找到!"<<endl;
                            }
                            break;
              }
                            
            
        break;
        
        case 7:cout<<"输入编号:";  //以编号输入查看人员工资
            cin>>n;
            k=1;
            while(k==1)
            {
                for(int i=0;i<a;i++)    //读出并检查教师类,如果符合if语句,执行输出函数
                {t[i].read1();
                    if(t[i].No_==n)
                    {
                        t[i].output();
                        k=0;
                        
                    }
                }
                    for(i=0;i<b;i++)   //读出并检查实验员类,如果符合if语句,执行输出函数
                    {r[i].read2();
                        if(r[i].No_==n)
                        {
                            r[i].output();
                            k=0;
                        
                        }
                    }
                        for(i=0;i<c;i++)   //读出并检查行政人员类,如果符合if语句,执行输出函数
                        {o[i].read3();
                            if(o[i].No_==n)
                            {
                                o[i].output();
                                k=0;
                        
                            }
                        }
                            for(i=0;i<d;i++)   //读出并检查教师兼职实验员类,如果符合if语句,执行输出函数
                            {tr[i].read4();
                            if(tr[i].No_==n)
                            {
                                tr[i].output();
                                k=0;
                            
                            }
                            }
                            for(i=0;i<e;i++)   //读出并检查行政人员教师类,如果符合if语句,执行输出函数
                            {to[i].read5();
                            if(to[i].No_==n)
                            {
                                to[i].output();
                                k=0;
                            
                            }
                            }
                            if(k==1)    //没找到
                            {cout<<"没找到!"<<endl;
                            k=0;
                            }
                            break;
            }
            
            break;
    
            }
            
            }
cout<<"退出系统"<<endl;   //输入X值为0的后果
}
2008-07-19 01:21
wuyu19841116
Rank: 1
等 级:新手上路
帖 子:7
专家分:0
注 册:2008-4-13
收藏
得分:0 
太长了,没法看呢,建议短一些精炼一些
2008-07-20 20:32
leon57
Rank: 1
来 自:xznu
等 级:新手上路
帖 子:29
专家分:0
注 册:2008-7-19
收藏
得分:0 
这是我们学校的课程设计的题目,我自己做的7个小时才弄成。虽然长但是很容易理解,也有注释,各位高手能帮住修改一下,或者改的精练一点也可以。谢谢了
2008-07-20 21:08
快速回复:谁能帮助我添加一个功能
数据加载中...
 
   



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

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