3.7.1
#include <iostream>
// 1英寸=0.0833英尺
int main()
{
using namespace std;
const double x = 0.0833;
cout << "请输入您的身高(英寸):______\b\b\b\b\b\b";
double height = 0;
cin >> height;
cout << "您的身高为 " << x*height << "英尺" << height << "英寸" << endl;
return 0;
}
3.7.2
#include <iostream>
// 1英尺=12英寸 1英寸=0.0254米 1千克=2.2磅 BMI=体重(千克)/身高(米)的平方
int main()
{
using namespace std;
double inch,feet,weight,height;
const double x = 12;
const double y = 0.0254;
const double z = 2.2;
cout << "请输入您的身高(以x英尺y英寸形式输入):\n";
cout << "英尺:";
cin >> feet;
cout << "英寸:";
cin >> inch;
cout << "您的身高为:" << feet << "英尺" << inch << "英寸" << endl;
cout << "请输入您的体重(磅):";
cin >> weight;
height = (feet * 12 + inch) * 0.0254;
cout << "您的身高为:" << height << "米。\n";
cout << "您的体重为:" << weight / 2.2 << "千克。\n";
cout << "您的BMI值为:" << weight / (2.2 * height * height) << endl;
return 0;
}
3.7.3
#include <iostream>
int main()
{
using namespace std;
double degrees,minutes,seconds;
const double x = 60;
double latitude;
cout << "Enter a latitude in degrees,minutes,and seconds:\n";
cout << "First,enter the degree:";
cin >> degrees;
cout << "Next, enter the minutes of arc:";
cin >> minutes;
cout << "Finally,enter the seconds of arc:";
cin >> seconds;
latitude = degrees + minutes/x + seconds/x;
cout << degrees << "degrees," << minutes << "minutes," << seconds << "seconds = " <<
latitude << "degrees";
return 0;
}
3.7.4
#include <iostream>
int main()
{
using namespace std;
int seconds,minutes,hours,days;
const int x = 60;
const int y = 3600;
const int z = 86400;
long long nseconds;
cout << "Enter the number of seconds:";
cin >> nseconds;
days = nseconds / z;
hours = (nseconds - days * z) / y;
minutes = (nseconds - days * z - hours * y) / x;
seconds = nseconds - days * z - hours * y - minutes * x;
cout << nseconds << " seconds = " << days << " days, " << hours << " hours, " <<
minutes << " minutes, " << seconds << " seconds\n";
return 0;
}
3.7.5
#include <iostream>
int main()
{
using namespace std;
long long world_p;
long long country_p;
cout << "Enter the world's population:";
cin >> world_p;
cout << "Enter the population of the US:";
cin >> country_p;
double rate = double(country_p) / double(world_p);
cout <<"The population of the US is " << rate * 100 << "%" <<
" of the world population." << endl;
return 0;
}
3.7.6
#include <iostream>
int main()
{
using namespace std;
double mile;
double gallon;
cout << "请输入驱车的里程:";
cin >> mile;
cout << "请输入使用的汽油量:";
cin >> gallon;
double rate = mile / gallon;
cout << "耗油一加仑行驶里程数:" << rate << "英里\n";
return 0;
}
3.7.7
#include <iostream>
int main()
{
using namespace std;
double eu;
cout << "请输入欧洲风格汽车耗油量:";
cin >> eu;
double mile = 62.14;
double gallon = eu / 3.875;
cout << "美国风格的耗油量:" << mile / gallon << endl;
return 0;
}