C++ Prime Plus 编程练习 第三章
2022/3/20 20:34:29
本文主要是介绍C++ Prime Plus 编程练习 第三章,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
1. 整数输入身高英寸,转为英尺英寸
#include <iostream> int main() { using namespace std; int inch; const int inch2foot = 12; cout << "Enter your height of inch:_\b"; cin >> inch; cout << "your inch: " << inch % inch2foot << endl; cout << "your foot: " << inch / inch2foot << endl; return 0; }
2. 计算BMI
#include <iostream> int main() { using namespace std; int inch; int foot; int bang; const int inch2foot = 12; const double inch2m = 0.0254; const double bang2k = 2.2; cout << "Enter your height of inch:_\b"; cin >> inch; cout << "Enter your height of foot:_\b"; cin >> foot; cout << "Enter your height of bang:_\b"; cin >> bang; double result = (bang / bang2k) / (foot * inch2foot / inch2m); cout << "your result: " << result << endl; return 0; }
3. 计算纬度
#include <iostream> int main() { using namespace std; int degrees{}; int minutes{}; int seconds{}; const int cov = 60; cout << "Enter a latitude in degrees, minutes, and seconds:" << endl; cout << "First, enter the degrees: "; cin >> degrees; cout << "Next, enter the minutes of arc: "; cin >> minutes; cout << "Finally, enter the seconds of arc: "; cin >> seconds; double all_degrees = degrees + double(minutes) / cov + double(seconds) / cov / cov; cout << degrees << " degrees, " << minutes << " minutes, " << seconds << " seconds = " << all_degrees << " degreses"; return 0; }
4. 将秒转为天数,小时,分钟,秒
#include <iostream> int main() { using namespace std; int days{}; int hours{}; int minutes{}; int seconds{}; const int time_cov = 60; const int hours2day = 24; long long all_minutes{}; cout << "enter the number of seconds: "; cin >> all_minutes; days = all_minutes / (hours2day * time_cov * time_cov); long dayofminutes_r = all_minutes - days * hours2day * time_cov * time_cov; hours = dayofminutes_r / (time_cov * time_cov); long hourofminutes_r = dayofminutes_r - hours * time_cov * time_cov; minutes = hourofminutes_r / time_cov; seconds = hourofminutes_r - minutes * time_cov; cout << all_minutes << " seconds = " << days << " days, " << hours << " hours, " << minutes << " minutes, " << seconds << " seconds"; return 0; }
5. 人口占比
#include <iostream> int main() { using namespace std; long long world_pop{}; long long us_pop{}; cout << "Enter the world's population: "; cin >> world_pop; cout << "Enter the population of the US: "; cin >> us_pop; double ratio = double(us_pop) / world_pop; cout << "The population of the US is " << ratio * 100 << "% of the world population."; return 0; }
6. 一加仑的里程
#include <iostream> int main() { using namespace std; double mile{}; double gallon{}; cout << "Enter the mile: "; cin >> mile; cout << "Enter the gallon: "; cin >> gallon; cout << "The car cost: " << mile / gallon << " mpg."; return 0; }
7. 欧洲风格的耗油量和美国风格的转换
#include <iostream> int main() { using namespace std; double mile{}; double gallon{}; const double km2mile = 62.14; const double gallon2 = 3.875; double sheng{}; cout << "Enter the p100km: "; cin >> sheng; mile = km2mile; gallon = sheng / gallon2; cout << "The car cost: " << mile / gallon << " mpg."; return 0; }
这篇关于C++ Prime Plus 编程练习 第三章的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-05-09flutter3.x_macos桌面os实战
- 2024-05-09Rust中的并发性:Sync 和 Send Traits
- 2024-05-08使用Ollama和OpenWebUI在CPU上玩转Meta Llama3-8B
- 2024-05-08完工标准(DoD)与验收条件(AC)究竟有什么不同?
- 2024-05-084万 star 的 NocoDB 在 sealos 上一键起,轻松把数据库编程智能表格
- 2024-05-08Mac 版Stable Diffusion WebUI的安装
- 2024-05-08解锁CodeGeeX智能问答中3项独有的隐藏技能
- 2024-05-08RAG算法优化+新增代码仓库支持,CodeGeeX的@repo功能效果提升
- 2024-05-08代码报错不用愁,CodeGeeX一键完成代码修复、错误解释的功能上线了!
- 2024-05-08今天开始程序员不用再发愁写commit message了,全部由CodeGeeX自动完成!