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 ...
随机推荐
- react-native 0.57 run-ios 失败解决办法
React Native 日常报错 'config.h' file not found 版权声明:本文为博主原创文章,未经博主允许不得转载. https://blog.csdn.net/qq_ ...
- 27. Remove Element(双指针)
Given an array nums and a value val, remove all instances of that value in-place and return the ne ...
- minicom的安装和tftp的安装
1.minicom 的安装 在弹出的窗口中选择“Serial port setup”进行配置.配置完之后选择“Save setup as dfl”保存.最后选择“Exit from Minicom”退 ...
- 20165207 Exp2 后门原理与实践
20165207 Exp2 后门原理与实践 〇.实验准备 两个虚拟机,一个kali一个win7.kali的ip是192.168.43.72,win7的ip是192.168.43.116,在win7关掉 ...
- 保护Hadoop集群三大方法
自今年以来,不少恶意软件开始频繁向Hadoop集群服务器下手,受影响最大的莫过于连接到互联网且没有启用安全防护的Hadoop集群. 大约在两年前,开源数据库解决方案MongoDB以及Hadoop曾遭受 ...
- python之路----钻石继承
钻石继承 继承顺序 class A(object): def test(self): print('from A') class B(A): def test(self): print('from B ...
- mysql与oracle常用函数及数据类型对比00持续补充
最近在转一个原来使用oracle,改为mysql的系统,有些常用的oracle函数的mysql实现顺便整理了下,主要是系统中涉及到的(其实原来是专门整理过一个详细doc的,只是每次找word麻烦). ...
- velocity #parse抽象重用部分组件
在某些时候,处于重用的目的,我们会选择将可以重用的部分内容剥离在单独的模板文件中,比如对于查询页面的表格部分,因为现在很多的条件可能是通过弹出查询框的方式来实现,而作为普通页面的时候,他们会有更多的功 ...
- 01: socket模块
网络编程其他篇 目录: 1.1 socket理论部分 1.2 socket处理单个连接 和 同时接受多个连接 1.3 socket实现远程执行命令,下载文件 1.4 通过socket实现简单的ssh ...
- 20145322何志威 Exp8 Web基础
20145322何志威 Exp8 Web基础 实践过程记录 一.Apache 1 修改/etc/apache2/ports.conf里的端口为5322后重新开启: 2 可以在浏览器中输入localho ...