1.使用一个整数输入自己的身高(单位为cm),并将此身高转化为米和厘米共同表示的形式,使用下划线字符来指示输入的位置,使用一个const符号常量来表示转换因子。

  1. #include<iostream>
  2. using namespace std;
  3. const int transform = ;
  4. int main()
  5. {
  6. cout << "请输入自己的身高,单位为厘米:___\b\b\b" ;//使用下划线字符来指示输入的位置
  7. int height;
  8. cin >> height;
  9. cin.get();
  10. cout << "你的身高是: " << height << "公分" << endl;
  11. int meter;
  12. meter = height / transform;
  13. int cm;
  14. cm = height % transform;
  15. cout << height << "公分是" << meter << "米加" << cm << "厘米" << endl;
  16. cin.get();
  17. return ;
  18. }

运行结果:  

  请输入自己的身高,单位为厘米:190
  你的身高是: 190公分
  190公分是1米加90厘米

2.要求以几英尺几英寸的方式输入身高,并以磅为单位输入其体重,计算IBM指数。

  1. #include<iostream>
  2. using namespace std;
  3. const double Inch2Meter = 0.254;
  4. const double Kilo2Pound = 2.2;
  5. const int Foot2Inch = ;
  6.  
  7. int main()
  8. {
  9. double height_foot = 0.0;
  10. double height_inch = 0.0;
  11. double height_meter = 0.0;
  12. double weight_pound = 0.0;
  13. double weight_kilo = 0.0;
  14. double BMI = 0.0;
  15.  
  16. cout << "Enter your height in foot and inch" << endl;
  17. cout << "First enter the foot: ";
  18. cin >> height_foot;
  19. cin.get();
  20. cout << "Second enter the inch: ";
  21. cin >> height_inch;
  22. cin.get();
  23. cout << "Enter you weight in pound: ";
  24. cin >> weight_pound;
  25. cin.get();
  26. height_meter = (height_foot * Foot2Inch + height_inch) * Inch2Meter;
  27. weight_kilo = weight_pound / Kilo2Pound;
  28.  
  29. BMI = weight_kilo / (height_meter * height_meter);
  30.  
  31. cout << "Your BIM is " << BMI << endl;
  32. cin.get();
  33. return ;
  34. }

运行结果:  

  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.要求用户以度,分,秒的方式输入一个纬度,然后最终以度为单位显示该纬度。

  1. #include<iostream>
  2. using namespace std;
  3. int main()
  4. {
  5. double degress = 0.0;
  6. double minutes = 0.0;
  7. double seconds = 0.0;
  8.  
  9. cout << "Enter a latitude in degrees,minutes,and seconds:" << endl;
  10. cout << "First enter the the degress: ";
  11. cin >> degress;
  12. cin.get();
  13. cout << "Second enter the minutes: ";
  14. cin >> minutes;
  15. cin.get();
  16. cout << "Finally ,enter the seconds : ";
  17. cin >> seconds;
  18. cin.get();
  19.  
  20. double last = seconds / / + minutes / + degress;
  21.  
  22. cout << degress << " degress, " << minutes << " minutes, " << seconds << " seconds = " << last << " degrees" << endl;
  23. cin.get();
  24. return ;
  25. }

运行结果:

  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. 要求用户以整数方式输入秒数,然后以天、小时、分钟和秒的方式显示这段时间。

  1. #include<iostream>
  2. using namespace std;
  3. int main()
  4. {
  5. long total = 0.0;
  6. cout << "请输入秒数,我给您以天、小时、分钟和秒的方式显示这段时间: " ;
  7. cin >> total;
  8. cin.get();
  9.  
  10. int days;
  11. int hours = ;
  12. int minutes = ;
  13. int seconds = ;
  14.  
  15. days = total / ( * * );
  16. hours = ((total % ( * * )) / ( * ));
  17. minutes = ((total % ( * )) / );
  18. seconds = (total % );
  19.  
  20. cout << "该段时间为:" << days << " 天 " << hours << " 小时 " << minutes << " 分钟 " << seconds << " 秒 " << endl;
  21. cin.get();
  22. return ;
  23. }

运行结果:  

  请输入秒数,我给您以天、小时、分钟和秒的方式显示这段时间: 4556652
  该段时间为:52 天 17 小时 44 分钟 12 秒

