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 ...
随机推荐
- MySQL用户授权 和 bin-log日志 详解和实战(http://www.cnblogs.com/it-cen/p/5234345.html)
看 了上一篇博文的发布时间,到目前已经有三个月没更新博文了.这三个月经历了很多事情,包括工作.生活和感情等等.由于个人发展的原因,这个月准备换工作 啦.在这段时间,我会把Web大型项目中所接触到的技术 ...
- n的二进制中有几个1
实例十七:n的二进制中有几个1 方法:result=n & (n-1) n&(n-1)的目的使最低位的1不断翻转. 比如:n=108,其二进制表示为0110 1100,则n& ...
- Hive 常用优化参数
常用调优测试语句 : ①显示当前hive环境的参数值: set 参数名; 如: hive> set mapred.map.tasks;mapred.map.tasks; ②设置hi ...
- Linux基础命令---zip
zip zip是一种最通用的文件压缩方式,使用于unix.msdos.windows.OS等系统.如果在编译zip时包含bzip 2库,zip现在也支持bzip 2压缩.当将大于4GB的文件添加到存档 ...
- MySQL Crash Course #09# Chapter 17. Combining Queries: UNION
INDEX UNION Rules WHERE VS. UNION UNION VS. UNION ALL Sorting Combined Query Results UNION Rules As ...
- INNODB引擎概述
INNODB存储引擎的历史概述: INNODB存储引擎是OLTP应用中核心表的首选存储引擎. INNODB存储引擎包含在所有mysql数据库的二进制发行版本中.早期其版本随着mysql数据库的更新而更 ...
- 浏览器内核、排版引擎、js引擎
[定义] 浏览器最重要或者说核心的部分是“Rendering Engine”,可大概译为“渲染引擎”,不过我们一般习惯将之称为“浏览器内核”.负责对网页语法的解释(如标准通用标记语 言下的一个应用HT ...
- spring mybatis 3.2调用mysql存储过程返回多结果集(完整、亲测、可用)
最近,有个开发提了个需求,希望中间件支持调用mysql存储过程时支持多结果集返回,因为某些原因我们使用了不少的存储过程,很多复杂的逻辑目前来看交互非常的多,所以从当前的现状来说,这个需求还是蛮合理的. ...
- Android Socket 知识点汇总
版权声明:这篇博客资料来源 https://blog.csdn.net/carson_ho/article/details/53366856 , 未经授权,严禁转发! 一.网络基础 1.1 计算机网络 ...
- 20162311 Hash 补分博客
20162311 Hash 补分博客 一.任务详情 二.解题过程 除留余数法和拉链法都懂了,也都会做,主要是开放寻址法.课下查了一些资料,也问了老师才彻底理解 引用例子 引用网上的一个例子来理解 参考 ...