标题:大侠来看看、帮这个程序出问题了 帮我改改
只看楼主
shinelin09
Rank: 2
来 自:中国
等 级:论坛游民
帖 子:9
专家分:20
注 册:2010-5-17
结帖率:0
已结贴  问题点数:20 回复次数:5 
大侠来看看、帮这个程序出问题了 帮我改改
#include<iostream.h>
#include<stdlib.h>
#include<fstream.h>
#include<iomanip.h>
#include<string.h>
class employee
{
public:
    employee()
    {
        salary=0;
    }
    void pay(){}
    void print(){}
    void input()
    {
        cout<<"ID:";
        cin>>no;
        cout<<" NAME:";
        cin>>name;
        cout<<" SEX(m/w):";
        cin>>sex;
        cout<<" AGE:";   
        cin>>age;
    }
protected:
    int no;
    char name[8];
    float salary;
    char sex;
    int age;

};
class manager:virtual public employee
{
protected:
    float monthlypay,sale;
public:
    manager(){monthlypay=8000;}
    void input(){cout<<"Manger";employee::input();}
    void save()
    {
    fstream  outfile;
    outfile.open("f:flsdfj.txt",ios::app);
    if(!outfile)
    {
        cout<<"f can't open.\n";
        abort();
    }
    outfile<<"Manger"<<endl;
    outfile<<"ID"<<no<<"NAME"<<name<<"SEX"<<sex<<"AGE"<<age<<"SALARY"<<salary<<endl;
    }
    void pay(){salary=monthlypay;}
    void print()
    {
        cout<<"├─────┼─────┼─────┼─────┼─────┤"<<endl;
        cout<<"│"<<setw(10)<<no<<"│"<<setw(10)<<name<<"│"<<setw(10)<<sex\
            <<"│"<<setw(10)<<age<<"│"<<setw(10)<<salary<<"│"<<endl;
    }
};

class technician:virtual public employee
{
private:
    float hourlyrate;
    int workhours;
public:
    technician(){hourlyrate=100;}
    void pay()
    {
        cout<<name<<"Work hour:";
        cin>>workhours;
        salary=hourlyrate*workhours;
    }
    void input(){cout<<"TECHNICIAN"<<endl;employee::input();}
    void save()
    {
    fstream  outfile;
    outfile.open("f:flsdfj.txt",ios::app);
    if(!outfile)
    {
        cout<<"f can't open.\n";
        abort();
    }
    outfile<<"TECHNICIAN"<<endl;
    outfile<<"ID"<<no<<"NAME"<<name<<"SEX"<<sex<<"AGE"<<age<<"SALARY"<<salary<<endl;
    }
    void print()
    {
        cout<<"├─────┼─────┼─────┼─────┼─────┤"<<endl;
        cout<<"│"<<setw(10)<<no<<"│"<<setw(10)<<name<<"│"<<setw(10)<<sex\
            <<"│"<<setw(10)<<age<<"│"<<setw(10)<<salary<<"│"<<endl;
    }
};
class salesman:virtual public employee
{
protected:
    float commrate;
    float sales;
public:
    salesman(){commrate=0.04;}
    void input(){cout<<"SALEMAN";employee::input();}
    void save()
    {
    fstream  outfile;
    outfile.open("f:flsdfj.txt",ios::app);
    if(!outfile)
    {
        cout<<"f can't open.\n";
        abort();
    }
    outfile<<"TECHNICIAN"<<endl;
    outfile<<"ID"<<no<<"NAME"<<name<<"SEX"<<sex<<"AGE"<<age<<"SALARY"<<salary<<endl;
    }
    void pay()
    {
        cout<<name<<"Sales volume:";
        cin>>sales;
        salary=sales*commrate;
    }
    void print()
    {
        cout<<"├─────┼─────┼─────┼─────┼─────┤"<<endl;
        cout<<"│"<<setw(10)<<no<<"│"<<setw(10)<<name<<"│"<<setw(10)\
            <<sex<<"│"<<setw(10)<<age<<"│"<<setw(10)<<salary<<"│"<<endl;
    }
};

