| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 795 人关注过本帖
标题:求教c++问题,,,帮我看看这个程序,哪里有问题了啊,好多的错误不能运行, ...
只看楼主 加入收藏
caihua
Rank: 1
等 级:新手上路
帖 子:25
专家分:0
注 册:2012-9-6
结帖率:66.67%
收藏
已结贴  问题点数:10 回复次数:10 
求教c++问题,,,帮我看看这个程序,哪里有问题了啊,好多的错误不能运行,谢谢大家
#include<iostream>
#include<string.h>
#include<fstream>
using namespace std;

class Employee
{
protected:
char name[20];
int num;
int rank;
float wages;
static int count;
public:
Employee();
void print();
friend class Head;
};
class Mansger:virtual public Employee{
public:
Mansger():Employee();
void print();
void save();
friend class Head;
}
class Salemansger:virtual public Employee
{
protected:
int sum;
public:
Salemansger():
Employee();
void print();
void save();
friend class Head;
};
class Technology:virtual public Employee
{
protected:
int time;
public:
Technology():Employee();
void print();
void save();
friend class Head;};
class Salesman:virtual public Employee
{
protected:
int sum1;
public:
Salesman():Employee();
void print();
void save();
friend class Head;
};
struck Linked
{
Employee *p;
Linked *next;
};
class Head
{
public:
Head();
void Insert(Employee *temp);
void Check();
void Delete();
void print();
~Head();
privata:
Linked *top;
};

