3.1:
不知道下划线指示输入位置理解是否有误?
#include <iostream>
using namespace std;
#define c 12
int main()
{
int cun;
cout << "你的身高是____英寸?" << endl;
cin >> cun;
int a, b;
a = cun / c;
b = cun%c;
cout << "你的身高转换之后为 " << a << " 英尺," << b << " 英寸。" << endl;
cin.get();
cin.get();
return 0;
}
3.2:
#include <iostream>
using namespace std;
#define FEETtoINCH 12
#define INCHtoMILE 0.0254
#define KGtoPOUND 2.2
int main()
{
int feet, inch;
float pound, mile, kg, ibm;
cout << "请输入你的身高:__英尺__英寸。" << endl;
cin >> feet >> inch;
cout << "请输入你的体重:__磅。" << endl;
cin >> pound;
mile = INCHtoMILE*float(feet*FEETtoINCH + inch);
kg = pound / KGtoPOUND;
ibm = kg / (mile*mile);
cout << "你的体重指数为:" << ibm << endl;
cin.get();
cin.get();
return 0;
}
3.3
#include <iostream>
using namespace std;
#define T 60
int main()
{
int degree, second, minute;
double degree_d;
cout << "Enter a latitude in degrees, minutes and seconds:" << endl
<< "First, enter the degrees:";
cin >> degree;
cout << "Next, enter the minutes of arc:";
cin >> minute;
cout << "Finally, enter the seconds of arc:";
cin >> second;
degree_d = double(degree) + double(minute) / T + double(second) / T / T;
cout << degree << " degrees, " << minute << " minutes, " << second << " seconds = " << degree_d << " degrees" << endl;
cin.get();
cin.get();
return 0;
}
3.4
#include <iostream>
using namespace std;
#define T 60
#define D 24
int main()
{
long long seconds;
long long temp;
int day, hour, minu, sec;
cout << "Enter the number of seconds: ";
cin >> seconds;
sec = seconds%T;
temp = seconds / T;
minu = temp%T;
temp = temp / T;
hour = temp%T;
temp = temp / D;
day = temp;
cout << seconds << " seconds = "
<< day << " days, "
<< hour << " hours, "
<< minu << " minutes, "
<< sec << " seconds." << endl;
cin.get();
cin.get();
return 0;
}
3.5
#include <iostream>
using namespace std;
int main()
{
long long Population_USA, Population_world;
double ratio;
cout << "Enter the world's population: ";
cin >> Population_world;
cout << "Enter the population of the US: ";
cin >> Population_USA;
ratio = (double(Population_USA)) / (double(Population_world)) * 100;
cout << "The population of the US is " << ratio << "% of the world population." << endl;
cin.get();
cin.get();
return 0;
}
3.6
#include <iostream>
using namespace std;
#define LEN 1.609344 //1 英里 = 1.609344 千米
#define VOLUME 3.7854118 //1 美式加仑 = 3.7854118 升
int main()
{
double mile, gallon;
cout << "请输入以英里为单位的里程数:";
cin >> mile;
cout << "请输入以加仑为单位的汽油量:";
cin >> gallon;
cout << "美国风格的耗油量为:每加仑 " << (double(mile)) / (double(gallon)) << " 英里。" << endl;
cout << "欧洲风格的耗油量为:每 100 公里的耗油量为:" << (double(gallon*VOLUME)) / (double(mile*LEN)) * 100 << "升。" << endl;
cin.get();
cin.get();
return 0;
}
3.7
该题中不知是否是我的计算有误,运行结果总是和提供的例子对不上,欢迎指正:
#include <iostream>
using namespace std;
#define TO (62.14*3.875)
int main()
{
float mpg;
cout << "请输入美国风格的耗油量(每加仑多少英里):";
cin >> mpg;
cout << mpg << "mpg 对应的欧洲风格的耗油量为:" << TO / mpg << "/100km" << endl;
cin.get();
cin.get();
return 0;
}