6.4
#include
using namespace std;
const int strsize=20;
struct bop{
char fullname[strsize];//real name
char title[strsize];//job title
char bopname[strsize];//secret BOP name
int preference;//0=fullname 1=title 2=bopname
};
void getCout(char c,bop *b);
void main64()
{
{“Lijing”,”Student”,”Li”,2},
{“Lijing2”,”Student2”,”Li2”,2},
{“Chenguang”,”dent”,”ci”,0}
};
cout<<”Benevolent order of Programmers Report”<<endl;
cout<<”a.display by name b.display by title”<<endl;
cout<<”c.display by bopname d.display by priference”<<endl;
cout<<”q.quit”<<endl;
cout<<”Enter your choice:”;
char ch;
cin>>ch;
while(ch!=’q’)
{
switch(ch)
{
case ‘a’:for(int i=0;i<4;i++){
cout<<b[i].fullname<<endl;
};break;
case ‘b’:for(int i=0;i<4;i++){
cout<<b[i].title<<endl;
};break;
case ‘c’:for(int i=0;i<4;i++){
cout<<b[i].bopname<<endl;
};break;
case ‘d’:getCout(ch,b);break;
default:cout<<”wrong input”<<endl;
//case ‘q’:cout<<”bye”<<endl,cin.get(),exit(1);
}
cout<<”Next Choice:”;
cin>>ch;
}
cout<<”bye”<<endl;
cin.get();
}
void getCout(char c,bop *b)//选择为preference时调用的函数
{
int s;
for(int i=0;i<4;i++,b++)
{
s=b->preference;
switch(s){
case 0:cout<
case 1:cout<
case 2:cout<
default:cout<<”wrong request!”;
}
}
}
—————————————————————————————————————————————————— //写的错误或者不好的地方请多多指导,可以在下面留言或者给我发邮件,指出我的错误以及不足,以便我修改,更好的分享给大家,谢谢。 转载请注明出处:https://www.royalchen.com/ author:royalchen Email:royalchen@royalchen.com ———————————————————————————————————————————————————
- 本文作者: royalchen
- 本文链接: http://www.royalchen.com/2016/02/24/cprimerplus第六版课后编程题答案64/
- 版权声明: 本博客所有文章除特别声明外,均采用 MIT 许可协议。转载请注明出处!