c++primer 第三章编程练习答案
3.7.1
#include<iostream>
int main() {
using namespace std;
const int unit = ;
int height,inch,foot;
cout << "please input your height __ inch\b\b\b\b\b\b\b";
cin >> height;
inch = height % unit;
foot = height / unit;
cin.get();
cout << "your height is " << foot << " foot " << inch << " inch";
cin.get();
}
3.7.2
#include<iostream>
int main() {
using namespace std;
cout.setf(ios_base::fixed, ios_base::floatfield);
const double inch_to_meter = 0.0254;
const double kg_to_lb = 2.2;
int inch, foot, lb;
//float height, weight;
cout << "please input your height!\n";
cout << "foot:_\b";
cin >> foot;
cout << "inch:_\b";
cin >> inch;
cout << "please input your weight " << "___ lb\b\b\b\b\b\b";
cin >> lb;
cin.get();
cout << "your height is " << foot * + inch << " inch\n";
cout << "your height is " << (foot * + inch)*inch_to_meter << "m\n";
cout << "your weight is " << lb / 2.2 << "kg\n";
cout << "your BMI is " << pow((lb / 2.2) / ((foot * + inch)*inch_to_meter), );
//cout << pow(2, 3);
cin.get();
}
3.7.3
#include<iostream>
int main() {
using namespace std;
const int degree_to_minute = ;
const int minute_to_second = ;
int degree, minute, second;
double latitude;
cout << "Enter a latitude in degree,minutes,and seconds:\n";
cout << "First,enter the degrees: ";
cin >> degree;
cout << "Next,enter the minutes of arc: ";
cin >> minute;
cout << "Finally,enter the seconds of arc: ";
cin >> second;
cin.get();
latitude = degree + double(minute) / degree_to_minute + double(second) / degree_to_minute / minute_to_second;
cout << degree << " degrees," << minute << " minutes," << second << " seconds = " << latitude << " degrees";
cin.get();
}
3.7.4
#include<iostream>
int main() {
using namespace std;
const int days_to_hours = ;
const int hours_to_minutes = ;
const int mintutes_to_seconds = ;
int days, hours, minutes, seconds,init_times;
cout << "Enter the number of seconds: ";
cin >> init_times;
cin.get();
days = init_times / mintutes_to_seconds / hours_to_minutes / days_to_hours;
hours = init_times / mintutes_to_seconds / hours_to_minutes % days_to_hours;
minutes = init_times / mintutes_to_seconds % hours_to_minutes;
seconds = init_times % mintutes_to_seconds;
cout << init_times << " seconds = " << days << " days," << hours << " hours," << minutes << " minutes," << seconds << " seconds.";
cin.get();
}
3.7.5
#include<iostream>
int main() {
using namespace std;
long long world_num;
long long us_num;
cout << "Enter the world's population: ";
cin >> world_num;
cout << "Enter the population of the US: ";
cin >> us_num;
cin.get();
cout << "The population of the US is " << double(us_num) / double(world_num)* << "% of the world population";
cin.get();
}
c++primer 第三章编程练习答案的更多相关文章
- c++primer 第五章编程练习答案
5.9.1 #include<iostream> int main() { using namespace std; ; cout << "input first i ...
- c++primer 第四章编程练习答案
4.13.1 #include<iostream> struct students { ]; ]; char grade; int age; }; int main() { using n ...
- C语言程序设计:现代方法(第2版)第三章全部习题答案
前言 本人在通过<C语言程序设计:现代方法(第2版)>自学C语言时,发现国内并没有该书完整的课后习题答案,所以就想把自己在学习过程中所做出的答案分享出来,以供大家参考.这些答案是本人自己解 ...
- CSAPP深入理解计算机系统(第二版)第三章家庭作业答案
<深入理解计算机系统(第二版)>CSAPP 第三章 家庭作业 这一章介绍了AT&T的汇编指令 比较重要 本人完成了<深入理解计算机系统(第二版)>(以下简称CSAPP) ...
- C++第三章课后作业答案及解析---指针的使用
今天继续完成上周没有完成的习题---C++第三章课后作业,本章题涉及指针的使用,有指向对象的指针做函数参数,对象的引用以及友元类的使用方法等 它们具体的使用方法在下面的题目中会有具体的解析(解析标注在 ...
- c++ primer plus 第三章 课后题答案
#include<iostream> using namespace std; int main() { ; int shen_gao; cout <<"Please ...
- c++primer 第l六章编程练习答案
6.11.1 #include<iostream> #include<cctype> int main() { using namespace std; char ch; ci ...
- c++primer 第二章编程练习答案
2.7.1 #include<iostream> int main() { using namespace std; ]; ]; cout << "input nam ...
- C++primer第三章标准库类型
除第二章介绍的基本数据类型外,C++ 还定义了一个内容丰富的抽象数据类型标准库. 本章将介绍标准库中的 vector.string 和 bitset 类型. string 类型支持长度可变的字符串 v ...
随机推荐
- StringBuffer、StringBuilder
相信大家都知道StringBuffer.StringBuilder,但是这两个的用法都差不多,到底有什么区别呢,这也是面试的时候问的比较多的一道题,这里我就来说说,这两个的区别结合String来说~ ...
- Can’t connect to local MySQL server through socket 解决办法
启动mysql 报错: ERROR 2002 (HY000): Can’t connect to local MySQL server through socket ‘/var/lib/mysql/m ...
- 小计---pandas读取带有中文文件名或者包含中文内容的文件
python2下: # -*- coding: utf-8 -*- import pandas as pd mydata = pd.read_csv(u"例子.csv") #前面加 ...
- C#中时间的Ticks属性
C#中时间的Ticks属性是一个很大的长整数,单位是 100 毫微秒.表示自 0001 年 1 月 1 日午夜 12:00:00 以来已经过的时间的以 100 毫微秒为间隔的间隔数,已经说得很清楚了, ...
- OpenGL学习进程(9)在3D空间的绘制实例
本节将演示在3D空间中绘制图形的几个简单实例: (1)在3D空间内绘制圆锥体: #include <GL/glut.h> #include <math.h> # ...
- java DateTimeUtil 日期工具类
package com.sicdt.library.core.utils; import java.sql.Timestamp; import java.text.DateFormat; import ...
- git操作整理
昨天手残 然后在GitHub for windows 上点了revert 然后就给重置了 更手残的是又给同步了 . 但是 GitHub 会保留之前的版本 . 只要删掉本次修改就可. 解决方案: g ...
- Android摄像头测量尺(Advanced Ruler Pro)使用方法
http://www.cnblogs.com/sinojelly/archive/2010/08/13/1799341.html Advanced Ruler Pro是一个Android手机应用程序, ...
- 跨平台移动开发 Android使用JPush推送消息
二话不说,直接上图,看效果 第一步在官网下载 Android Push SDK https://www.jpush.cn/sdk/android 第二步 创建注册帐号,应用 第三步 下载应用,导入l ...
- 递归实现N皇后问题
其实是看到一位名为“活在二次元的伪触”的博主昨天还是前天写了篇这个题材的笔记,觉得有点意思,于是想自己来写写. 其实我发现上述那位同学写N皇后问题写得还不错,文末也会给出这位同学用通过递归的方法实现N ...