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

求帮忙 急解决方案

2013-06-26 
求帮忙 急急急!#include iostreamusing namespace std#include stringconst int t100int a[4]int

求帮忙 急急急!
#include <iostream>
using namespace std;
#include <string>
const int t=100;
int a[4];
int m=0;
class A
{
private:
    string n;
protected:

    float b; 
public:
   void setn(string n){this->n=n;}
   string getn(){return n;}
   float getb(){return b;}
void show()
{cout<<n<<endl;}
};
class B:public A
{
private:
int c;
float d;
public:
void Setc(int c){this->c=c;}
void Setd(float d){this->d=d;}
  void pay(){b=c*d;}
};
class C:public A{
protected:
int e;
float f;
public:
void sete(float e){this->e=e;}
void setf(float f){this->f=f;}
void pay(){b=e*f;}
};
class D:public A{
protected:
float g;
public:
void setg(float g){this->g=g;}
void pay(){b=g;}
};
int main()
{   
int i,j,k,q;
int a[4]={0,0,0,0};
string n;
        int c;
float d,e,f;
        A z[t];
B w[t];
C r[t];
 while(1){
  cout<<"1.添加信息"<<endl;
cout<<"2.浏览信息"<<endl;
cout<<"3.退出程序"<<endl;
cout<<"选择1-3:"<<endl;
    cin>>j;
switch(j){      
    case 1:cout<<"1A,2B,3C>"<<endl;cin>>k;
  switch(k)
  {
  case 1:
   cin>>n;z[a[0]].setn(n);z[a[0]].getn();
  cin>>c;z[a[0]].Setc(c);
                  cin>>d;z[a[0]].Setd(d);
  z[a[0]].pay();a[0]++;break;
  }m++;break;
case 2:
switch(m){
        case 0:break;
default:
for(q=0;q<a[0];q++){z[q].show();}
                         break;
}break;
case 3:return 0;break;
default:break;}
  }
return 0;
}
我不想在主函数中接收那么多 想用一个函数接收 怎么才能实现?
[解决办法]
void read_z(B z[], int a[])
{
int k = 0,c = 0, d = 0;
string n;
cout<<"1A,2B,3C>"<<endl;cin>>k;
switch(k)
{
case 1:
cin>>n;z[a[0]].setn(n);z[a[0]].getn();
cin>>c;z[a[0]].Setc(c);
cin>>d;z[a[0]].Setd(d);
z[a[0]].pay();a[0]++;break;
}
m++;
}


...
switch(j)
{      
case 1:
read_z(z, a);
break;


case 2:
...
[解决办法]

void Enter(technician *t, int *no, string name, string empNo, int workHours, float hourlyRate)
{
(t + *no)->setname(name);
(t + *no)->getname();
(t + *no)->setempNO(empNo);
(t + *no)->getempNO();
(t + *no)->SetWorkHours(workHours);
(t + *no)->SethourlyRate(hourlyRate);
(t + *no)->pay();
(*no)++;
}

case 1:
cout<<"输入员工姓名:";cin>>name;
cout<<"输入员工编号:";cin>>empNO;
cout<<"输入工作时间:";cin>>Rate;
cout<<"输入工资:";cin>>hourlyRate;
Enter(t01, &a[0], name, empNO, Rate, hourlyRate);
break;

热点排行