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 ...
随机推荐
- unity3d-物理引擎
简介 物理引擎就是在游戏中模拟真实的物理效果,比如,场景中有两个立方体对象,一个在空中,一个在地面上,在空中的立方体开始自由下落,然后与地面上的立方体对象发生碰撞,而物理引擎就是用来模拟真实碰撞的效果 ...
- 原生http模块与使用express框架对比
node的http创建服务与利用Express框架有何不同 原生http模块与使用express框架对比: const http = require("http"); let se ...
- VS2010/MFC编程入门之四十三(MFC常用类:CTime类和CTimeSpan类)
上一节中鸡啄米讲了MFC常用类CString类的用法,本节继续讲另外两个MFC常用类-日期和时间类CTime类和CTimeSpan类. 日期和时间类简介 CTime类的对象表示的时间是基于格林威治标准 ...
- Python 为什么要用yield
可能听说过,带有 yield 的函数在 Python 中被称之为 generator(生成器),何谓 generator ?我们先抛开 generator,以一个常见的编程题目来展示 yield 的概 ...
- linux常用命令:yum 命令
用于添加/删除/更新RPM包,自动解决包的依赖问题以及系统更新升级. 1.命令格式: yum [参数] [软件名]2.命令功能: 功能: yum提供了查找.安装.删除某一个.一组甚至全 ...
- 网络营销相关缩写名称CPM CPT CPC CPA CPS SEM SEO解析
网络营销相关缩写名称CPM CPT CPC CPA CPS SEM SEO解析 CPM CPT CPC CPA CPS SEM SEO在网络营销中是什么意思?SEO和SEM的区别是? CPM(Cost ...
- UVA756 Biorhythms
UVA756 Biorhythms crt crt裸题 因为模数已知所以有些值能直接求 #include<iostream> #include<cstdio> using na ...
- P4009 汽车加油行驶问题
P4009 汽车加油行驶问题 最短路 清一色的spfa....送上一个堆优化Dijkstra吧(貌似代码还挺短) 顺便说一句,堆优化Dj跑分层图灰常好写 #include<iostream> ...
- 在wamp 2.0环境下面安装Zend Optimizer的方法
原文链接:http://blog.sina.com.cn/s/blog_8dc13ec50101pbat.html 我是用WAMP来做PHP的服务器,进行本机测试和开发PHP项目. wamp环境是刚刚 ...
- ACM数论之旅6---数论倒数,又称逆元(我整个人都倒了( ̄﹏ ̄))
数论倒数,又称逆元(因为我说习惯逆元了,下面我都说逆元) 数论中的倒数是有特别的意义滴 你以为a的倒数在数论中还是1/a吗 (・∀・)哼哼~天真 先来引入求余概念 (a + b) % p = (a% ...