3-7 编程练习解答

3-7_1

 1 /* Author : grey_qisen */
 2 //3-7_1.cpp
 3
 4 #include<iostream>
 5 const int CHANGENUM = 12;
 6 int main(){
 7     using namespace std;
 8     int height;
 9     cout << "Please input your height(inch):   \b\b\b";
10     cin  >> height;
11     cout << "Your height is " << height / 12 << " feet and " << height % 12 << " inchs." << endl;
12
13     return 0;
14 }

3-7_2

 1 /* Author : grey_qisen */
 2 //3-7_2.cpp
 3
 4 #include<iostream>
 5 const int footIntoInch = 12;
 6 const double inchIntoMeter = 0.0254;
 7 const double poundIntoKilogram = 2.2;
 8
 9 int main(){
10     using namespace std;
11     int feet;    int inch;
12     double pound;    double BMI;
13
14     cout << "First,please input your height(feet):  \b\b";
15     cin  >> feet;
16     cout << "Second,please input your height(inch):   \b\b\b";
17     cin  >> inch;
18     inch = footIntoInch * feet + inch;
19     cout << "Your height is " << inch << endl;
20
21     cout << "Third,please input your weight(pound):    \b\b\b\b";
22     cin  >> pound;
23     inch = inch * inchIntoMeter;
24     pound = pound / poundIntoKilogram;
25
26     BMI = pound / (inch * inch);
27     cout << "Your body‘s BMI is " << BMI << endl;
28
29     return 0;
30 }

3-7_3

 1 /* Author : grey_qisen */
 2 //3-7_3.cpp
 3
 4 #include<iostream>
 5 const double minuteToDegree = 60.0;
 6 const double secondToMinute = 60.0;
 7
 8 int main(){
 9     using namespace std;
10     int degrees;    int minutes;    int seconds;
11     double latitude;
12
13     cout << "Enter a latitude in degrees,minutes,and seconds:" << endl;
14     cout << "First,enter the degrees:   \b\b\b";
15     cin  >> degrees;
16     cout << "Next,enter the minutes of arc:  \b\b";
17     cin  >> minutes;
18     cout << "Finally,enter the seconds of arc:  \b\b";
19     cin  >> seconds;
20     latitude = degrees + minutes / minuteToDegree + seconds /(minuteToDegree * secondToMinute);
21     cout << degrees << " degrees, " << minutes << " minutes, " << seconds << " seconds= "
22          << latitude << " degrees" << endl;
23
24     return 0;
25 }

3-7_4

 1 /* Author : grey_qisen */
 2 //3-7_4.cpp
 3
 4 #include<iostream>
 5 const int dayToHour = 24;
 6 const int hourToMinute = 60;
 7 const int minuteToSecond = 60;
 8
 9 int main(){
10     using namespace std;
11     long long second;
12     int days;    int hours;    int minutes;    int seconds;
13
14     cout << "Enter the number of seconds:          \b\b\b\b\b\b\b\b\b\b";
15     cin  >> second;
16     seconds = second % minuteToSecond;
17     minutes = (second / minuteToSecond) % hourToMinute;
18     hours = (second / (minuteToSecond * hourToMinute)) % dayToHour;
19     days = second / (minuteToSecond * hourToMinute * dayToHour);
20
21     cout << second << " seconds = " << days << " days, " << hours
22          << " hours, " << minutes << " minutes, " << seconds << " seconds" << endl;
23
24     return 0;
25 }

3-7_5

 1 /* Author : grey_qisen */
 2 // 3-7_5.cpp
 3
 4 #include<iostream>
 5
 6 int main(){
 7     using namespace std;
 8     long long worldPopulation;    long long USPopulation;
 9
10     cout << "Enter the world‘s population:    \b\b\b\b";
11     cin  >> worldPopulation;
12     cout << "Enter the population of US:    \b\b\b\b";
13     cin  >> USPopulation;
14     cout << "The popluation of the US is " << (100.0 * USPopulation / worldPopulation)
15          << "% of the world population." << endl;
16
17     return 0;
18 }

3-7_6

 1 /* Author : grey_qisen */
 2 // 3-7_6.cpp
 3 #include<iostream>
 4
 5 int main(){
 6     using namespace std;
 7     double mile;    double gallon;
 8     double kilometer;    double litre;
 9     int m;
10
11     cout << "Choose a method of input(1 is mile/gallon;2 is Km/L):";
12     cin  >> m;
13     if(m == 1){
14         cout << "You choose the first method of input." << endl
15              << "Now,please enter the mile: ";
16         cin  >> mile;
17         cout << "Please enter the gallon: ";
18         cin  >> gallon;
19         cout << mile / gallon << endl;
20     }else if(m == 2){
21         cout << "You choose the second method of input." << endl
22              << "Now,please enter the kilometer: ";
23         cin  >> kilometer;
24         cout << "Please enter the litre: ";
25         cin  >> litre;
26         cout << (100 * litre) / kilometer << endl;
27     }
28
29     return 0;
30 }

