1、
代码:
#include<iostream>
int main()
{
using namespace std;
const int EXT = 5;
cout << "请输入身高:___\b\b\b";
int height;
cin >> height;
cout << "身高英尺是:" << height*EXT << endl;
return 0;
}
运行结果:
2、
代码:
#include<iostream>
int main()
{
using namespace std;
const int INCH = 12;
const double MI = 2.54E-2;
const double KG = 2.2;
cout << "请输入英尺身高:____\b\b\b\b";
int height;
cin >> height;
cout << endl;
cout << "请输入英寸身高:____\b\b\b\b";
int heightCun;
cin >> heightCun;
cout << endl;
cout << "请输入体重(磅):____\b\b\b\b";
int weight;
cin >> weight;
cout << endl;
double newHeight = height*MI + (heightCun/INCH)*MI;
double newweight = weight/KG;
cout << "您的身高为:" << newHeight << "米" << endl;
cout << "您的体重为:" << newweight << "千克" <<endl;
return 0;
}
运行结果:
3、
代码:
#include<iostream>
int main()
{
using namespace std;
const int EXTDEGREE = 60;
const int EXTMINUTES = 60;
cout << "Enter a latitude in degrees, minutes, and seconds:\n";
cout << "Forst, enter the degrees:";
int degrees;
cin >> degrees;
cout << endl;
cout << "Next, enter the minutes of arc:";
int minutes;
cin >> minutes;
cout << endl;
cout << "Finally, enter te seconds of arc:";
int seconds;
cin >> seconds;
double outcome = degrees + (seconds/EXTMINUTES + minutes)/EXTDEGREE;
cout << degrees << " degrees, " << minutes << " minutes, " << seconds << " seconds = " << outcome << " degrees" <<endl;
return 0;
}
运行结果:
4、
代码:
#include<iostream>
int main()
{
using namespace std;
const int DAYHOUR = 24;
const int HOURMIN = 60;
const int MINSECONDS = 60;
cout << "Enter the number of Sencods:";
int seconds;
cin >> seconds;
cout << endl;
int days = seconds/(DAYHOUR*HOURMIN*MINSECONDS);
int afterDaysOverSeconds = (seconds-days*DAYHOUR*HOURMIN*MINSECONDS)/MINSECONDS;
int minutes = afterDaysOverSeconds/MINSECONDS;
int overSeconds = afterDaysOverSeconds-minutes*MINSECONDS;
cout << seconds << " seconds = " << days << " days, " << minutes << " minutes, " << overSeconds << " seconds" << endl;
return 0;
}
运行结果:
5、
代码:
#include<iostream>
int main()
{
using namespace std;
cout << "请输入驱车里程(英里):";
float mileage;
cin >> mileage;
cout << endl;
cout << "请输入耗油量(加仑):";
float gasoline;
cin >> gasoline;
float fuel = mileage/gasoline;
cout << "每加仑行驶里程为:" << fuel << " 英里" << endl;
return 0;
}
运行结果:
6、
代码:
#include<iostream>
int main()
{
using namespace std;
const float MILETOKM = 100/62.14;
const float GALTOL = 3.875;
cout << "输入汽车每一百公里耗油量(L):";
float gasoline;
cin >> gasoline;
float mile = 100/MILETOKM;
float ltogal = gasoline/GALTOL;
cout << "换算结果是:每加仑行驶 " << ltogal/mile << "英里" << endl;
return 0;
}
运行结果: