ccpp5 编程练习6.4
生活随笔
收集整理的這篇文章主要介紹了
ccpp5 编程练习6.4
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
2019獨角獸企業重金招聘Python工程師標準>>>
此網站上有參考XD:?http://www.ignatkov.net/cppprimerplus/
5月3日查看,此網站已被黑。
// ex6.4 // 希望回頭想到好辦法 #include <iostream> using namespace std; const int strsize = 20; // 20 或許有點小 const int NUM = 5; void showmenu(); // Benevolent Order of Programmers name structure struct bop {char fullname[strsize]; // real namechar title[strsize]; // job titlechar bopname[strsize]; // secret BOP nameint preference; // 0 = fullname, 1 = title, 2 = bopname };int main () {// 除了書上貼出來的信息,其他瞎編bop bops[NUM] = {{"Wimp Macho", "Farmer", "Wim", 0},{"Raki Rhodes", "Junior Programmer", "Rak", 1},{"Celia Laiter", "Driver", "MIPS", 2},{"Hoppy Hipman", "Analyst Trainee", "Hop", 1},{"Pat Hand", "Teacher", "LOOPY", 2}};showmenu();char ch; // choicecout << "Enter your choice: ";int i; // 不重復聲明了// 這個寫的復雜了,希望能想出好辦法while (cin >> ch && ch != 'q'){switch (ch){case 'a': for (i = 0; i < NUM; i++)cout << bops[i].fullname << endl;break;case 'b': for (i = 0; i < NUM; i++)cout << bops[i].title << endl;break;case 'c': for (i = 0; i < NUM; i++)cout << bops[i].bopname << endl;break;case 'd': for (i = 0; i < NUM; i++){switch (bops[i].preference){case 0: cout << bops[i].fullname << endl; break;case 1: cout << bops[i].title << endl; break;default: cout << bops[i].bopname << endl;}}break;default: break;}// 吞掉后面多掛的字符while ((ch = cin.get()) != '\n')continue;cout << "Next choice: ";}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";return; }轉載于:https://my.oschina.net/u/727594/blog/119006
總結
以上是生活随笔為你收集整理的ccpp5 编程练习6.4的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 马云马化腾李彦宏在IT峰会上的话-内容提
- 下一篇: Firefox扩展开发 Hello Wo