《C++ primer plus》第六版课后编程题-第05章

ops/2025/1/24 21:27:15/

第五章

1

#include <iostream>
#include <array>using namespace std;void main() {int n1, n2;cin >> n1 >> n2;int sum = 0;for (int i = n1; i <= n2; i++) {sum += i;}cout << sum;
}

2

#include <iostream>
#include <array>using namespace std;const int ArSize = 16;void main() {array<long double,ArSize> factorials;factorials[1] = factorials[0] = 1;for (int i = 2; i < ArSize; i++)factorials[i] = i * factorials[i - 1];for (int i = 0; i < ArSize; i++)std::cout << i << "!=" << factorials[i] << std::endl;}

3

#include <iostream>
#include <array>using namespace std;void main() {int sum = 0;int n = 1;while (n != 0) {cin >> n;sum += n;cout << sum << endl;}}

4

#include <iostream>
#include <array>using namespace std;double Daphne_money(int years) {return 100+0.1 * 100 * years;
}double Cleo_money( int years) {if (years == 1)return 100;else {return Cleo_money(years - 1) * 1.05;}
}void main() {int years = 1;while (Daphne_money(years) > Cleo_money(years)) {years++;}cout << years;
}

5

#include <iostream>
#include <vector>
#include <string>using namespace std;void main() {vector<string> sells = { "January", "February", "March", "April", "May", "June","July", "August", "September", "October", "November","December" };vector<int> number(12);int total = 0;for (int i = 0; i < 12; i++) {cout << "Total sells in " << sells[i] << " is:" << endl;cin >> number[i];total += number[i];}cout << "total sells is" << total << endl;
}

6

#include <iostream>
#include <vector>
#include <string>using namespace std;void main() {vector<vector<string>> sells(3,vector<string>(12));sells= { { "January", "February", "March", "April", "May", "June","July", "August", "September", "October", "November","December" },{ "January", "February", "March", "April", "May", "June","July", "August", "September", "October", "November","December" },{ "January", "February", "March", "April", "May", "June","July", "August", "September", "October", "November","December" } };vector<vector<int>> number(3,vector<int>(12));int total_per_year[3] = { 0,0,0 };int total = 0;for (int j = 0; j < 3; j++) {for (int i = 0; i < 12; i++) {cout << "Total sells in " << sells[j][i] <<" No."<<j+1<< "year is:" << endl;cin >> number[j][i];total_per_year[j] += number[j][i];total += number[j][i];}cout << "total sells in No." << j+1 << " year is" << total_per_year[j] << endl;}cout << "total sells of all years is" << total << endl;
}

http://www.ppmy.cn/ops/152851.html

相关文章

i春秋冬季赛2025个人学习总结

鏖战三天&#xff0c;也就100出头&#xff0c;还是太菜了&#xff0c;简单记录一下比赛中学到的知识 misc ezmisc 1、提示&#xff1a;利⽤DP泄露来求出私钥&#xff0c;从⽽还原私钥流解密密⽂ 2、图片经过了Arnold变换 给了一个流量包&#xff0c;可以从中导出一个加密的压…

NPM 下载依赖超时:npm ERR! RequestError: connect ETIMEDOUT

问题描述与处理策略 1、问题描述 npm install electron --save-dev执行上述 NPM 指令安装 Electron&#xff0c;报如下错误 npm ERR! RequestError: connect ETIMEDOUT 20.205.243.166:443# 翻译 npm 错误 请求异常&#xff1a;连接 20.205.243.166:443 超时2、处理策略 &a…

Alluxio 联手 Solidigm 推出针对 AI 工作负载的高级缓存解决方案

作者&#xff1a;Wayne Gao, Yi Wang, Jie Chen, Sarika Mehta Alluxio 作为全球领先的 AI 缓存解决方案供应商&#xff0c; 提供针对 GPU 驱动 AI 负载的高速缓存。其可扩展架构支持数万个节点&#xff0c;能显著降低存储带宽的消耗。Alluxio 在解决 AI 存储挑战方面的前沿技…

Redis高阶3-缓存双写一致性

Redis缓存双写一致性 Redis双写一致性的理解 如果Redis中有数据 需要和数据库中的值相同 如果redis中无数据 数据库中的值要是最新值&#xff0c;且准备回写redis 按照操作分为两种 只读缓存 读写缓存 同步直写策略 ​ 写数据库后也同步写redis缓存&#xff0c;缓存和数据库…

Spring Boot 3.4 正式发布,结构化日志!

1 从 Spring Boot 3.3 升级到 3.4 1.1 RestClient 和 RestTemplate 新增对 RestClient 和 RestTemplate 自动配置的支持&#xff0c;可用 Reactor Netty 的 HttpClient 或 JDK 的 HttpClient。支持的客户端优先级&#xff1a; Apache HTTP Components (HttpComponentsClient…

Elasticsearch 和arkime 安装

安装一定要注意版本号&#xff0c;不然使用不了 这里Ubuntu使用ubuntu-20.04.6-desktop-amd64.iso elasticsearch这里使用Elasticsearch 7.17.5 | Elastic arkime这里使用wget https://s3.amazonaws.com/files.molo.ch/builds/ubuntu-20.04/arkime_3.4.2-1_amd64.deb 大家想…

解决 IntelliJ IDEA 项目包后出现“% classes”和“% lines covered”的问题

前言 在使用 IntelliJ IDEA 开发 Java 或其他支持的语言时&#xff0c;您可能会遇到项目包后面意外地出现了“% classes”和“% lines covered”的信息。这些百分比表示的是代码覆盖率&#xff08;Coverage&#xff09;&#xff0c;它们展示了您的测试覆盖了多少比例的类和代码…

从根源分析,调试,定位和解决MacOS ld: unsupported tapi file type ‘!tapi-tbd‘ in YAML file

你要是遇到同样错误&#xff0c;找一圈都没有解决&#xff0c;建议认真读一下本文&#xff0c;这个应该是最终极的解决办法&#xff0c;从原理上剖析了产生的原因&#xff0c;同时给出来了调试和定位的办法。 maccos使用brew安装了一个gcc14, 结果编译一个最简单的程序都报错&a…