c++ primer plus 第五章 课后题答案
- #include <iostream>
- using namespace std;
- int main()
- {
- int num_1,num_2,sum=;
- cout << "Please enter two number: ";
- cin >> num_1;
- cin >> num_2;
- if (num_1 > num_2)
- {
- int a;
- a = num_1;
- num_1 = num_2;
- num_2 = a;
- }
- for (int i = num_1; i <= num_2; i++)
- {
- sum += i;
- }
- cout << "The sum of num_1-num_2 is " << sum << endl;
- system("pause");
- }
- #include <iostream>
- #include <array>
- using namespace std;
- const int num=;
- int main()
- {
- array<long double, num+> jiecheng;
- jiecheng[] = jiecheng[] = ;
- cout << << "! = " << jiecheng[] << endl;
- cout << << "! = " << jiecheng[] << endl;
- for (int i = ; i <= num; ++i)
- {
- jiecheng[i] = i * jiecheng[i - ];
- cout << i << "! = " << jiecheng[i]<<endl;
- }
- system("pause");
- }
- #include <iostream>
- #include <array>
- using namespace std;
- int main()
- {
- int a,b=;
- cout << "Please enter a number other than zero: ";
- do
- {
- cin >> a;
- if (a == )
- cout << "Stop summing!\n";
- else
- {
- b = b + a;
- cout << "The sum of the numbers already entered is: " << b << endl;
- }
- } while (a != );
- system("pause");
- }
- #include <iostream>
- using namespace std;
- const float lixi1 = 0.1;
- const float lixi2 = 0.05;
- int main()
- {
- float Daphne_i = , Cleo_i = , Daphne = Daphne_i, Cleo = Cleo_i;
- int year = ;
- while (Daphne >= Cleo)
- {
- Daphne = Daphne + Daphne_i * lixi1;
- Cleo = Cleo + Cleo * lixi2;
- year += ;
- // cout << Daphne << "," << Cleo<<"--"<< year<<endl;
- }
- cout << "In " << year << "th years, Cleo's funds exceed Daphne.\nAt this time, the funds of Cleo are " << Cleo << ", and the funds of Daphne are " << Daphne << ".\n";
- system("pause");
- }
- #include <iostream>
- using namespace std;
- const int month = ;
- int main()
- {
- int num[month];
- int sum = ;
- const char* months[month] = { "January","February","March","April","May","June","July","August","September","October","November","December" };
- cout << "Please enter the monthly sales volume:\n";
- for (int i = ; i < month; ++i)
- {
- cout << months[i] << " : ";
- cin >> num[i];
- sum += num[i];
- }
- cout << "The total sales this year is " << sum << ".\n";
- system("pause");
- }
- #include <iostream>
- using namespace std;
- const int year = ;
- const int month = ;
- int main()
- {
- int num[year][month];
- int sum[] = { ,,, };
- const char* months[month] = { "January","February","March","April","May","June","July","August","September","October","November","December" };
- for (int j = ; j < year; ++j)
- {
- cout << "Please enter the monthly sales volume of " << j + << "th year:\n";
- for (int i = ; i < month; ++i)
- {
- cout << months[i] << " : ";
- cin >> num[j][i];
- sum[j] += num[j][i];
- }
- cout << "The total sales of " << j+ << "th year is "<< sum[j] << ".\n";
- sum[year] = sum[year] + sum[j];
- }
- cout << "The total sales of " << year << " years are "<<sum[year] << ".\n";
- system("pause");
- }
- #include <iostream>
- #include <string>
- using namespace std;
- struct car
- {
- string make;
- int year;
- };
- int main()
- {
- int num;
- cout << "How many cars do you wish to catalog?";
- cin >> num;
- car *all_car = new car[num];
- for (int i = ; i < num; ++i)
- {
- cout << "Car #" << i+ << endl;
- cout << "Please enter the make : ";
- cin.ignore();
- getline(cin, all_car[i].make);
- cout << "Please enter the year made : ";
- cin >> all_car[i].year;
- }
- cout << "Here is your collection:\n";
- for (int i = ; i < num; ++i)
- {
- cout << all_car[i].year << " " << all_car[i].make << endl;
- }
delete [] all_car;- system("pause");
- }
- #include <iostream>
- #include <cstring>
- using namespace std;
- const int num_words = ;
- int main()
- {
- char words[];
- int s = ;
- bool flag = true;
- cout << "Enter words (to stop, tpye the word done) :\n";
- for (int i = ; i < num_words; ++i)
- {
- cin >> words;
- if (flag && !strcmp(words, "done"))
- flag = false;
- if (flag && strcmp(words, "done"))
- s += ;
- }
- cout << "Your entered a total of " << s << " words.\n";
- system("pause");
- }
- #include <iostream>
- #include <string>
- using namespace std;
- const int num_words = ;
- int main()
- {
- const string sstop_word = "done";
- string str;
- int s = ;
- bool flag = true;
- cout << "Enter words (to stop, tpye the word done) :\n";
- for (int i = ; i < num_words; ++i)
- {
- cin >> str;
- if (flag && str== sstop_word)
- flag = false;
- if (flag && !(str == sstop_word))
- s += ;
- }
- cout << "Your entered a total of " << s << " words.\n";
- system("pause");
- }
- #include <iostream>
- using namespace std;
- int main()
- {
- int num;
- cout << "Enter number of rows: ";
- cin >> num;
- for (int i = ; i < num; ++i)
- {
- for (int j = ; j < (num - i); ++j)
- cout << ".";
- for (int j = ; j < i; ++j)
- cout << "*";
- cout << endl;
- }
- system("pause");
- }
c++ primer plus 第五章 课后题答案的更多相关文章
- c++ primer plus 第七章 课后题答案
#include <iostream> using namespace std; double HAR_AVG(double, double); void TEST(bool); int ...
- c++ primer plus 第六章 课后题答案
#include <iostream> #include <cctype> using namespace std; int main() { char in_put; do ...
- c++ primer plus 第四章 课后题答案
#include<iostream> #include<string> using namespace std; int main() { string first_name; ...
- c++ primer plus 第三章 课后题答案
#include<iostream> using namespace std; int main() { ; int shen_gao; cout <<"Please ...
- C程序设计(谭浩强)第五版课后题答案 第一章
大家好,这篇文章分享了C程序设计(谭浩强)第五版课后题答案,所有程序已经测试能够正常运行,如果小伙伴发现有错误的的地方,欢迎留言告诉我,我会及时改正!感谢大家的观看!!! 1.什么是程序?什么是程序设 ...
- c++ primer plus 第二章 课后题答案
#include<iostream> using namespace std; int main() { cout << "My name is Jiantong C ...
- python核心编程第5章课后题答案
5-8Geometry import math def sqcube(): s = float(raw_input('enter length of one side: ')) print 'the ...
- python核心编程第4章课后题答案(第二版75页)
4-1Python objects All Python objects have three attributes:type,ID,and value. All are readonly with ...
- python核心编程第3章课后题答案(第二版55页)
3-4Statements Ues ; 3-5Statements Use\(unless part of a comma-separated sequence in which case \ is ...
随机推荐
- 摘自(http://www.ruanyifeng.com/blog/2011/07/linux_load_average_explained.html)
理解Linux系统负荷 作者: 阮一峰 一.查看系统负荷 如果你的电脑很慢,你或许想查看一下,它的工作量是否太大了. 在Linux系统中,我们一般使用uptime命令查看(w命令和top命令也行) ...
- Django初级手册3-视图层与URL配置
设计哲学 在Django中一个视图有指定函数和指定模版组成.对于某些特定的应用应该分成若干视图.例如博客系统 Blog主页面 详细页面入口 基于年的页面展示 基于月的页面展示 基于天的页面展示 评论行 ...
- java的时间处理
采用joda.time库 gradle,可以简化calendar的 compile "joda-time:joda-time:2.7" 例子:http://blog.csdn.ne ...
- VS2010/MFC编程入门之五十一(图形图像:GDI对象之画刷CBrush)
上一节中鸡啄米主要讲的是画笔CPen的用法,前面也说了,GDI对象中最常用的就是画笔和画刷,本节就讲讲画刷CBrush. 鸡啄米依然是通过实例的方式来说明画刷的用法.此实例要实现的功能是,对话框上有一 ...
- EditPlus 4.3.2555 中文版已经发布
新的版本修复了之前版本出现的多行文本缩进调整的问题. 下载连接在页面左上角!
- jQuery 批量操作checkbox
困扰很久的问题: 如果只是 $('input[type=checkbox]').attr('checked',true);//全选 $('input[type=checkbox]').attr('ch ...
- ROS知识(2)----理解ROS系统结构
学习新事物,方法高于技术本身,如果没有把握"BIG PICTURE"的话很难理解进去.通过以下几点进行理解ROS: ROS实际上不是操作系统,他只是一个通信的框架,一个代码管理的架 ...
- 完美解决Linux服务器tomcat开机自启动问题
经过多次测试终于彻底解决tomcat开机自启动的问题了 PID3=`ps aux | grep /home/server/shichuan/ | grep java | awk '{print $2} ...
- 基于webview的Hybrid app和React Native及html5
基于webview的Hybrid app和React Native及html5 React Native 结合了 Web 应用和 Native 应用的优势,可以使用 JavaScript 来开发 iO ...
- linux chkconfig 管理服务开机自启动
chkconfig命令主要用来更新(启动或停止)和查询系统服务的运行级信息.谨记chkconfig不是立即自动禁止或激活一个服务,它只是简单的改变了符号连接. 使用语法:chkconfig [--ad ...