编程菜鸟的日记-初学尝试编程-C++ Primer Plus 第6章编程练习4

#include <iostream>
using namespace std;
const int strsize=30;
const int BOPSIZE=5;
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";
}
struct bop
{
	char fullname[strsize];
	char title[strsize];
	char bopname[strsize];
	int preference;
};
int main()
{
	showmenu();
	char ch;
	int i;
	bop newbop[BOPSIZE]=
	{
		{"Wimp Macho","Teahcer","WWW",0},
		{"Raki Rhodes","Junior Programmer","RRR",1},
		{"Celia Laiter","Star","MIPS",2},
		{"Hoppy Hipman","Analyst Trainee","HHH",1},
		{"Pat Hand","Doctor","LOOPY",2}
	};
	cout<<"Enter your choice: ";
	while(cin>>ch && ch!='q')
	{
		switch(ch)
		{
		case 'a':
			for(i=0;i<BOPSIZE;i++)
				cout<<newbop[i].fullname<<endl;
			break;
		case 'b':
			for(i=0;i<BOPSIZE;i++)
				cout<<newbop[i].title<<endl;
			break;
		case 'c':
			for(i=0;i<BOPSIZE;i++)
				cout<<newbop[i].bopname<<endl;
			break;
		case 'd':
			for(i=0;i<BOPSIZE;i++)
			{
				if(0==newbop[i].preference)
					cout<<newbop[i].fullname<<endl;
				else if(1==newbop[i].preference)
					cout<<newbop[i].title<<endl;
				else if(2==newbop[i].preference)
					cout<<newbop[i].bopname<<endl;
			}
		  	  break;
		  //case 'q':cout<<"Bye!\n";
		}
		cout<<"Next choice: ";
	}
	cout<<"Bye!\n";
	system("pause");
	return 0;
}
		

 

转载于:https://www.cnblogs.com/lynnycy/p/3453207.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值