C++.Primer.Plus第五版第五章编程练习答案
来源:互联网 发布:陆奥号战列舰 知乎 编辑:程序博客网 时间:2024/05/01 16:02
// 1#include <iostream>using namespace std;int main(){cout << "This progress need tow int numbers:\n";int int1,int2;cout << "Please input the little number: \n";cin >> int1;cout << "Please input the big number: ";cin >> int2;int total = 0;for(int comp = int1;comp <= int2; comp++)total += comp;cout << "total = " << total << endl;return 0;}// 2#include <iostream>using namespace std;int main(){ int num,num_total= 0; cin >> num; while(num != 0) { num_total+= num; cout << "num_total = " << num_total << endl; cin >> num; } cout << "num_total = " << num_total << endl; /*while(cin >> i && i) sum+= i,cout << sum<< endl;*/ return 0;}// 3#include <iostream>using namespace std;int main(){int Daphne = 100,Cleo = 100,year = 0;while(Cleo <= Daphne){Daphne += 100 * 10 / 100;Cleo += Cleo * 5 / 100;year ++;}cout << year << "years latter :\n"; cout << "Daphne = " << Daphne << endl;cout << "Cleo = " << Cleo << endl;return 0;}// 4#include <iostream>#define MONTH_TOTAL 12using namespace std;int main(){ const char * month[MONTH_TOTAL] = {"January","February","March","April","Mary","June","July","August","September","October","November","December"};int salo[MONTH_TOTAL] = {},sum = 0;for(int i = 0; i < MONTH_TOTAL; i++){cout << month[i] << ":\t\t\t ";cin >> salo[i];sum += salo[i];}cout << "total = " << sum << endl;return 0;}// 5 #include <iostream>#define MONTH_TOTAL 12#define YEAR_TOTAL 3 using namespace std;int main(){ const char * month[MONTH_TOTAL] = {"January","February","March","April","Mary","June","July","August","September","October","November","December"};int salo[YEAR_TOTAL][MONTH_TOTAL] = {},sum = 0,year = 0,i = 0;while(year < YEAR_TOTAL){if(i == MONTH_TOTAL){year ++;i = 0;if(year == YEAR_TOTAL)break;}cout << year << "\t" << month[i] << ":\t\t\t ";cin >> salo[year][i];sum += salo[year][i++];}cout << "total = " << sum << endl;return 0;}// 6 注意cin.get()所在位置及作用 当输入多个字符串时!#include <iostream>#include <string>using namespace std;struct car {//string maker;char maker[100];int year;};int main(){cout << "How many cars do you wish to catalog: ";int car_number;//cin.get();cin >> car_number;car * car_info = new car [car_number];for(int i = 0; i < car_number; i++){cout << "Car\t#" << i + 1 << ":\n" ;cout << "Please enter the maker: ";//cin >> car_info[i].maker;cin.get();cin.getline(car_info[i].maker,100);//cout << "maker:" << car_info[i].maker << endl;cout << "Please enter the year made: ";cin >> car_info[i].year;}cout << "Here is your collection:\n";for(int i = 0; i < car_number; i++)cout << car_info[i].year << "\t" << car_info[i].maker << endl;delete [] car_info;return 0;}// 7#include <iostream>#include <cstring>using namespace std;int main(){cout << "Enter words (to stop, type the word done):\n";int count = 0;while(1){char string[100];cin >> string;if(strcmp(string,"done") == 0)break;elsecount++;}cout << "You entered a total of " << count << " words.\n";return 0;}// 8#include <iostream>#include <string>using namespace std;int main(){cout << "Enter words (to stop, type the word done):\n";int count;while(1){string str;cin >> str;if(str == "done")break;elsecount++;}cout << "You entered a total of " << count << " words.\n";return 0;}// 9#include <iostream>using namespace std;int main(){int line;cout << "Please input a number: ";cin >> line;for(int i = 0; i < line; i++){for(int dian = 0; dian < line - i - 1; dian++)cout << ".";for(int xing = 0;xing <= i; xing++)cout << "*";cout << endl;}return 0;}
0 0
- C++.Primer.Plus第五版第五章编程练习答案
- C Primer Plus (第五版) 第五章 编程练习 答案
- c++.primer.plus第五版第六章编程练习答案
- c++.primer.plus第五版第七章编程练习答案
- c++.primer.plus第五版第八章编程练习答案
- c++.primer.plus第五版第九章编程练习答案
- c++.primer.plus第五版第十章编程练习答案
- C Primer Plus (第五版) 第六章 编程练习 答案
- C++ Primer Plus第五版 第五章 编程练习答案
- C primer plus 第五章 编程练习个人答案
- C primer plus(第五版)编程练习第五章
- C++ Primer Plus第六版 第五章 编程练习答案
- C++ Primer Plus第五版 第四章 编程练习答案
- C++ Primer Plus第五版 第三章 编程练习答案
- C++ Primer Plus第五版 第二章 编程练习答案
- C++ Primer Plus第五版 第六章 编程练习答案
- C++ Primer Plus第五版 第七章 编程练习答案
- C++ Primer Plus第五版 第八章 编程练习答案
- iOS 纯代码适配iPhone6,6+
- Spring MVC注释集合
- Spring事务配置的五种方式及事务传播相关
- Akka---容错
- navicat for mysql中SSH连接方式
- C++.Primer.Plus第五版第五章编程练习答案
- c语言有符号数和无符号类型计算
- SpringMVC基于zyUpload组件实现上传
- Codeforces 551C GukiZ hates Boxes 二分答案
- android一键退出整个APP
- C和C++混合编程(error C2059: syntax error : 'string')
- 2012年5月SAT香港真题解析
- PHP mysqul连接数据库,执行查询语句,打印返回结果集和断开数据库
- leetCode(38):Lowest Common Ancestor of a Binary Search Tree