当前位置: 首页 > news >正文

C++ Primer Plus 编程练习题 第三章 处理数据

1.身高转换

#include <iostream>
using namespace std;

int main() 
{
	const int yingchi = 12;
	const double yingcun = 0.0254;
	double height;
	cout << "请输入你的身高(米):____\b\b\b\b";
	cin >>height;
	cout << "您的升高为" << height / yingcun << "英寸";
	cout << "您的升高为" << height / yingcun / yingchi << "英尺";
	return 0;
}

2.BMI计算

#include <iostream>
using namespace std;

int main() 
{
	const int yingchi = 12;
	const double yingcun = 0.0254;
	const double bang = 2.2;

	double height_yingchi;
	double height_yingcun;
	cout << "请输入你的身高(英尺):____\b\b\b\b";
	cin >> height_yingchi;
	cout << "请输入你的身高(英寸):____\b\b\b\b";
	cin >> height_yingcun;
	double height_mi;
	height_mi = (height_yingchi * yingchi + height_yingcun) * yingcun;
	double weight_bang;
	cout << "请输入你的体重(磅):____\b\b\b\b";
	cin >> weight_bang;
	double weight_kg;
	weight_kg = weight_bang / bang;
	double BMI;
	BMI = weight_bang / (height_mi * height_mi);
	cout << "您的BMI为" << BMI;
	return 0;
}

3.纬度转换

#include <iostream>
using namespace std;

int main() 
{
	const int degree_minute = 60;
	const int minute_second = 60;
	int degree;
	float minutes;
	float seconds;
	cout << "请输入度";
	cin >> degree;
	cout << "请输入分";
	cin >> minutes;
	cout << "请输入秒";
	cin >> seconds;
	cout << degree << "度" << minutes << "分" << seconds << "秒 = " << degree + minutes / degree_minute + seconds / (degree_minute * minute_second) << "度";
	return 0;
}

4.表示时间

#include <iostream>
using namespace std;

int main() 
{
	long seconds;
	cout << "输入秒数";
	cin >> seconds;
	const int day_seconds = 24*60*60;
	const int hour_seconds = 60*60;
	const int minute_seconds = 60;
	cout << seconds / day_seconds<<"days,"<< seconds % day_seconds/hour_seconds<<"hours,"<< seconds % hour_seconds /minute_seconds<<"minutes,"<< seconds % hour_seconds % minute_seconds;
	return 0;
}

5.人口计算

强制转换

#include <iostream>
using namespace std;

int main() 
{
	long long people_world;
	cout << "请输入全球人口";
	cin >> people_world;
	cout << "请输入全国人口";
	long long people_nation;
	cin >> people_nation;
	cout << "全国人口占全球人口百分比为" << (double(people_nation) / double(people_world))*100<<"%";
	return 0;
}

6.油耗计算

#include <iostream>
using namespace std;

int main() 
{
	double mile;
	cout << "请输入您的里程(英里)";
	cin >> mile;
	double gas;
	cout << "请输入您的耗油量(加仑)";
	cin >> gas;
	cout << "您耗油量为一加仑的里程为" << mile / gas<<"英里";
	return 0;
}

7.欧美耗油量转换

#include <iostream>
using namespace std;

int main() 
{
	const float mile_convert = 62.14;
	const float gas_convert = 3.875;
	float gas_mile;
	cout << "请输入欧洲风格的耗油量(升/百公里)";
	cin >> gas_mile;
	cout << "美国风格的耗油量为" << mile_convert/(gas_mile / gas_convert)<< "(gpm)";
	return 0;
}

相关文章:

  • 某得物 - WebView App H5调试
  • dataframe能否把列表里所有的NaN换成列表上一位的数字?
  • 蓝桥杯备考:动态规划路径类dp之迷雾森林
  • ubuntu 20.04下ZEDmini安装使用
  • 【 <一> 炼丹初探:JavaWeb 的起源与基础】之 JSP 中的内置对象:request、response、session 的使用示例
  • C++11新特性:auto遇上const时的推导规则
  • blender看不到导入的模型
  • YOLOv12本地部署教程——42%速度提升,让高效目标检测触手可及
  • 要查看 SQLite 数据库中的所有表,可以通过查询 SQLite 的系统表 sqlite_master
  • 从0到1搭建315答题抽奖小程序:技术踩坑与运营真相
  • 【Vue CLI脚手架开发】——6.scoped样式
  • javascript字符串截取有哪些
  • RabbitMQ知识点
  • 二叉树-验证二叉搜索树
  • 计算机网络开发(2)TCP\UDP区别、TCP通信框架、服务端客户端通信实例
  • RV1126采集VI视频数据流
  • 【QWEN】机器人控制器的控制周期越短精度越高吗
  • Kotlin D1
  • 模块15.常用API
  • Java接口(3)与图书管理系统
  • 校园网站集群建设/网络营销软文
  • 郑州网站建设知乎/行业关键词搜索量排名
  • 网站整体营销方案/百度人工客服在线咨询电话
  • 乐清高端网站建设/厉害的seo顾问
  • 网站建设费 无形资产/软文推广页面
  • 广州网站建设/淘宝宝贝关键词排名查询工具