EmployeeEmployee::Employee()
{
cout<<"输入姓名: ";
cin>>name;
++count;
num=count;
rank=1;
}
void Employee::print()
{
cout<<"编号"<<num<<" "<<"姓名"<<name<<" "<<"等级"<<rank<<" "<<"月薪"<<wages<<endl;
}
MansgerMansger::Mansger():Employee()
{
rank=4;
wages=8000;
}
void Mansger::print()
{
cout<<"编号"<<num<<" "<<"姓名"<<name<<" "<<"等级"<<rank<<" "<<"月薪"<<wages<<endl;
}
void Mansger::save()
{
ofstream fs("d:\\Mansger.txt");
fs<<wages;
cout<<"Mansger ok"<<endl;
}
SalemansgerSalemansger::Salemansger():Employee()
{
rank=3;
cout<<"输入部门销售总额: ";
cin>>sum;
wages=0.005*sum;
}
void Salemansger::print()
{
cout<<"编号"<<num<<" "<<"姓名"<<name<<" "<<"等级"<<rank<<" "<<"月薪"<<wages<<endl;
}
void Salemansger::save(){
ofstream fs("d:\\Salemansger.txt");
fs<<wages;
cout<<"Salemansger ok"<<endl;
}
TechnologyTechnology::Technology():Employee()
{
rank=3;
cout<<"输入工作时间: ";
cin>>sum;
wages=100*time;
}
void Technology::print()
{
cout<<"编号"<<num<<" "<<"姓名"<<name<<" "<<"等级"<<rank<<" "<<"月薪"<<wages<<endl;}
void Technology::save()
{
ofstream fs("d:\\Technology.txt");
fs<<wages;
cout<<"Technology ok"<<endl;
}
SalesmanSalesman::Salesman():Employee()
{
cout<<"输入月销售额: ";
cin>>sum1;
wages=0.04*sum1;
}
void Salesman::print(){
cout<<"编号"<<num<<" "<<"姓名"<<name<<" "<<"等级"<<rank<<" "<<"月薪"<<wages<<endl;}
void Salesman::save()
{
ofstream fs("d:\\Salesman.txt");
fs<<wages;
cout<<"Salesman ok"<<endl;
}
HeadHead::Head()
{
if((top=new Linked)==NULL)exit(-1_);
top->next=NULL;
}
void Head::Insert(Employee *temp)
{
Linked *ttop=top;
while(ttop->next)
ttop=ttop->next;
ttop->next=new Linked;
ttop->next->p=temp;
ttop->next->next=0;
}
void Head::Check()
{
char s[20];
cout<<"输入要查找人的姓名: ";
cin>>s;
Linked *pbuf=top->next;
while(pbuf!=NULL)
{
if(strcmp(pbuf->p->name,s)!=0)
pbuf=pbuf->next;
else if(strcmp(pbuf->p->name,s)==0
{
cout<<"编号"<<pbuf->p->num<<" "<<"姓名"<<pbuf->p->name<<" "<<"等级"<<pbuf->p->rank<<" "<<"月薪"<<pbuf->p->wages<<endl;
}
pbuf=pbuf->next;
continue;
}
elsecout<<"查无此人"<<endl;
}
void Head::Delete()
{
int a;
cout<<"输入要删除人的编号: ";
cin>>a;
Linked *pbuf=top,*q;
while(pbuf->next!=NULL)
{
if(a!=pbuf->next->p->num)
pbuf=pbuf->next;
else if(a==pbuf->next->p->num)
{
q=pbuf->next;
pbuf->next=pbuf->next->next;
delete q;
cout<<"删除成功"<<endl;
}
elsecout<<"查无此人"<<endl;
}
void Head::print()
{
Linked *pbuf=top->next;
while(pbuf!=NULL)
{
pbuf->p->print();
pbuf=pbuf->next;
}
}
Head::~Head ()
{
Linked *ttop,*q;
ttop=top->next;
while(ttop!=NULL)
{
q=ttop;
ttop=ttop->next;
delete q;
}
}void mnue(Head *Data)
{
int n;
cout<<"请输入1、查找 2、删除 3、打印 0 退出:\n";
cin>>n;
switch(n)
{
case 1:
Data->Check();
break;
case 2:
Data->Delete();
break;
case 3:
Data->print();
break;
case 0:
break;
}
cout<<"是否继续继续请按1退出请按0";
cin>>n;
if(n!=0) mnue(Data);
}
void menu(Head *Data)
{
Mansger *M;Salemansger *S;
Technology *T;
Salesman *SA;
int n;
cout<<"请输入1、经理 2、销售经理 3、技术 4、销售员 0、退出:\n";
cin>>n;
switch(n)
{
case 1:
M=new Mansger;
M->save();
Data->Insert(M);
break;
case 2:
S=new Salemansger;
S->save();
Data->Insert(S);
break;
case 3:
T=new Technology;
T->save();
Data->Insert(T);
break;
case 4:
SA=new Salesman;
SA->save();
Data->Insert(SA);
break;
case 0:break;
}
cout<<"是否继续继续请按1退出请按0";
cin>>n;
if(n!=0) mnue(Data);
}
void main()
{
Head Data;
int n;
while(1)
{
cout<<"请输入(1 输入 2 其他操作 0 退出):\n";
cin>>n;
switch(n)
{case 1:
menu(&Data);
break;
case 2:
menu(&Data);
break;
case 0:
system("pause");
return;
}
}
system("cls");
}
搜索更多相关主题的帖子: void namespace include public friend 
2013-05-08 18:57
caihua
Rank: 1
等 级:新手上路
帖 子:25
专家分:0
注 册:2012-9-6
收藏
得分:0 
没有人吗
2013-05-08 19:25
fxbszj
Rank: 5Rank: 5
来 自:阿修罗界
等 级:职业侠客
威 望:4
帖 子:163
专家分:331
注 册:2012-10-8
收藏
得分:0 
以下是引用caihua在2013-5-8 19:25:14的发言:

没有人吗

你这排版,真心不想去看
2013-05-08 22:05
peach5460
Rank: 15Rank: 15Rank: 15Rank: 15Rank: 15
来 自:武汉
等 级:贵宾
威 望:30
帖 子:2780
专家分:6060
注 册:2008-1-28
收藏
得分:0 
错误是什么?

我总觉得授人以鱼不如授人以渔...
可是总有些SB叫嚣着:要么给代码给答案,要么滚蛋...
虽然我知道不要跟SB一般见识,但是我真的没修炼到宠辱不惊...
2013-05-09 06:54
apull
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
来 自:三体星系
等 级:版主
威 望:216
帖 子:1509
专家分:9241
注 册:2010-3-16
收藏
得分:10 
问题比较多,注释内容都是有问题的语句。
程序代码:

#include<iostream>
#include<string.h>
#include<fstream>
#include <stdlib.h>
using namespace std;

class Employee
{
    protected:
        char name[20];
        int num;
        int rank;
        float wages;
        static int count;
    public:
        Employee();
        void print();
        friend class Head;
};
int Employee::count = 0;    //初始化静态变量
class Mansger: virtual public Employee {
    public:
        Mansger();    //Mansger(): Employee();
        void print();
        void save();
        friend class Head;
};//缺少;
class Salemansger: virtual public Employee
{
    protected:
        int sum;
    public:
        Salemansger();    //Salemansger(): Employee();
        void print();
        void save();
        friend class Head;
};
class Technology: virtual public Employee
{
    protected:
        int time;
    public:
        Technology();    //Technology(): Employee();
        void print();
        void save();
        friend class Head;
};
class Salesman: virtual public Employee
{
    protected:
        int sum1;
    public:
        Salesman();    //Salesman(): Employee();
        void print();
        void save();
        friend class Head;
};
struct Linked    //struck Linked
{
    Employee *p;
    Linked *next;
};
class Head
{
    public:
        Head();
        void Insert(Employee *temp);
        void Check();
        void Delete();
        void print();
        ~Head();
    private:    //privata:
        Linked *top;
};

Employee::Employee()    //EmployeeEmployee::Employee()
{
    cout << "输入姓名: ";
    cin >> name;
    ++count;
    num = count;
    rank = 1;
}
void Employee::print()
{
    cout << "编号" << num << " " << "姓名" << name << " " << "等级" << rank << " " << "月薪" << wages << endl;
}
Mansger::Mansger(): Employee()    //MansgerMansger::Mansger(): Employee()
{
    rank = 4;
    wages = 8000;
}
void Mansger::print()
{
    cout << "编号" << num << " " << "姓名" << name << " " << "等级" << rank << " " << "月薪" << wages << endl;
}
void Mansger::save()
{
    ofstream fs("d:\\Mansger.txt");
    fs << wages;
    cout << "Mansger ok" << endl;
}
Salemansger::Salemansger(): Employee()    //SalemansgerSalemansger::Salemansger(): Employee()
{
    rank = 3;
    cout << "输入部门销售总额: ";
    cin >> sum;
    wages = 0.005 * sum;
}
void Salemansger::print()
{
    cout << "编号" << num << " " << "姓名" << name << " " << "等级" << rank << " " << "月薪" << wages << endl;
}
void Salemansger::save() {
    ofstream fs("d:\\Salemansger.txt");
    fs << wages;
    cout << "Salemansger ok" << endl;
}
Technology::Technology(): Employee()    //TechnologyTechnology::Technology(): Employee()
{
    rank = 3;
    cout << "输入工作时间: ";
    cin >> time;    //cin >> sum;
    wages = 100 * time;
}
void Technology::print()
{
    cout << "编号" << num << " " << "姓名" << name << " " << "等级" << rank << " " << "月薪" << wages << endl;
}
void Technology::save()
{
    ofstream fs("d:\\Technology.txt");
    fs << wages;
    cout << "Technology ok" << endl;
}
Salesman::Salesman(): Employee()    //SalesmanSalesman::Salesman(): Employee()
{
    cout << "输入月销售额: ";
    cin >> sum1;
    wages = 0.04 * sum1;
}
void Salesman::print() {
    cout << "编号" << num << " " << "姓名" << name << " " << "等级" << rank << " " << "月薪" << wages << endl;
}
void Salesman::save()
{
    ofstream fs("d:\\Salesman.txt");
    fs << wages;
    cout << "Salesman ok" << endl;
}
Head::Head()    //HeadHead::Head()
{
    if((top = new Linked) == NULL)
        exit(-1);    //exit(-1_);
    top->next = NULL;
}
void Head::Insert(Employee *temp)
{
    Linked *ttop = top;
    while(ttop->next)
        ttop = ttop->next;
    ttop->next = new Linked;
    ttop->next->p = temp;
    ttop->next->next = 0;
}
void Head::Check()
{
    char s[20];
    cout << "输入要查找人的姓名: ";
    cin >> s;
    Linked *pbuf = top->next;
    while(pbuf != NULL)
    {
        if(strcmp(pbuf->p->name, s) != 0)
            pbuf = pbuf->next;
        else
            if(strcmp(pbuf->p->name, s) == 0)    //if(strcmp(pbuf->p->name, s) == 0
            {
                cout << "编号" << pbuf->p->num << " " << "姓名" << pbuf->p->name << " " << "等级" << pbuf->p->rank << " " << "月薪" << pbuf->p->wages << endl;
            }
            else
                cout << "查无此人" << endl;
        pbuf = pbuf->next;
        continue;
    }
    //elsecout << "查无此人" << endl;    
    
}
void Head::Delete()
{
    int a;
    cout << "输入要删除人的编号: ";
    cin >> a;
    Linked *pbuf = top, *q;
    while(pbuf->next != NULL)
    {
        if(a != pbuf->next->p->num)
            pbuf = pbuf->next;
        else
            if(a == pbuf->next->p->num)
            {
                q = pbuf->next;
                pbuf->next = pbuf->next->next;
                delete q;
                cout << "删除成功" << endl;
            }
            else
                cout << "查无此人" << endl;    //elsecout << "查无此人" << endl;
    }
}//缺少大括号
void Head::print()
{
    Linked *pbuf = top->next;
    while(pbuf != NULL)
    {
        pbuf->p->print();
        pbuf = pbuf->next;
    }
}
Head::~Head ()
{
    Linked *ttop, *q;
    ttop = top->next;
    while(ttop != NULL)
    {
        q = ttop;
        ttop = ttop->next;
        delete q;
    }
}
void mnue(Head * Data)
{
    int n;
    cout << "请输入1、查找 2、删除 3、打印 0 退出:\n";
    cin >> n;
    switch(n)
    {
        case 1:
            Data->Check();
            break;
        case 2:
            Data->Delete();
            break;
        case 3:
            Data->print();
            break;
        case 0:
            break;
    }
    cout << "是否继续继续请按1退出请按0";
    cin >> n;
    if(n != 0)
        mnue(Data);
}
void menu(Head * Data)
{
    Mansger *M;
    Salemansger *S;
    Technology *T;
    Salesman *SA;
    int n;
    cout << "请输入1、经理 2、销售经理 3、技术 4、销售员 0、退出:\n";
    cin >> n;
    switch(n)
    {
        case 1:
            M = new Mansger;
            M->save();
            Data->Insert(M);
            break;
        case 2:
            S = new Salemansger;
            S->save();
            Data->Insert(S);
            break;
        case 3:
            T = new Technology;
            T->save();
            Data->Insert(T);
            break;
        case 4:
            SA = new Salesman;
            SA->save();
            Data->Insert(SA);
            break;
        case 0:
            break;
    }
    cout << "是否继续继续请按1退出请按0";
    cin >> n;
    if(n != 0)
        mnue(Data);
}
int main()    //void main()
{
    Head Data;
    int n;
    while(1)
    {
        cout << "请输入(1 输入 2 其他操作 0 退出):\n";
        cin >> n;
        switch(n)
        {   case 1:
                menu(&Data);
                break;
            case 2:
                menu(&Data);
                break;
            case 0:
                system("pause");
                return 0;
        }
    }
    system("cls");
}


2013-05-09 12:02
caihua
Rank: 1
等 级:新手上路
帖 子:25
专家分:0
注 册:2012-9-6
收藏
得分:0 
回复 5楼 apull
你注释的语句是帮我改过了的还是有问题的,为什么在我电脑上运行时还是好多滴的错误,搞不懂啊
2013-05-09 13:21
peach5460
Rank: 15Rank: 15Rank: 15Rank: 15Rank: 15
来 自:武汉
等 级:贵宾
威 望:30
帖 子:2780
专家分:6060
注 册:2008-1-28
收藏
得分:0 
多看书

我总觉得授人以鱼不如授人以渔...
可是总有些SB叫嚣着:要么给代码给答案,要么滚蛋...
虽然我知道不要跟SB一般见识,但是我真的没修炼到宠辱不惊...
2013-05-09 13:24
caihua
Rank: 1
等 级:新手上路
帖 子:25
专家分:0
注 册:2012-9-6
收藏
得分:0 
回复 4楼 peach5460
我运行的时候下面报错说是:后的语句没有在}里边,从构造函数就开始有错误了
2013-05-09 13:24
apull
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
来 自:三体星系
等 级:版主
威 望:216
帖 子:1509
专家分:9241
注 册:2010-3-16
收藏
得分:0 
回复 6楼 caihua
这个代码我用g++,bcc,vc2012都能编译通过。

附图。
图片附件: 游客没有浏览图片的权限,请 登录注册
2013-05-09 20:11
apull
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
来 自:三体星系
等 级:版主
威 望:216
帖 子:1509
专家分:9241
注 册:2010-3-16
收藏
得分:0 
我感觉你对自己写的代码不是很熟悉。呵呵。
2013-05-09 20:14
快速回复:求教c++问题,,,帮我看看这个程序,哪里有问题了啊,好多的错误不能 ...
数据加载中...
 
   



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

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