C++ Primer章课后编程问题
#include<iostream>
int main()
{using namespace std;int num1;int num2;int total=0;cout << "请输入開始数字\n";cin >> num1;cout << "请输入结束数字\n";cin >> num2;for (num1; num1<=num2; num1++)total = num1 + total;cout << num1 << " 和 " << num2 << "之间的整数和为 " << total <<endl;return 0;
}
#include<iostream>
int main()
{using namespace std;double total = 0.0;double in;cout << "请输入数字:";cin >> in;while (in != 0){total += in;cout << "全部输入数的和为:" << total << "\n";cout << "请输入下一个数字:";cin >> in;}cout << "执行结束";return 0;
}
#include<iostream>
int main()
{using namespace std;double daphne=100;double cleo=100;int year=1;while (daphne >= cleo){daphne += 100*0.1;cleo += cleo*0.05;cout << "第" << year << "年,daphne投资价值为 " << daphne << "cleo投资价值为 " << cleo <<endl;year++;}cout << "第 " << year << "年,时cleo超过daphne的投资价值"<< endl;return 0;
}
#include<iostream>
const char *months[12] = {"一月","二月","三月","四月","五月","六月","七月","八月","九月","十月","十一月","十二月"};
int main()
{using namespace std;int sales[12];int total;for (int i=1; i<=12; i++){cout << "请输入" << months[i-1] << "销售数量:";cin >> sales[i-1];}for (int j=0; j<12; j++){total = total+sales[j];}cout << "总销售为:" << total <<endl;return 0;
}
#include<iostream>
const char *months[12] = {"一月","二月","三月","四月","五月","六月","七月","八月","九月","十月","十一月","十二月"};
int main()
{using namespace std;int sales[3][12];int total[3] = {0}; //一定要初始化。不然初始值不为0int sum;for (int a=1;a<=3;a++){for (int i=1; i<=12; i++){cout << "请输入第"<< a << "年" << months[i-1] << "销售数量:";cin >> sales[a-1][i-1];}}for (int b=0; b<3; b++){for (int j=0; j<12; j++){total[b] = total[b]+sales[b][j];}sum = sum + total[b];cout << "第" << b+1 << "年总销量为" << total[b] <<endl;}cout << "总销售为:" << sum <<endl;return 0;
}
<pre name="code" class="cpp">//一定要加while (cin.get() != '\n');
#include<iostream>
using namespace std;
const int LEN = 60;
struct Car
{char brand[LEN];int year;
};
int main()
{int num;cout << "How many cars do you wish to catalog?";cin >> num;while (cin.get() != '\n');Car *ps = new Car[num];for (int i=0;i<num;i++){cout << "Car #" << (i+1) << ":\n";cout << "Please enter the make:";cin.getline(ps[i].brand, LEN);cout << "Please enter the year made:";cin >> ps[i].year;while(cin.get() != '\n');}cout << "Here is your collection:\n";for (int i=0; i<num; i++){cout << ps[i].year << " " << ps[i].brand <<endl;}delete [] ps;return 0;
}
#include<iostream>
#include<cstring>
const int STR_LEN=60;
int main()
{using namespace std;char words[STR_LEN];int count=0;cout << "Enter words(to stop,type the word done):\n";while (cin >> words && strcmp("done", words))++count;cout << "You entered a total of " << count << " words .\n" <<endl;return 0;
}
#include<iostream>
#include<string>
int main()
{using namespace std;string words;int count=0;cout << "Enter words {to stop,type the word done}:\n";while (cin >> words && words != "done")++count;cout << "You entered a total of " << count << " words .\n";return 0;
}
#include<iostream>
int main()
{using namespace std;int row;cout << "Enter number of row:";cin >> row;for (int i=0; i<row; i++){for (int j=row-i; j>1; j--){cout << ".";}for (int k=0; k<=i; k++){cout << "*";}cout << "\n";}return 0;
}
版权声明:本文博主原创文章。博客,未经同意不得转载。
转载于:https://www.cnblogs.com/gcczhongduan/p/4888896.html
C++ Primer章课后编程问题相关推荐
- C++ Primer Plus课后编程练习第6章参考代码
(C++ Primer Plus课后编程练习第6章参考代码) 声明: 作者入门小白,将学习过程中的代码做一些分享,仅供大家参考,欢迎大家交流指正.全部编译运行过,水平有限,不喜勿喷. 环境: Wind ...
- 【C Primer Plus第二章课后编程题】
[C Primer Plus第二章课后编程题] 2.1 2.2 2.3 2.4 2.5 2.6 2.7 2.8 2.1 #include <stdio.h> int main (void) ...
- C++ Primer Plus第四章课后编程
C++ Primer Plus第四章课后编程 4.12 复习题* 4.13 编程练习* 三句话,希望读者可以先看* 4.12 复习题* #include<iostream> #includ ...
- C primer plus 第四章课后编程练习答案笔记解释整理
第四章的编程练习: 1.编写一个程序,提示用户输入名和姓,然后以"名,姓"的格式打印. 编程分析: 程序功能是读取用户输入的字符串,并且重新格式化输出.应该针对名和姓分别定义对应的 ...
- C++ Primer Plus(第六版) 第4章 课后编程题
1.输出下列的信息:名字包含多个字母:程序中将下调整成绩,向上调整一个字母 What is your first name? Betty Sue What is your last name? Yew ...
- C++ Primer Plus第二章课后编程答案
1. #include<iostream>using namespace std;int main() {cout << "我的名字是:帅哥" <&l ...
- 尚学堂Java学习第四章课后编程题作业参考答案
我只是一个学习java 的初学者哈哈哈,代码写的都很烂,望大佬们指点指点. #尚学堂第三章:java面向对象基础 ##课后作业编程题一: 题目:1. 编写 Java 程序用于显示人的姓名和年龄.定义 ...
- Web前端开发精品课HTML CSS JavaScript基础教程第十四章课后编程题答案
编程题: 下面有一段代码,请在这段代码的基础上使用正确的选择器以及这两章学到的字体样式.文本样式来实现图14-13所示的效果. <!DOCTYPE html> <html> & ...
- Web前端开发精品课HTML CSS JavaScript基础教程第六章课后编程题答案
编程题: 利用这样一章学到的知识,制作如图6-10所示的表格效果,并且要求代码语义化. 用VS2013新建ASP.NET空网站,添加新项,建立HTML文件,向其加入以下代码: <!DOCTYPE ...
最新文章
- 0x80070659系统策略禁止这个安装 vc_教你一招,解决所有系统丢失DLL文件的问题!...
- Gridview 隐藏列
- python nums函数获取结果记录集有多少行记录_PHP mysqli_num_rows():获取查询结果的行数...
- 地址html后面传参,JS中获取地址栏url后面的参数的三种方法
- postgresql 动态添加过滤条件_XsqlFilterResult----动态生成sql语句的类,过滤一些为空的查询条件...
- maven配置testng_TestNG Maven Surefire插件配置
- 应用程序的可视化图形引擎库控件Vectordraw Developer Framework
- 常见的HTTP状态码大全
- 工程系列 计算机中级职称,工程类中级职称有哪些
- STM32F7 I2S接口 WM8978 边播放 边录音
- win7 计算机定时关机脚本,电脑设置定时关机的方法 win7系统怎么设置定时关机...
- devops运维平台汇总
- 快速幂与快速矩阵幂(以大数下的斐波那契数列为例)
- RabbitMq 消息接收确认(可靠消费)
- 127.0.0.1 拒绝了我们的连接请求--访问本地IP时显示拒绝访问
- 各种奇葩3389连接不上的解决方法
- Java中英文字母的大小写转换ideaeclipse大小写快捷键
- 戴森全新V12 Detect Slim轻量无绳吸尘器中国首发
- RocketDock 重启之后又回到默认样式的问题
- Python 生产者消费者模型
热门文章
- 虚拟机安装黑群晖_【群晖系统】HEI群辉DSM 6.2.1 系统安装图文教程 (19年2月)
- 人工智能在fpga的具体应用_人工智能带动了FPGA的发展
- h5 网站滚动到某个位置
- java用scanner 和random的一个小案例
- C++(STL):31 ---关联式容器map源码剖析
- linux常用解压和压缩文件的命令
- mysql hp ux_hp ux apa 切换
- 密码学在区块链隐私保护中的应用学习
- 以太坊智能合约 编译脚本
- Android Gradle 多渠道打包、动态配置AppName