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-11-26RocketMQ入门指南:搭建与使用全流程详解
- 2024-11-26RocketMQ入门教程:轻松搭建与使用指南
- 2024-11-26手写RocketMQ:从入门到实践的简单教程
- 2024-11-25【机器学习(二)】分类和回归任务-决策树(Decision Tree,DT)算法-Sentosa_DSML社区版
- 2024-11-23增量更新怎么做?-icode9专业技术文章分享
- 2024-11-23压缩包加密方案有哪些?-icode9专业技术文章分享
- 2024-11-23用shell怎么写一个开机时自动同步远程仓库的代码?-icode9专业技术文章分享
- 2024-11-23webman可以同步自己的仓库吗?-icode9专业技术文章分享
- 2024-11-23在 Webman 中怎么判断是否有某命令进程正在运行?-icode9专业技术文章分享
- 2024-11-23如何重置new Swiper?-icode9专业技术文章分享