首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ >

~不知道主函数哪错了

2012-05-07 
求助~不知道主函数哪错了~初步判断主函数错了,貌似switch有问题此程序是计算四类职员工资//定义基类#inclu

求助~不知道主函数哪错了~
初步判断主函数错了,貌似switch有问题
此程序是计算四类职员工资


//定义基类
#include<iostream>
#include<string>
using namespace std;
class Pay
{
public:
void input()
{
cout<<"Please input the num:";
cin>>num;
  cout<<"Please input the name:";
cin>>name;
}
void display()
{
cout<<"num:"<<num<<endl;
cout<<"name:"<<name<<endl;
cout<<"salary:"<<salary<<endl;
}
protected:
int num;
string name;
  int salary;
};





//派生类
#include"class.h"
//经理
class Manager:virtual public Pay
{
public:
void calculate()
{
salary=8000;
}
};
//兼职技术人员
class Technician:public Pay
{
public:
void inputtime()
{
cout<<"Please input the worktime:";
cin>>worktime;
}
void calculate()
{
salary=worktime*100;
}
private:
int worktime;
};
//销售员
class Salesman:virtual public Pay
{
public:
void calculate()
{
salary=salesvolume*0.04;
}
void inputsalesvolume()
{
cout<<"Please input the salesvolume:";
cin>>salesvolume;
}
protected:
int salesvolume;
};
//销售经理(经理和销售员的派生类)
class Salesmanager:public Manager,public Salesman
{
public:
void calculate()
{
salary=salesvolume*0.05+5000;
}
};





//主函数
#include"inheritance.cpp"
int main()
{
int choice;
do 
{
cout<<"\n[salary calculator]\n";
cout<<"-------------------------------\n";
cout<<"Please choose the staff member:\n";
cout<<"<1> Manager\n";
cout<<"<2> Technician\n";
cout<<"<3> Salesman\n";
cout<<"<4> Salesmanager\n";
cout<<"-------------------------------\n";
cout<<"<0> Quit\n";
cin>>choice;
switch(choice)
{
case 1:
{Manager a;
a.input;
a.calculate;
a.display;
};break;
case 2:
{Technician b;
b.input;
b.inputtime;
b.calculate;
b.display;
};break;
case 3:
{Salesman c;
c.input;
c.inputsalesvolume;
c.calculate;
c.display;
};break;
  case 4:
{Salesmanager d;
d.input;
d.calculate;
d.display;
};break;
}
}while (choice!=0);
return 0;
}

[解决办法]
如下面这样,加括号,是调用成员函数

C/C++ code
    a.input();                a.calculate();                a.display();
[解决办法]
//class.h

C/C++ code
#include<iostream>#include<string>#ifndef CLASS_H#define CLASS_Husing namespace std;class Pay{public:    void input()    {        cout<<"Please input the num:";        cin>>num;        cout<<"Please input the name:";        cin>>name;    }    void display()    {        cout<<"num:"<<num<<endl;        cout<<"name:"<<name<<endl;        cout<<"salary:"<<salary<<endl;    }protected:    int num;    string name;    int salary;};#endif 

热点排行