3-7_7

 1 /* Author : grey_qisen */
 2 // 3-7_7.cpp
 3 #include<iostream>
 4
 5 int main(){
 6     using namespace std;
 7     double Eur;    double USh;
 8     cout << "Please enter your Fuel consumption in Eur:";
 9     cin  >> Eur;
10     USh =  0.6214 * 3.875 * (100 / Eur);
11     cout << USh;
12
13     return 0;
14 }
时间: 2024-10-10 07:21:00

3-7 编程练习解答的相关文章

《C和指针》章节后编程练习解答参考——6.3

<C和指针>——6.3 题目: 编写一个函数,把参数字符串中的字符反向排列. 函数原型: void reverse_string(char *string); 要求: 使用指针而不是数组下标 不要使用任何C函数库中用于操纵字符串的函数 不要声明一个局部数组来临时存储参数字符串 解答代码: #include <stdio.h> void reverse_string(char *string) { int i, n=0; while (*(string+n) != '\0') //计

libevent编程疑难解答

转载请注明出处:http://blog.csdn.net/luotuo44/article/details/39547391 前段时间阅读了libevent的源码.读完后,之前在使用libevent时的一些疑问都已经豁然开朗了.对于libevent源码的分析,可以到http://blog.csdn.net/luotuo44/article/category/2435521查看. 本文通过自问自答的形式,希望能帮助其他人解答在使用libevent时的一些疑惑. 一个文件描述符可以关联多个event

《C和指针》章节后编程练习解答参考——第9章

9.1 1 #include <stdio.h> 2 #include <ctype.h> 3 #include <string.h> 4 5 #define N 100 6 7 int main (void) 8 { 9 int i = 0; 10 char strarray[N+1]; //= "Hello world! \t3I'm here!"; 11 char *input = strarray; 12 char ch; 13 unsign

4-13编程练习解答

4-13_1 1 /* Author : grey_qisen */ 2 // 4-13_1.cpp 3 #include<iostream> 4 const int Size = 20; 5 6 int main(){ 7 using namespace std; 8 char firstName[Size]; char lastName[Size]; 9 char deserveGrade; char trueGrade; 10 int age; 11 12 cout << &

《C和指针》章节后编程练习解答参考——第10章

10.1 1 #include <stdio.h> 2 3 typedef struct 4 { 5 unsigned char QuHao[5]; 6 unsigned char Exchange[10]; 7 unsigned char StnNum[10]; 8 }TelphoneNumber; 9 10 typedef struct 11 { 12 unsigned char date[10]; 13 unsigned char time[10]; 14 TelphoneNumber

Libevent使用例子,从简单到复杂

本文从简单到复杂,展示如何使用libevent.网上的许多例子都是只有服务器端的,本文里面客户端和服务器端都有,以飨读者. 关于libevent编程时的一些疑问可以阅读<libevent编程疑难解答>.假如读者还想了解libevent的具体实现,可以阅读<libevent源码分析>系统文章. 不说这么多了,直接上代码. 初等: 客户端代码: 1 #include<sys/types.h> 2 #include<sys/socket.h> 3 #include

[z]Libevent使用例子,从简单到复杂

[z]http://blog.csdn.net/luotuo44/article/details/39670221 本文从简单到复杂,展示如何使用libevent.网上的许多例子都是只有服务器端的,本文里面客户端和服务器端都有,以飨读者. 关于libevent编程时的一些疑问可以阅读<libevent编程疑难解答>.假如读者还想了解libevent的具体实现,可以阅读<libevent源码分析>系统文章. 不说这么多了,直接上代码. 初等: 客户端代码: [cpp] view pl

Libevent使用样例,从简单到复杂

        转载请注明出处:http://blog.csdn.net/luotuo44/article/details/39670221 本文从简单到复杂.展示怎样使用libevent.网上的很多样例都是仅仅有server端的,本文里面client和server端都有,以飨读者. 关于libevent编程时的一些疑问能够阅读<libevent编程疑难解答>.假如读者还想了解libevent的详细实现,能够阅读<libevent源代码分析>系统文章. 不说这么多了.直接上代码.

Linux下Libevent安装和简单实用

前言 Libevent 是一个用C语言编写的.轻量级的开源高性能事件通知库,主要有以下几个亮点:事件驱动( event-driven),高性能;轻量级,专注于网络,不如 ACE 那么臃肿庞大:源代码相当精炼.易读:跨平台,支持 Windows. Linux. *BSD 和 Mac Os:支持多种 I/O 多路复用技术, epoll. poll. dev/poll. select 和 kqueue 等:支持 I/O,定时器和信号等事件:注册事件优先级.Libevent 已经被广泛的应用,作为底层的