第三章习题 C++ Primer 第六版
1.使用一个整数输入自己的身高(单位为cm),并将此身高转化为米和厘米共同表示的形式,使用下划线字符来指示输入的位置,使用一个const符号常量来表示转换因子。
#include<iostream>
using namespace std;
const int transform = ;
int main()
{
cout << "请输入自己的身高,单位为厘米:___\b\b\b" ;//使用下划线字符来指示输入的位置
int height;
cin >> height;
cin.get();
cout << "你的身高是: " << height << "公分" << endl;
int meter;
meter = height / transform;
int cm;
cm = height % transform;
cout << height << "公分是" << meter << "米加" << cm << "厘米" << endl;
cin.get();
return ;
}
运行结果:
请输入自己的身高,单位为厘米:190
你的身高是: 190公分
190公分是1米加90厘米
2.要求以几英尺几英寸的方式输入身高,并以磅为单位输入其体重,计算IBM指数。
#include<iostream>
using namespace std;
const double Inch2Meter = 0.254;
const double Kilo2Pound = 2.2;
const int Foot2Inch = ; int main()
{
double height_foot = 0.0;
double height_inch = 0.0;
double height_meter = 0.0;
double weight_pound = 0.0;
double weight_kilo = 0.0;
double BMI = 0.0; cout << "Enter your height in foot and inch" << endl;
cout << "First enter the foot: ";
cin >> height_foot;
cin.get();
cout << "Second enter the inch: ";
cin >> height_inch;
cin.get();
cout << "Enter you weight in pound: ";
cin >> weight_pound;
cin.get();
height_meter = (height_foot * Foot2Inch + height_inch) * Inch2Meter;
weight_kilo = weight_pound / Kilo2Pound; BMI = weight_kilo / (height_meter * height_meter); cout << "Your BIM is " << BMI << endl;
cin.get();
return ;
}
运行结果:
Enter your height in foot and inch
First enter the foot: 12
Second enter the inch: 45
Enter you weight in pound: 6
Your BIM is 0.00118342
3.要求用户以度,分,秒的方式输入一个纬度,然后最终以度为单位显示该纬度。
#include<iostream>
using namespace std;
int main()
{
double degress = 0.0;
double minutes = 0.0;
double seconds = 0.0; cout << "Enter a latitude in degrees,minutes,and seconds:" << endl;
cout << "First enter the the degress: ";
cin >> degress;
cin.get();
cout << "Second enter the minutes: ";
cin >> minutes;
cin.get();
cout << "Finally ,enter the seconds : ";
cin >> seconds;
cin.get(); double last = seconds / / + minutes / + degress; cout << degress << " degress, " << minutes << " minutes, " << seconds << " seconds = " << last << " degrees" << endl;
cin.get();
return ;
}
运行结果:
Enter a latitude in degrees,minutes,and seconds:
First enter the the degress: 37
Second enter the minutes: 51
Finally ,enter the seconds : 19
37 degress, 51 minutes, 19 seconds = 37.8553 degrees、
4. 要求用户以整数方式输入秒数,然后以天、小时、分钟和秒的方式显示这段时间。
#include<iostream>
using namespace std;
int main()
{
long total = 0.0;
cout << "请输入秒数,我给您以天、小时、分钟和秒的方式显示这段时间: " ;
cin >> total;
cin.get(); int days;
int hours = ;
int minutes = ;
int seconds = ; days = total / ( * * );
hours = ((total % ( * * )) / ( * ));
minutes = ((total % ( * )) / );
seconds = (total % ); cout << "该段时间为:" << days << " 天 " << hours << " 小时 " << minutes << " 分钟 " << seconds << " 秒 " << endl;
cin.get();
return ;
}
运行结果:
请输入秒数,我给您以天、小时、分钟和秒的方式显示这段时间: 4556652
该段时间为:52 天 17 小时 44 分钟 12 秒
第三章习题 C++ Primer 第六版的更多相关文章
- 统计学习导论:基于R应用——第三章习题
第三章习题 部分证明题未给出答案 1. 表3.4中,零假设是指三种形式的广告对TV的销量没什么影响.而电视广告和收音机广告的P值小说明,原假设是错的,也就是电视广告和收音机广告均对TV的销量有影响:报 ...
- PythonCrashCourse 第三章习题
PythonCrashCourse 第三章习题 3.1 将一些朋友的姓名存储在一个列表中,并将其命名为names.依次访问该列表中的每个元素,从而将每个朋友的姓名都打印出来 names = ['lih ...
- 周志华-机器学习西瓜书-第三章习题3.5 LDA
本文为周志华机器学习西瓜书第三章课后习题3.5答案,编程实现线性判别分析LDA,数据集为书本第89页的数据 首先介绍LDA算法流程: LDA的一个手工计算数学实例: 课后习题的代码: # coding ...
- UNIX环境高级编程-第三章习题
1,当读写磁盘文件时,read,write等函数确实是不带缓冲机制的吗?请说明原因. 答:所有磁盘I/O都要经过内核的块缓存区(即内核的缓冲区高速缓存).唯一例外的是对原始磁盘设备的I/O,但是我们不 ...
- C++面向对象程序设计第三章习题答案解析
整理一下自己写的作业,供考试前复习用,哈哈 进入正题!!! 题目: 2.分析下面的程序,写出其运行时的输出结果 这里就不展示课本源代码,直接给出修改后的代码,错误部分代码已给出具体的注释 #inclu ...
- C和指针 第三章 习题
在一个源文件中,有两个函数x和y,定义一个链接属性external储存类型static的变量a,且y可以访问,x不可以访问,该如何定义呢? #include <stdio.h> void ...
- python核心编程-第三章-习题
1.这是python的语言特性,python先创建对象,在给变量赋值时,不需要定义变量的名称和类型,它实际是用变量引用对象.变量类型在给变量赋值时自动声明 2.原因类似变量无须声明类型 3.pytho ...
- Reinforcement Learning by Sutton 第三章习题答案
好不容易写完了 想看全部的欢迎点击下面的github https://github.com/LyWangPX/Solutions-of-Reinforcement-Learning-An-Introd ...
- 《C++Primer》第五版习题答案--第三章【学习笔记】
[C++Primer]第五版[学习笔记]习题解答第三章 ps:答案是个人在学习过程中书写,可能存在错漏之处,仅作参考. 作者:cosefy Date: 2020/1/10 第三章:字符串,向量和数组 ...
随机推荐
- playbook+roles
playbook setup ansible_all_ipv4_addresses # ipv4的所有地址 ansible_all_ipv6_addresses # ipv6的所有地址 ansible ...
- jquery-validate插件
jQuery Validation 插件 优点:1.表单验证非常简单方便,并且提供了许多配置项目2.国际化,可以自定义提示信息 命令行安装 //初始化bowerbower init //使用bower ...
- 栅格那点儿事(一)---Raster是个啥子东西
Raster是个啥子东西 现如今,不仅是在遥感应用中能看到花花绿绿的影像了,在GIS应用中也能随处看到她们的身影.在各种在线地图中,卫星影像作为底图与矢量的道路层叠加:高程DEM作为高程来源实现地形的 ...
- Java Knowledge series 4
JVM & Bytecode Has-a or Is-a relationship(inheritance or composition) 如果想利用新类内部一个现有类的特性,而不想使用它的接 ...
- Android自定义控件练手——波浪效果
这一次要绘制出波浪效果,也是小白的我第一次还望轻喷.首先当然是展示效果图啦: 一.首先来说说实现思路. 想到波浪效果,当然我第一反应是用正余弦波来设计啦(也能通过贝塞尔曲线,这里我不提及这个方法但是在 ...
- instanceof和相关函数
instanceof:如果左边对象是右边类型所表示类(或任意一子类)的一个实例,则返回true,否则false.判断左边真实类型是不是右边的类或它的派生类. //实例一 Object o= new L ...
- 青石B2C商城
平台: Windows 类型: 虚拟机镜像 软件包: azure commercial ecbluestone ecommerce ecommerce solution 服务优惠价: 按服务商许可协议 ...
- php的yii框架开发总结8
EMailer是一个简单的封装PHPMailer类.利用这个扩展可以实现发邮件的功能. 下载地址:http://www.yiiframework.com/extension/mailer/ 下载解压把 ...
- 微信小程序又一爆炸功能上线-云开发
云开发介绍 开发者可以使用云开发开发微信小程序.小游戏,无需搭建服务器,即可使用云端能力. 云开发为开发者提供完整的云端支持,弱化后端和运维概念,无需搭建服务器,使用平台提供的 API 进行核心业务开 ...
- php中增删改查以及返回结果(一)
虽然毕业后找的第一份正式的工作并不那么令人满意,但是在度过最初的迷茫期后,自己还是决定成为一个程序猿. 最近也是利用上班偶尔闲下来的时间,开始看书,撸代码,写一些小程序. 这两个礼拜主要的写的都是有关 ...