c++ primer plus 第六版第三章编程练习答案
2015-02-07 14:47
423 查看
3.7.1
#include <iostream>
#include <cstdlib>
int main()
{
using namespace std;
//一米八是71英寸,foot 英尺,inch英寸
int foot, inch;
cout << "Enter your height(inch):__\b\b";
cin >> inch;
foot = inch / 12;
inch = inch % 12;
cout << "Your height is " << foot << " foot " << inch << " inch " << endl;
system("pause");
return 0;
}
3.7.2
#include <iostream>
#include <cstdlib>
int main()
{
using namespace std;
//一米八是五英尺十一英寸,75kg是165磅
int foot, inch;
float meter, pound, kilogram;
cout << "Input your foot and inch:";
cin >> foot;
cin >> inch;
cout << "Input your pound:";
cin >> pound;
meter = 0.3048*foot + (inch*1.0 / 12)*0.3048;
kilogram = pound / 2.2;
cout << "The BMI of me is " << kilogram / (meter * meter);
system("pause");
return 0;
}
3.7.3
#include <iostream>
#include <cstdlib>
int main()
{
using namespace std;
const double change = 60.0; //度分秒之间的进位为60
double degrees, minute, seconds;
cout << "Enter a latitude in degrees, minutes, and seconds: " << endl;
cout << "First, enter the degrees: ";
cin >> degrees;
cout << "Next, enter the minytes of arc: ";
cin >> minute;
cout << "Finally, enter the seconds of arc: ";
cin >> seconds;
cout << degrees << " degrees, "
<< minute << " minute, "
<< seconds << " seconds = ";
degrees = degrees + (minute) / change + (seconds) / (change * change);
cout << degrees << " degrees" << endl;
system("pause");
return 0;
}
3.7.4
#include <iostream>
#include <cstdlib>
int main()
{
using namespace std;
const float S_P_M = 60.0; //seconds per minute
const float M_P_H = 60.0; //minutes per hour
const float H_P_D = 24.0; //hours per day
int day, hour, minute, second;
cout << "Enter the number of seconds:";
cin >> second;
day = second / (S_P_M*M_P_H*H_P_D);
hour = (second - day*S_P_M*M_P_H*H_P_D) *1.0 / (S_P_M*M_P_H);
minute = (second - day*S_P_M*M_P_H*H_P_D - hour * S_P_M*M_P_H) / S_P_M;
cout << second << " seconds = ";
second = (second - day*S_P_M*M_P_H*H_P_D - hour * S_P_M*M_P_H - minute * S_P_M);
cout << day << " days, "
<< hour << " hours, "
<< minute << " minutes, "
<< second << " seconds" << endl;
system("pause");
return 0;
}
3.7.5
#include <iostream>
#include <cstdlib>
int main()
{
using namespace std;
long long population, US;
cout << "Enter the world's population :";
cin >> population;
cout << "Enter the population of the US:";
cin >> US;
cout << "The population of the US is "
<< US * 100.0 / population
<< "%"
<< "of the world population."
<< endl;
system("pause");
return 0;
}
3.7.6
#include <iostream>
#include <cstdlib>
const double KM100_TO_MILES = 62.14;
const double LITERS_PER_GALLON = 3.875;
int main(void)
{
using namespace std;
double euro_rating;
double us_rating;
cout << "Enter fuel consumption in liters per 100 km: ";
cin >> euro_rating;
us_rating = (LITERS_PER_GALLON * KM100_TO_MILES) / euro_rating;
cout << euro_rating << " liters per 100 km is ";
cout << us_rating << " miles per gallon.\n";
system("pause");
return 0;
}
#include <iostream>
#include <cstdlib>
int main()
{
using namespace std;
//一米八是71英寸,foot 英尺,inch英寸
int foot, inch;
cout << "Enter your height(inch):__\b\b";
cin >> inch;
foot = inch / 12;
inch = inch % 12;
cout << "Your height is " << foot << " foot " << inch << " inch " << endl;
system("pause");
return 0;
}
3.7.2
#include <iostream>
#include <cstdlib>
int main()
{
using namespace std;
//一米八是五英尺十一英寸,75kg是165磅
int foot, inch;
float meter, pound, kilogram;
cout << "Input your foot and inch:";
cin >> foot;
cin >> inch;
cout << "Input your pound:";
cin >> pound;
meter = 0.3048*foot + (inch*1.0 / 12)*0.3048;
kilogram = pound / 2.2;
cout << "The BMI of me is " << kilogram / (meter * meter);
system("pause");
return 0;
}
3.7.3
#include <iostream>
#include <cstdlib>
int main()
{
using namespace std;
const double change = 60.0; //度分秒之间的进位为60
double degrees, minute, seconds;
cout << "Enter a latitude in degrees, minutes, and seconds: " << endl;
cout << "First, enter the degrees: ";
cin >> degrees;
cout << "Next, enter the minytes of arc: ";
cin >> minute;
cout << "Finally, enter the seconds of arc: ";
cin >> seconds;
cout << degrees << " degrees, "
<< minute << " minute, "
<< seconds << " seconds = ";
degrees = degrees + (minute) / change + (seconds) / (change * change);
cout << degrees << " degrees" << endl;
system("pause");
return 0;
}
3.7.4
#include <iostream>
#include <cstdlib>
int main()
{
using namespace std;
const float S_P_M = 60.0; //seconds per minute
const float M_P_H = 60.0; //minutes per hour
const float H_P_D = 24.0; //hours per day
int day, hour, minute, second;
cout << "Enter the number of seconds:";
cin >> second;
day = second / (S_P_M*M_P_H*H_P_D);
hour = (second - day*S_P_M*M_P_H*H_P_D) *1.0 / (S_P_M*M_P_H);
minute = (second - day*S_P_M*M_P_H*H_P_D - hour * S_P_M*M_P_H) / S_P_M;
cout << second << " seconds = ";
second = (second - day*S_P_M*M_P_H*H_P_D - hour * S_P_M*M_P_H - minute * S_P_M);
cout << day << " days, "
<< hour << " hours, "
<< minute << " minutes, "
<< second << " seconds" << endl;
system("pause");
return 0;
}
3.7.5
#include <iostream>
#include <cstdlib>
int main()
{
using namespace std;
long long population, US;
cout << "Enter the world's population :";
cin >> population;
cout << "Enter the population of the US:";
cin >> US;
cout << "The population of the US is "
<< US * 100.0 / population
<< "%"
<< "of the world population."
<< endl;
system("pause");
return 0;
}
3.7.6
#include <iostream>
#include <cstdlib>
const double KM100_TO_MILES = 62.14;
const double LITERS_PER_GALLON = 3.875;
int main(void)
{
using namespace std;
double euro_rating;
double us_rating;
cout << "Enter fuel consumption in liters per 100 km: ";
cin >> euro_rating;
us_rating = (LITERS_PER_GALLON * KM100_TO_MILES) / euro_rating;
cout << euro_rating << " liters per 100 km is ";
cout << us_rating << " miles per gallon.\n";
system("pause");
return 0;
}
相关文章推荐
- C++ Primer Plus第六版 第三章 编程练习答案
- C++primer plus第六版课后编程练习答案2.3
- C++ Primer Plus第六版 第九章 编程练习答案
- C++primer plus第六版课后编程练习答案3.4
- C++primer plus第六版课后编程练习答案3.5
- C++ Primer Plus第六版 第六章 编程练习答案
- C++ Primer Plus第六版 第十三章 编程练习答案
- C++primer plus第六版课后编程练习答案3.1
- C++primer plus第六版课后编程练习答案4.3
- C++primer plus第六版课后编程练习答案2.4
- C++ Primer Plus第六版 第十一章 编程练习答案
- C++ PRIMER PLUS (第六版) 中文版 第七章编程练习答案
- C++ Primer Plus第六版 第七章 编程练习答案
- C++ Primer Plus第六版 第二章 编程练习答案
- C++ Primer Plus第六版 第四章 编程练习答案
- C++primer plus第六版课后编程练习答案3.2
- C++ Primer Plus第六版 第十章 编程练习答案
- C++primer plus第六版课后编程练习答案2.2
- C++primer plus第六版课后编程练习答案3.7
- C++primer plus第六版课后编程练习答案4.5