求助~不知道主函数哪错了~

Iantone 2012-05-03 10:24:24
初步判断主函数错了,貌似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;
}
...全文
129 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
写给我自己 2012-05-04
  • 打赏
  • 举报
回复
//class.h

#include<iostream>
#include<string>

#ifndef CLASS_H
#define CLASS_H

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;
};
#endif


//inheritance.cpp

#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;
}
};



//main()

#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;
}

hen_hao_ji 2012-05-03
  • 打赏
  • 举报
回复
如下面这样,加括号,是调用成员函数

a.input();
a.calculate();
a.display();
按下矩阵按键在数码管上逐个显示对应的键值,键值如下: S1-S4:0-3 S4-S8:4-7 S9-S12:8-B S13-S16:C-F */ #include #define GPIO_DIG P0 #define GPIO_KEY P1 sbit LSA=P2^2; sbit LSB=P2^3; sbit LSC=P2^4; unsigned char code DIG_CODE[17]={ 0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07, 0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71}; //0、1、2、3、4、5、6、7、8、9、A、b、C、d、E、F的显示码 unsigned char KeyValue; //用来存放读取到的键值 unsigned char KeyState; //记录按键的状态,0没有,1有 unsigned char DisplayData[8]; //用来存放要显示的8位数的值 void Delay10ms(); //延时10ms void KeyDown(); //检测按键函数 void DigDisplay(); //动态显示函数 /******************************************************************************* * 函 数 名 : main * 函数功能 : 主函数 * 输 入 : 无 * 输 出 : 无 *******************************************************************************/ void main(void) { KeyState=0; while(1) { KeyDown(); if(KeyState==1) { DisplayData[7]=DisplayData[6]; DisplayData[6]=DisplayData[5]; DisplayData[5]=DisplayData[4]; DisplayData[4]=DisplayData[3]; DisplayData[3]=DisplayData[2]; DisplayData[2]=DisplayData[1]; DisplayData[1]=DisplayData[0]; DisplayData[0]=DIG_CODE[KeyValue]; KeyState=0; } DigDisplay(); } } /******************************************************************************* * 函 数 名 : DigDisplay * 函数功能 : 使用数码管显示 * 输 入 : 无 * 输 出 : 无 *******************************************************************************/ void DigDisplay() { unsigned char i; unsigned int j; for(i=0;i<8;i++) { switch(i) //位选,选择点亮的数码管, { case(0): LSA=0;LSB=0;LSC=0; break;//显示第0位 case(1): LSA=1;LSB=0;LSC=0; break;//显示第1位 case(2): LSA=0;LSB=1;LSC=0; break;//显示第2位 case(3): LSA=1;LSB=1;LSC=0; break;//显示第3位 case(4): LSA=0;LSB=0;LSC=1; break;//显示第4位 case(5): LSA=1;LSB=0;LSC=1; break;//显示第5位 case(6): LSA=0;LSB=1;LSC=1; break;//显示第6位 case(7): LSA=1;LSB=1;LSC=1; break;//显示第7位 } GPIO_DIG=DisplayData[i];//发送段码 j=10; //扫描间隔时间设定 while(j--); GPIO_DIG=0x00;//消隐 } } /******************************************************************************* * 函 数 名 : KeyDown * 函数功能 : 检测有按键按下并读取键值 * 输 入 : 无 * 输 出 : 无 *******************************************************************************/ void KeyDown(void) { unsigned int a=0; GPIO_KEY=0x0f; if(GPIO_KEY!=0x0f) { Delay10ms(); a++; a=0; if(GPIO_KEY!=0x0f) { KeyState=1;//有按键按下 //测试列 GPIO_KEY=0X0F; // Delay10ms(); switch(GPIO_KEY) { case(0X07): KeyValue=0;break; case(0X0b): KeyValue=1;break; case(0X0d): KeyValue=2;break; case(0X0e): KeyValue=3;break; // default: KeyValue=17; //检测出错回复17意思是把数码管全灭掉。 } //测试行 GPIO_KEY=0XF0; Delay10ms(); switch(GPIO_KEY) { case(0X70): KeyValue=KeyValue;break; case(0Xb0): KeyValue=KeyValue+4;break; case(0Xd0): KeyValue=KeyValue+8;break; case(0Xe0): KeyValue=KeyValue+12;break; // default: KeyValue=17; } while((a<500)&&(GPIO_KEY!=0xf0)) //按键松手检测 { Delay10ms(); a++; } a=0; } } } /******************************************************************************* * 函 数 名 : Delay10ms * 函数功能 : 延时函数,延时10ms * 输 入 : 无 * 输 出 : 无 *******************************************************************************/ void Delay10ms(void) //误差 0us { unsigned char a,b,c; for(c=1;c>0;c--) for(b=38;b>0;b--) for(a=130;a>0;a--); }
#include "iostream.h" #include "string.h" #include "stdlib.h" int g; //g是接收功能选择的变量 // 加法函数 void out() { cout<<" 程序功能:可以完成任意大数的加法,减法和比较大小"<y?m=x:m=y; ma=m; i=x-1; j=y-1; for(;m>0;i--,j--,m--) { if(j=xx) s=int(a[i])-48+jin; //将字符转换成整型 else if(i=yy) s=int(b[j])-48+jin; else if(i>=xx && j>=yy) s=(int(a[i])-48+int(b[j])-48+jin); if(s>9) { jin=1; c[m]=char(s+38); } else { jin=0; c[m]=char(s+48); } } if(jin==1) c[0]='1'; else c[0]=' '; if(g==1) { cout<<"两数相加的结果为:"; if(f==0) for(i=0;i=0;i--,j--,m--) { if(j=xx) s=int(a[i])-48-jin; else if(i>=xx&&j>=yy) s=(int(a[i])-48)-(int(b[j])-48)-jin; if(s<0) { jin=1; c[m]=char(s+58); } else { jin=0; c[m]=char(s+48); } } if(g==1) { cout<<"两数相加的结果为:"; if(f==0) for(i=0;iy) { if(a[0]=='-') cout<<"数一小于数二"<b[i]) { cout<<"数一小于数二"<b[i]) { cout<<"数一大于数二"<主函数 void main() { char a[100]; char b[100]; char yn; int f,d; int x,y; out(); cout<<" 输入第一个大数:"; cin>>a; cout<<" 输入第二个大数:"; cin>>b; while(1) { cout<<"(1:加法 2:减法 3:比较 4:乘法 5:除法 6:求余)请选择:"; cin>>g; x=strlen(a); y=strlen(b); if(a[0]=='-' && b[0]=='-' && g==1) { f=1; d=3; add(a,b,x,y,f,d); } if(a[0]!='-' && b[0]!='-' && g==1) { f=0; d=0; add(a,b,x,y,f,d); } if(a[0]=='-' && b[0]!='-' && g==1) { if(x-1>y) { f=1; d=1; jian(a,b,x,y,f,d); } if(x-1==y) { for(int i=0;ib[i]) { f=1; d=1; jian(a,b,x,y,f,d); break; } if(a[i+1]y-1) { f=0; d=2; jian(a,b,x,y,f,d); } if(x==y-1) { for(int i=0;ib[i+1]) { f=0; d=2; jian(a,b,x,y,f,d); break; } if(a[i]y) { f=1; d=1; jian(a,b,x,y,f,d); } if(x==y) { for(int i=1;ib[i]) { f=1; d=1; jian(a,b,x,y,f,d); break; } if(a[i]y) { f=0; d=0; jian(a,b,x,y,f,d); } if(x==y) { for(int i=0;ib[i]) { f=0; d=0; jian(a,b,x,y,f,d); break; } if(a[i]>yn; if(yn!='Y' && yn!='y') break; } }赞同0| 评论 向TA求助 回答者: PFanAya | 四级采纳率:27% 擅长领域: C/C++ 参加的活动: 暂时没有参加的活动 提问者对回答的评价: 谢了 相关内容 2012-2-6 请设计一个有效的算法,可以进行两个n位大整数的乘法运算。 2011-5-31 c语言题目 1.编写两个函数,输入的整数按字符串形式逆序输出,要求... 2011-4-21 用c语言表达,输出 思路写两个例子,不要printf("\n").其次:需... 2 2011-4-3 请你设计个算法,在整数边长的直角三角形ABC的斜边c的长度确定的情... 2009-5-14 如何用栈设计个C语言计算器,高手请跟我说说算法,特别是那些括号... 7 更多相关问题>> 查看同主题问题: 整数 乘法 c++ 算法 长度 两个 其他回答 共2条 2010-10-4 09:56 alfredzzj | 三级 网上很多的呀,Google一下。 按照乘法的运算思想就可以,这是每次都将进位缓存起来。 赞同0| 评论 2010-10-5 13:44 陈学阳 | 十二级 感觉这个好~~你可以挨着比较两个字符,需要匹配的可以不去比较,或者是问号的就当成是相等的字符 bool Match(const char* pSrc,const char* pMatch) { while(*pSrc!=0) { if(*pMatch==0) return false; if(*pMatch != '?' && *pSrc != *pMatch) return false; pMatch++; pSrc++; } if(*pMatch!=0) return false; else return true; }

64,681

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