第三章习题 C++ Primer 第六版的更多相关文章

  1. 统计学习导论:基于R应用——第三章习题

    第三章习题 部分证明题未给出答案 1. 表3.4中,零假设是指三种形式的广告对TV的销量没什么影响.而电视广告和收音机广告的P值小说明,原假设是错的,也就是电视广告和收音机广告均对TV的销量有影响:报 ...

  2. PythonCrashCourse 第三章习题

    PythonCrashCourse 第三章习题 3.1 将一些朋友的姓名存储在一个列表中,并将其命名为names.依次访问该列表中的每个元素,从而将每个朋友的姓名都打印出来 names = ['lih ...

  3. 周志华-机器学习西瓜书-第三章习题3.5 LDA

    本文为周志华机器学习西瓜书第三章课后习题3.5答案,编程实现线性判别分析LDA,数据集为书本第89页的数据 首先介绍LDA算法流程: LDA的一个手工计算数学实例: 课后习题的代码: # coding ...

  4. UNIX环境高级编程-第三章习题

    1,当读写磁盘文件时,read,write等函数确实是不带缓冲机制的吗?请说明原因. 答:所有磁盘I/O都要经过内核的块缓存区(即内核的缓冲区高速缓存).唯一例外的是对原始磁盘设备的I/O,但是我们不 ...

  5. C++面向对象程序设计第三章习题答案解析

    整理一下自己写的作业,供考试前复习用,哈哈 进入正题!!! 题目: 2.分析下面的程序,写出其运行时的输出结果 这里就不展示课本源代码,直接给出修改后的代码,错误部分代码已给出具体的注释 #inclu ...

  6. C和指针 第三章 习题

    在一个源文件中,有两个函数x和y,定义一个链接属性external储存类型static的变量a,且y可以访问,x不可以访问,该如何定义呢? #include <stdio.h> void ...

  7. python核心编程-第三章-习题

    1.这是python的语言特性,python先创建对象,在给变量赋值时,不需要定义变量的名称和类型,它实际是用变量引用对象.变量类型在给变量赋值时自动声明 2.原因类似变量无须声明类型 3.pytho ...

  8. Reinforcement Learning by Sutton 第三章习题答案

    好不容易写完了 想看全部的欢迎点击下面的github https://github.com/LyWangPX/Solutions-of-Reinforcement-Learning-An-Introd ...

  9. 《C++Primer》第五版习题答案--第三章【学习笔记】

    [C++Primer]第五版[学习笔记]习题解答第三章 ps:答案是个人在学习过程中书写,可能存在错漏之处,仅作参考. 作者:cosefy Date: 2020/1/10 第三章:字符串,向量和数组 ...

随机推荐

  1. 轻松完成excel读写操作- 基于POI的框架BingExcel的使用(2)

    在进行 类转换时候,系统默认注册了一些转换器,当然你也可以自定局部或者全局的转换器.下面进行具体使用说明  java类说明 对应的java实体类,其属性必须要有__@CellConfig__注解,此注 ...

  2. Unity3D 调用Android与IOS的剪贴板

    Unity3D剪贴板 最近遇到一个需要调用Android与IOS设备本身剪贴板的需求,就是在Unity中,要将文本复制到设备本身的剪贴板中,然后在其他应用程序中都能粘贴. 最开始在网上查到的方式是使用 ...

  3. SharePoint 2010 列表查阅项栏的formfield控件对象取值

    开发的时候想当然的认为主表解析出来就是一个dropdownlist,可是在大数据测试的时候,发现有情况. 首先创建一个子列表:DetailList,并添加19条数据: 创建主列表:MainList,并 ...

  4. Lucene学习入门——下载初识

    本文从官网下载Lucene开始,一步一步进行Lucene的应用学习研究.下载初识Snowball Stemmer 1.下载 (1)首先,去Lucne的Apache官网主页 http://lucene. ...

  5. ztree的数据绑定

    ztree用法(1)首先引用ztree的css和js <link type="text/css" rel="stylesheet" href=" ...

  6. 建堆复杂度O(n)证明

    堆排序中首先需要做的就是建堆,广为人知的是建堆复杂度才O(n),它的证明过程涉及到高等数学中的级数或者概率论,不过证明整体来讲是比较易懂的. 堆排过程 代码如下 void print(vector&l ...

  7. IOS 自定义代理delegate方法

    创建一个自定义代理 @class MJTgFooterView; /** 1.协议名称: 控件类名 + Delegate 2.代理方法普遍都是@optional 3. */ @protocol MJT ...

  8. UVA 11983 Weird Advertisement

    题意:求矩形覆盖k次以上的区域总面积. 因为k≤10,可以在线段树上维护覆盖次数为0,...,k, ≥k的长度数量. 然后就是一个离散化以后扫描线的问题了. 离散化用的是半开半闭区间,以方便表示没有被 ...

  9. 2018.8.3 Java中容易犯错误的问题思考与总结

    Java容易犯错误的问题思考 float型 float f = 3.4 是否正确 不正确,应该用强制类型转换.如下所示:float f = (float)3.4 或float f = 3.4f 在ja ...

  10. 2017.10.6 Java命名规范及使用情况

    Package 的命名 Package 的名字应该都是由一个小写单词组成. Class 的命名 Class 的名字必须由大写字母开头而其他字母都小写的单词组成 Class 变量的命名 变量的名字必须用 ...