第三章习题 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 第三章:字符串,向量和数组 ...
随机推荐
- IDEA检出SVN项目
https://blog.csdn.net/qq_27093465/article/details/74898489 https://jingyan.baidu.com/article/47a29f2 ...
- bai_du 采集代码(已过期)
<?php $url = "http://www.baidu.com/s?wd=site:www.xxxxxx.com+inurl:hot&tn=baidulaonian&am ...
- Design Pattern ->Abstract Factory
Layering & Contract Philosophy With additional indirection Abstract Factory //The example code i ...
- ArcGIS API for JavaScript开发初探——基本地图组件使用
1.前言 在上一篇我们已经我们已经讲述了第一个地图应用程序的HelloMap的创建过程,这一篇我们来讲述基本地图组件:Home Button.比例尺.鹰眼图的使用方法. 2.基本地图组件 在ArcGI ...
- hibernate 初印象
将要学习的内容: 1.HelloWorld a) xml b) annotation2.Hibernate 原理模拟 - 什么是 O/R Mapping 以及为什么要有 O/RMapping3.常见 ...
- Azure资源模板化部署,伦家不懒都不好意思了
如果老板让你在云平台上部署一套系统,你准备怎么做? 嗯,估计得根据具体需求开通或创建一大堆东西:虚拟机.存储.数据库.虚拟网络……别急还没完,接着还要对这些东西的规模.配置等各方面调整和优化.一系列环 ...
- c++基础(积少成多)
1.#include<string> #include<iostream> 这是引用头文件: 2.Using namespace std; 这是引用命名空间,防止同一个命名空间 ...
- Jmeter入门4 添加断言 判断响应数据是否符合预期
发出请求之后,通过添加断言可以判断响应数据是否是我们的预期结果. 1 在Jmeter中发送一个登录的http请求(参数故意输入错误).结果肯定是登陆失败啦. 但结果树中http请求的图标显示‘绿色’表 ...
- 问题 B: C++习题 对象数组输入与输出
题目描述 建立一个对象数组,内放n(n<10)个学生的数据(学号.成绩),用指针指向数组首元素,输出第奇数(1,3,5,7)个学生的数据. 输入 n和n个学生的学号.成绩 输出 奇数学生的数据 ...
- MySQL游标(cursor) 定义及使用
概念 游标(Cursor)它使用户可逐行访问由SQL Server返回的结果集. 使用游标(cursor)的一个主要的原因就是把集合操作转换成单个记录处理方式. 用SQL语言从数据库中检索数据后,结果 ...