C++ primer plus 6th 6.4编程答案(仅供参考)

#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;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值