码迷,mamicode.com
首页 > 其他好文 > 详细

3-7 编程练习解答

时间:2015-08-25 21:04:41      阅读:254      评论:0      收藏:0      [点我收藏+]

标签:

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 }

 

3-7 编程练习解答

标签:

原文地址:http://www.cnblogs.com/grey-qisen/p/4758294.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!