class salesmanager:virtual public manager,virtual public salesman
{
private:
    float total;int no1,no2,no3,no4;char name1[8],name2[8],name3[8],name4[8];
    float sale1,sale2,sale3,sale4;
public:
    void salemanager()
    {
        monthlypay=5000;
        commrate=0.005;
    }
    void input(){cout<<"Sales manger";employee::input();}
    void save()
    {
    fstream  outfile;
    outfile.open("f:flsdfj.txt",ios::app);
    if(!outfile)
    {
        cout<<"f can't open.\n";
        abort();
    }
    outfile<<"Sales manger"<<endl;
    outfile<<"ID"<<no<<"NAME"<<name<<"SEX"<<sex<<"AGE"<<age<<"SALARY"<<salary<<endl;
    }
    void savesale()
    {
    fstream  outfile;
    outfile.open("f:flsdfj.txt",ios::app);
    if(!outfile)
    {
        cout<<"f can't open.\n";
        abort();
    }
    outfile<<"The salary of saleman of sales manger and themselves"<<endl;
    outfile<<"ID"<<no1<<"NAME"<<name1<<"SALARY"<<sale1<<endl;
    outfile<<"ID"<<no2<<"NAME"<<name2<<"SALARY"<<sale2<<endl;
    outfile<<"ID"<<no3<<"NAME"<<name3<<"SALARY"<<sale3<<endl;
    outfile<<"ID"<<no4<<"NAME"<<name4<<"SALARY"<<sale4<<endl;
    }
    void pay()
    {
        cout<<name<<"The sales volume of everydepartment:";
        salary=monthlypay+commrate*total;
    }
    float totalsale(){total=sale1+sale2+sale3+sale4;return total;}
    void printtotal()
    {
        cout<<"├─────┴──┬──┴─────┤"<<endl;
        cout<<"│Total    │   "<<setw(10)<<total<<" │"<<endl;
        cout<<"└────────┴────────┘"<<endl;
    }
    void sort(salesmanager p)
{
    int tmp,i,j;
    for(j=0;j<2;j++)
        for(i=0;i<2;i++)
            if(total<p.salary)
            {
                tmp=salary;
                total=p.salary;
                p.salary=tmp;
                tmp=no;
                no=p.no;
                p.no=tmp;
            }
}
    void saler()
    {
        cout<<"Staff ID:";
        cin>>no1;
        cout<<" Staff NAME:";
        cin>>name1;
        cout<<" Sales volume:";
        cin>>sale1;
        cout<<"Staff ID:";
        cin>>no2;
        cout<<" Staff NAME:";
        cin>>name2;
        cout<<" Sales volume:";
        cin>>sale2;
        cout<<"Staff ID:";
        cin>>no3;
        cout<<" Staff NAME:";
        cin>>name3;
        cout<<" Sales volume:";
        cin>>sale3;
        cout<<"Staff ID:";
        cin>>no4;
        cout<<" Staff NAME:";
        cin>>name4;
        cout<<" Sales volume:";
        cin>>sale4;

    }
    void saleprint()
    {
    cout<<"│"<<setw(10)<<no1<<"│"<<setw(10)<<name1<<"│"<<setw(10)<<sale1<<"│"<<endl;
    cout<<"├─────┼─────┼─────┤"<<endl;
    cout<<"│"<<setw(10)<<no2<<"│"<<setw(10)<<name2<<"│"<<setw(10)<<sale2<<"│"<<endl;
    cout<<"├─────┼─────┼─────┤"<<endl;
    cout<<"│"<<setw(10)<<no3<<"│"<<setw(10)<<name3<<"│"<<setw(10)<<sale3<<"│"<<endl;
    cout<<"├─────┼─────┼─────┤"<<endl;
    cout<<"│"<<setw(10)<<no4<<"│"<<setw(10)<<name4<<"│"<<setw(10)<<sale4<<"│"<<endl;
    }
    void print()
    {
    cout<<"├─────┼─────┼─────┼─────┼─────┤"<<endl;
    cout<<"│"<<setw(10)<<no<<"│"<<setw(10)<<name<<"│"<<setw(10)<<sex<<"│"\
        <<setw(10)<<age<<"│"<<setw(10)<<salary<<"│"<<endl;
    }
};
void main()
{
    manager m[4];
    technician t[4];
    salesman s[4];
    salesmanager sm[4];
    t[1].save();
    int flag=1,operate;
      do{
    cout<<"             #### The system of salary manger ####\n";
    cout<<"                ┌─────────────┐\n";     
    cout<<"                │    Chose your actions    │\n";
    cout<<"                │  Input:1,Enter         │\n";
    cout<<"                │  Total:2,Enter         │\n";
    cout<<"                │  Output:3,Enter        │\n";
    cout<<"                │  Save:4,Enter          │\n";
    cout<<"                │  Exit:5,Enter          │\n";
    cout<<"                └─────────────┘\n";  
    cout<<"                      Please chose one action:   ";
    cin>>operate;
    switch(operate)
    {
    case 1:
        cout<<"Waiting for a minute!"<<endl;
        {
            for(int i=0;i<4;i++)
            {m[i].input();}
            for(int j=0;j<4;j++)
            {t[j].input();}
            for(int k=0;k<4;k++)
            {s[k].input();}
            for(int l=0;l<4;l++)
            {sm[l].input();}
        };
        {
            for(int i=0;i<4;i++)
            {m[i].pay();}
            for(int j=0;j<4;j++)
            {t[j].pay();}
            for(int k=0;k<4;k++)
            {s[k].pay();}
            for(int l=0;l<4;l++)
                {sm[l].pay();sm[l].saler();}
            };break;
        case 2:
            cout<<"Waiting for a minute!"<<endl;
            {
            {
               for(int l=0;l<4;l++)
                    sm[l].totalsale();
            for(int i=0;i<4;i++)
                    for(int j=0;j<2;j++)
                    sm[j].sort(sm[j+1]);
        };   
        cout<<"The saleman of the first sales manger"<<endl;
        cout<<"┌─────┬─────┬─────┐"<<endl;
        cout<<"│ ID     │  NAME  │   SALARY │"<<endl;
        sm[0].saleprint();
        sm[0].printtotal();            
        cout<<"              The order is complete"<<endl;
        cout<<"List names of every sales manger"<<endl;
        cout<<"┌─────┬─────┬─────┬─────┬─────┐"<<endl;
        cout<<"│ ID     │  NAME  │ SEX   │ AGE   │ SALARY  │"<<endl;
            for(int k=0;k<4;k++)
                sm[k].print();
        cout<<"└─────┴─────┴─────┴─────┴─────┘"<<endl;
        };break;
        case 3:
        cout<<"Waiting for a minute!"<<endl;
        {   
        cout<<"                  The blank of the :"<<endl;
        cout<<"┌─────┬─────┬─────┬─────┬─────┐"<<endl;
        cout<<"│ ID     │  NAME  │ SEX   │ AGE   │ SALARY  │"<<endl;
        for(int i=0;i<4;i++)
        {m[i].print();}
        cout<<"└─────┴─────┴─────┴─────┴─────┘"<<endl;
        cout<<"┌─────┬─────┬─────┬─────┬─────┐"<<endl;
        cout<<"└─────┴─────┴─────┴─────┴─────┘"<<endl;
        cout<<"┌─────┬─────┬─────┬─────┬─────┐"<<endl;
        cout<<"│ ID     │  NAME  │ SEX   │ AGE   │ SALARY  │"<<endl;
        for(int k=0;k<4;k++)
        {s[k].print();}
        cout<<"└─────┴─────┴─────┴─────┴─────┘"<<endl;
        cout<<"┌─────┬─────┬─────┬─────┬─────┐"<<endl;
        cout<<"└─────┴─────┴─────┴─────┴─────┘"<<endl;
            };break;
        case 4:
        cout<<"Waiting for a minute!"<<endl;   
        {
        for(int i=0;i<4;i++)
        {m[i].save();}
            for(int j=0;j<4;j++)
            {t[j].save();}
            for(int k=0;k<4;k++)
            {s[k].save();}
            for(int l=0;l<4;l++)
            {sm[l].save();}
            };cout<<"     Information save!   "<<endl;break;
       case 5:exit(0);break;
       default:cout<<"Error!Repeat again!"<<endl;
        }
    }while(flag=1);   
}
}
搜索更多相关主题的帖子: 改改 
2010-05-17 17:34
guoangang123
Rank: 2
等 级:论坛游民
帖 子:14
专家分:29
注 册:2007-5-12
得分:6 
怎长啊,有些没耐心
2010-05-18 19:09
duhongru
Rank: 2
等 级:论坛游民
威 望:1
帖 子:31
专家分:84
注 册:2010-4-21
得分:6 
最后一句多了个},删除掉就好了。
我试过了删除后运行没有问题。
2010-05-18 21:00
shinelin09
Rank: 2
来 自:中国
等 级:论坛游民
帖 子:9
专家分:20
注 册:2010-5-17
得分:0 
回复 楼主 shinelin09
  呵呵、、帮帮忙咯
2010-05-18 23:11
shinelin09
Rank: 2
来 自:中国
等 级:论坛游民
帖 子:9
专家分:20
注 册:2010-5-17
得分:0 
回复 3楼 duhongru
吖、、我看看哈
2010-05-18 23:12
fanfan320
Rank: 3Rank: 3
来 自:运城
等 级:论坛游侠
帖 子:82
专家分:104
注 册:2010-5-12
得分:6 
你能把问题描述一下吗。太复杂了,不太清楚你所要解决的问题@
2010-05-19 15:28



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-307043-1-1.html




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

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