#include <iostream>
void menu(void);
const int strsize=20;
using namespace std;
struct bop{
char fullname[strsize];
char title[strsize];
char bopname[strsize];
int preference;
};
int main() {
bop arr[3]={
{"Wimp Macho","wa haha","nikon",2},
{"Raki Rhodes","hao di","canon",0},
{"Calia Laiter","da wang","fujji",1}
};
menu();
cout<<"Enter your choice:";
char ch;
cin.get(ch).get();
while(ch!='q')
{
switch(ch)
{
case 'a':
for(int i=0;i<3;++i)
cout<<arr[i].fullname<<endl;
break;
case 'b':
for(int i=0;i<3;++i)
cout<<arr[i].title<<endl;
break;
case 'c':
for(int i=0;i<3;++i)
cout<<arr[i].bopname<<endl;
break;
case 'd':
for(int i=0;i<3;++i)
if(arr[i].preference==0)
cout<<arr[i].fullname<<endl;
else if(arr[i].preference==1)
cout<<arr[i].title<<endl;
else
cout<<arr[i].bopname<<endl;
break;
default :cout<<"Please enter a a,b,c or q:";
cin.get(ch).get();
continue;
}
cout<<"Next choice:";
cin.get(ch).get();
}
cout<<"bye!"<<endl;
return 0;
}
void menu(void)
{
cout<<"Benevolent order of Programmers Report"<<endl;
cout<<"a. display by name b. display by title"<<endl
<<"c. display by bopname d. display by preference"<<endl
<<"q. quit"<<endl;
}
C++ primer plus 6th 6.4编程答案(仅供参考)
最新推荐文章于 2024-11-10 21:41:28 发布