IT数码 购物 网址 头条 软件 日历 阅读 图书馆
TxT小说阅读器
↓语音阅读,小说下载,古典文学↓
图片批量下载器
↓批量下载图片,美女图库↓
图片自动播放器
↓图片自动播放器↓
一键清除垃圾
↓轻轻一点,清除系统垃圾↓
开发: C++知识库 Java知识库 JavaScript Python PHP知识库 人工智能 区块链 大数据 移动开发 嵌入式 开发工具 数据结构与算法 开发测试 游戏开发 网络协议 系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程
数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁
 
   -> C++知识库 -> c++primer plus第五章循环和关系表达式编程练习答案 -> 正文阅读

[C++知识库]c++primer plus第五章循环和关系表达式编程练习答案

#include<iostream>
int main(void)
{
	using namespace std;
	int min, max;
	cout << "please input your frist number: ";
	cin >> min;
	cout << "please input your next number: ";
	cin >> max;
	int sum = 0;
	for (int i = min; i <= max; i++)
	{
		sum += i;
	}
	cout << "the sum of " << min << "   + ... +" << max << "  is  ";
	cout << sum << endl;



	return 0;
}

2.

#include<iostream>
#include<array>
using namespace std;
const int  A = 101;
int main(void)
{
	array<long double, A>ferry;
	ferry[0] = ferry[1] = 1;
	for (int i =2; i <A; i++)
	{
		ferry[i] = i * ferry[i-1];
	}
	for (int i = 0; i < A; i++)
	{

		cout <<i<< "!= " << ferry[i]<< endl;
	}



	return 0;
}

3.

#include<iostream>
using namespace std;
int main(void)
{
	double temp, sum = 0;
	do {
		cout << "Input a numeral to add:";
		cin >> temp;
		sum += temp;
	} while (temp != 0);
	cout << "Iput end.\n" << "The sum" << sum << endl;
	
	return 0;
}

4.

#include<iostream>
using namespace std;
int main(void)
{
	const int money = 100;
	double Daphne_m = money;
	double Cleo_m = 100;
	int year = 0;

	while (Daphne_m >= Cleo_m)
	{
		Daphne_m += money * 0.1;
		Cleo_m += 0.05 * Cleo_m;
		year++;

	}
	cout << "throught " << year << "Cleo's money is more than Daphne's money" << endl;
	cout << "Cleo's money  is " << Cleo_m << "Daphne's money is " << Daphne_m << endl;


	return 0;
}

5.

#include<iostream>
#include<string>
using namespace std;
int main(void)
{
	const string Month[] = { "Jan","feb","mar","Apr","May","jun","jul","Aug","Sept","Oct","Nov",
	"Dec" };
	int sale_num[12];
	int sum = 0;
	for (int i = 0; i < 12; i++)
	{

		cout << Month[i] << ": ";
		cin >> sale_num[i];
		sum += sale_num[i];
	}
	cout << sum;

	return 0;
}

6.

#include<iostream>
#include<string>
using namespace std;
int main(void)
{
	const string month[] = { "Jan","Feb","Mar","Apr","Mar","Jun","jul",
		"Aug","Sep","Oct","Dec","Nov" };
	int sale_num[3][12];
	int year = 0;
	double sum = 0;
	for (int i = 0; i < 3; i++)
	{
		cout << "Strating " << i + 1  << " year date." << endl;
		for (int j = 0; j < 12; j++)
		{
			cout << month[j] << " : ";
			cin>> sale_num[i][j];


	
		}

		cout << "Input Done!"<<endl;

	}
	for (int i = 0; i < 3; i++)
	{
		for (int j = 0; j < 12; j++)
			sum += sale_num[i][j];
		cout << "the sum is " << sum;
	}
	cout << "the sum is " << sum;

	return 0;
}

7.

#include<iostream>
#include<string>
using namespace std;
struct car
{
	string manufacturer;
	int dates;
};

int main(void)
{
	int  car_number;
	car* pcar;//car类型的指针

	cout << "How many cars do you wish to catalog? ";
	cin >> car_number;
	cin.get();//读取缓冲区中的空格
	pcar = new car[car_number];//使用NEW来创建一个由相应数量的car结构著称的动态数组
	for (int i = 0; i < car_number; i++)
	{
		cout << "Car #" << i + 1 << ":" << endl;
		cout << "Please enter the make :";
		getline(cin, pcar[i].manufacturer);//string的读取用getline
		cout << "Please enter the made: ";
		cin >> pcar[i].dates;//此时缓冲区中有数字且空格,空格不读入在缓冲区中
		cin.get();//将缓冲区中的空格读入
	}

	cout << "Here is your collection:" << endl;
	for (int i = 0; i < car_number; i++)
	{
		cout << pcar[i].dates << " " << endl;
		cout << pcar[i].manufacturer << endl;
	}
	delete [] pcar;
	return 0;
}

8.

#include<iostream>
#include<cstring>
using namespace std;
const char Done[] = done;
int main(void)
{
	int counter = 0;
	char words[20];
	cout << "enter words (to stop,type the words down)";
	do
	{
		cin >> words;
		cin.get();
		counter++;

	} while (strcmp(words, Done) != 0);




	return 0;

}

9.

#include<iostream>
#include<string>
const char Done[] = "done";
using namespace std;
int main(void)
{
	
	string words;
	int counter = 0;
	cout << "Enter words (to stop,type the word done):" << endl;
	do
	{
		cin >> words;
		cin.get();
		counter++;


	} while (words != Done);




	return 0;
}

10.

#include<iostream>
using namespace std;
int main(void)
{
	int max;
	cout << "Please input a number  as a starting  ";
	cin >> max;
	for (int i = 0; i < max; i++)
	{
		for (int j=0;j<max-i-1;j++)
			cout << ".";
		for (int x = 0; x <=i; x++)
			cout << "*";
		cout<<endl;
		


	}

	return 0;
}

  C++知识库 最新文章
【C++】友元、嵌套类、异常、RTTI、类型转换
通讯录的思路与实现(C语言)
C++PrimerPlus 第七章 函数-C++的编程模块(
Problem C: 算法9-9~9-12:平衡二叉树的基本
MSVC C++ UTF-8编程
C++进阶 多态原理
简单string类c++实现
我的年度总结
【C语言】以深厚地基筑伟岸高楼-基础篇(六
c语言常见错误合集
上一篇文章      下一篇文章      查看所有文章
加:2022-03-31 23:45:54  更:2022-03-31 23:46:50 
 
开发: C++知识库 Java知识库 JavaScript Python PHP知识库 人工智能 区块链 大数据 移动开发 嵌入式 开发工具 数据结构与算法 开发测试 游戏开发 网络协议 系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程
数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁

360图书馆 购物 三丰科技 阅读网 日历 万年历 2024年11日历 -2024/11/24 2:00:50-

图片自动播放器
↓图片自动播放器↓
TxT小说阅读器
↓语音阅读,小说下载,古典文学↓
一键清除垃圾
↓轻轻一点,清除系统垃圾↓
图片批量下载器
↓批量下载图片,美女图库↓
  网站联系: qq:121756557 email:121756557@qq.com  IT数码