1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
|
#include <iostream>
#include <cctype>
#include <string>
struct bop {
char fullname[40]; // real name
char title[20]; // job title
char bopname[40]; // secret BOP name
int preference; // 0 = fullname, 1 = title, 2 = bopname
};
int main()
{
using namespace std;
bop Programmer[5] = {
"Alex Ignatkov","System Analyst","IGNAT",2,
"Bob Emerson","Manager","BOBZ",1,
"John Doe","Programmer","DOE",0,
"Bob Evans","Debugger","EVS",2,
"Nick Johns","Tester","NJ",1};
char choice;
cout << "a. display by name b. display by title\n";
cout << "c. display by bopname d. display by preference\nq. quit\n";
do
{
cout << "\nEnter your choice: ";
cin >> choice;
choice = tolower(choice);
if (choice != 'a' && choice != 'b' && choice !='c' && choice !='d')
continue;
else for (int i=0; i<5; i++)
{
switch (choice)
{
case 'a': cout << "\n" << Programmer [i].fullname;break;
case 'b': cout << "\n" << Programmer [i].title;break;
case 'c': cout << "\n" << Programmer [i].bopname;break;
case 'd': switch (Programmer[i].preference)
{
case 0: cout << "\n" << Programmer [i].fullname;break;
case 1: cout << "\n" << Programmer [i].title;break;
case 2: cout << "\n" << Programmer [i].bopname;break;
}
}
}
} while (choice != 'q');
cout << "\nBye!\n";
cin.get();
cin.get();
return 0;
}
|