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 ...
随机推荐
- hive批量执行sql命令及使用小技巧
root@hadoop-senior hive-0.13.1]$ bin/hive -helpusage: hive -d, --define <key=value> Variable s ...
- m进制转n进制
http://www.cnblogs.com/pkuoliver/archive/2010/10/27/Convert-m-number-to-n-number.html 从这道题中可以看出,数论中存 ...
- BAPI_ACC_DOCUMENT_POST 解决原因代码输入问题-利用BADI
(1) 复制函数SAMPLE_INTERFACE_RWBAPI01为Z SAMPLE_INTERFACE_RWBAPI01 *"---------------------------- ...
- Kafka简介、安装
一.Kafka简介 Kafka是一个分布式.可分区的.可复制的消息系统.几个基本的消息系统术语:1.消费者(Consumer):从消息队列(Kafka)中请求消息的客户端应用程序.2.生产者(Prod ...
- MC20模块教程目录
MC20模块使用教程 为了阅读和修正方便,所有教程在线观看,请在有网络的环境下观看下面教程,谢谢! MC20模块教程在线目录 第一章:基础使用,使用电脑调试MC20的各项功能 1.1 使用电脑测试MC ...
- 面试题2:实现Singleton模式(Java实现)
SIngleton(单例)设计模式 它是最简单的常用的设计模式之一,设计模式在面向对象程序设计中起着举足轻重的作用,Singleton是唯一一个能够用短短几十行代码完整实现的模式. public cl ...
- formatblock 块及
有标签,执行标签替换,只是替换标签,属性不改变. 在无标签外部添加标签
- UI组件之UIImage
UIImageView:图像视图,用于在应用程序中显示图片 UIImage:是将图片文件转换为程序中的图片对象 UIImageView是UIImage的载体 方法一:用此方法创建图片对象,会将图片ca ...
- rsh命令配置于使用
安装环境:一台centos6.10虚拟机,一台centos7.5虚拟机,全部使用root用户登录. 两台机器上都要安装rsh.rsh-server.xinetd包. 两台机器都要关闭防火墙并配置/et ...
- Django-Ajax基础知识
Ajax准备知识:json 1.什么是json JSON(JavaScript Object Notation, JS 对象标记) 是一种轻量级的数据交换格式. 它基于 ECMAScript (w3c ...