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 ...
随机推荐
- 怎样在不对控件类型进行硬编码的情况下在 C#vs 中动态添加控件
文章ID: 815780 最近更新: 2004-1-12 这篇文章中的信息适用于: Microsoft Visual C# .NET 2003 标准版 Microsoft Visual C# .NET ...
- Python学习进程(5)Python语法
本节介绍Python的基本语法格式:缩进.条件和循环. (1)缩进: Python最具特色的是用缩进来标明成块的代码. >>> temp=4;x=4; >> ...
- Linux用户和用户组管理 用户配置和管理的相关文件
用户信息文件 /etc/passwd 这个文件中保存的就是系统中所有的用户及其对应的用户主要信息. 文件格式 : 第1字段 第2字段 第3字段 第4字段 第5字段 第6字段 第7字段 用户名称 密码 ...
- RocketMq入坑指南
报错信息Caused by: org.apache.rocketmq.remoting.exception.RemotingConnectException: connect to <172.1 ...
- Python编程-异常处理
一.错误和异常 1.程序中难免出现错误,而错误分成两种 (1)语法错误(这种错误,根本过不了python解释器的语法检测,必须在程序执行前就改正) #语法错误示范一 if #语法错误示范二 def t ...
- list— 把数组中的值赋给一组变量
(PHP 4, PHP 5, PHP 7) list — 把数组中的值赋给一组变量 array list ( mixed $var1 [, mixed $... ] ) 像 array() 一样,这不 ...
- php数组函数-array_pop()
array_pop()函数删除数组中的最后一个元素(出栈). array_pop(array) array:必需.规定数组 返回值:返回数组的最后一个值.如果数组是空,或者不是一个数组,将返回NULL ...
- 一、安装虚拟机,配置ip地址
一.安装linux 注意点: 一.选择最小化安装的时候,要自定义安装软件,必须要安装下面的 如果没有安装上面的,需要用下面的命令来查询安装 如果没有安装就会出现各种问题 二.分区简单介绍 1.至少要一 ...
- axios拦截器/http
Interceptors //处理请求或响应之前拦截请求或响应. //添加一个请求拦截器 axios.interceptors.request.use(function (config) { //在请 ...
- Go Log模块生成日志文件
使用log模块示例代码: package main import ( "fmt" "time" "log" "os" ) ...