C++ Primer Plus 6.4

#include <iostream>
using namespace std;
const int strsize=20;
const int listsize=5;
void showmenu();
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
};

int main()
{

 char ch;
 int i=0;
 bop namelist[listsize]=
 {
  {"Wimp Macho","Junior Programer","WM",1},
  {"Raki Rhodes","Junior Programer","RaR",2},
  {"Celia Laiter","Senior Programer","MIPS",3},
  {"Hoppy Hipman","Analyst Traniee","Hman",2},
  {"Pat Hand","Analyst Expert","LOOPY",3}
 };
 showmenu();
 cout<<"Enter your choice: ";
 cin>>ch;
 if(ch>='a'&&ch<='d'||ch>='A'&&ch<='D'||ch=='q'||ch=='Q')
 {
  while(ch!='q'&&ch!='Q')
  {
   switch(ch)
   {
   case 'a':
   case 'A':for(i=0;i<listsize;i++) cout<<namelist[i].fullname<<endl;
    break;
   case 'b':
   case 'B':for(i=0;i<listsize;i++) cout<<namelist[i].title<<endl;
    break;
   case 'c':
   case 'C':for(i=0;i<listsize;i++) cout<<namelist[i].bopname<<endl;
    break;
   case 'd':
   case 'D':for(i=0;i<listsize;i++)
      {
       if(namelist[i].preference==1) cout<<namelist[i].fullname<<endl;
       else if(namelist[i].preference==2) cout<<namelist[i].title<<endl;
       else if(namelist[i].preference==3) cout<<namelist[i].bopname<<endl;
       else cout<<"wrong preference"<<endl;
      }
    break;
   default:cout<<"The program shouldn't get here!/n";
    break;
   }
   cout<<"Next choice: ";
   cin>>ch;
  }
  cout<<"Bye!/n";

 }
 return 0;
}

void showmenu()
{
 cout<<"Benevolent Order of Programmers Report/n"
  "a. display by name b. display by title/n"
  "c. display by bopname d.display by preference/n"
  "q. quit/n";
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值