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 第六版的更多相关文章

  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. Docker 清理命令汇总

    杀死所有正在运行的容器 docker kill $(docker ps -a -q) 删除所有已经停止的容器 docker rm $(docker ps -a -q) 删除所有未打 dangling ...

  2. 4.JavaScript

    1.简介 JavaScript 是一种轻量级的编程语言,是一种动态类型.弱类型.基于原型的脚本语言. JavaScript,通常缩写为JS,是一种高级的,解释执行的编程语言.JavaScript是一门 ...

  3. (生产)jsonp - 跨域请求

    参考:https://github.com/webmodules/jsonp 参数: url (String) url to fetch opts (Object), optional param ( ...

  4. Eclipse Infrastructure

    Everything is plug-ins running on or loaded by plug-ins loader called by a small kernal which is an ...

  5. NoSQL(Not Only SQL)

    Everything has its properties and has relation with each other. All in world can be related to each ...

  6. Android 通过接口的方式去调用服务里面的方法

    public class MainActivity extends AppCompatActivity { private MyConn conn; private Iservice myBinder ...

  7. 如何使用Nunit进行测试

    如何使用Nunit进行测试(Visual Studio 2017 comminity) 原文:如何使用Nunit进行测试(Visual Studio 2017 comminity) 一.环境 操作系统 ...

  8. GitHub教程(三) 本地仓库托管到GitHub

    本文开头先特别声明一下:由于GitHub教程属于Git系列教程的GitHub子篇章,因此GitHub教程中将不再详细介绍Git操作命令及其用法,我会根据实际需要穿插着回顾Git操作命令.如果读者需要学 ...

  9. mybatis返回boolean值时数据库返回null

    Servlet.service() for servlet [springDispatcherServlet] in context with path [/ms] threw exception [ ...

  10. 搭建Web开发环境JavaEE_Eclipse

    1. 下载和安装1.1 下载JDK在Java官方网站下载最新版本的 Java SE:  http://www.oracle.com/technetwork/java/javase/downloads/ ...