【发布时间】:2017-02-20 21:00:50
【问题描述】:
#include<iostream>
using namespace std;
class emp
{
public:
int en;
char name[10],des[10];
void get()
{
cout<<"enter emp no.";
cin>>en;
cout<<"enter emp name";
cin>>name;
cout<<"enter designation";
cin>>des;
}
};
class salary : public emp
{
public:
float bp,hra,da,pf,np;
void get1()
{
cout<<"enter basic pay";
cin>>bp;
cout<<"enter domestic allowance";
cin>>da;
cout<<"enter profit fund";
cin>>pf;
cout<<"enter human resource admittance";
cin>>hra;
}
void calculate()
{
np=bp+da+hra-pf;
}
void display()
{
cout<<en<<"\t"<<name<<"\t"<<des<<"\t"<<da<<"\t"<<pf<<"\t"<<np<<"\n";
}
};
int main()
{
salary s[10];
int i,n;
char ch;
cout<<"enter the no. of employees";
cin>>n;
for(i=0;i<=n;i++)
{
s[i].get();
s[i].get1();
s[i].calculate();
}
cout<<"\n eno. \t ename \t des \t bp \t hra \t da \t pf \t np \n";
for(i=0;i<=n;i++)
{
s[i].display();
}
return 0;
}
【问题讨论】:
-
请描述您面临的具体问题
-
cin>>name[10];=>cin>>name;同上des -
数组的名称是“name”和“des”。我建议访问the book list。
-
我在 CodeBlocks IDE 上写的,它在左边距显示“红色”标记,表示错误。(我不是经验丰富的程序员,请帮助)
-
如果我的名字输入 15 个字母会怎样?