6.4
#include <iostream> 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() { bop b[4]={{"Chen shiguang","Coder","guang",1}, //初始化数组 {"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<<b->fullname<<endl;break; case 1:cout<<b->title<<endl;break; case 2:cout<<b->bopname<<endl;break; default:cout<<"wrong request!"; } } }
——————————————————————————————————————————————————
//写的错误或者不好的地方请多多指导,可以在下面留言或者给我发邮件,指出我的错误以及不足,以便我修改,更好的分享给大家,谢谢。
转载请注明出处:https://www.royalchen.com/
author:royalchen
Email:royalchen@royalchen.com
———————————————————————————————————————————————————