C++ Primer Plus (第六版) 编程练习3.7

来源:互联网 发布:课件下载软件 编辑:程序博客网 时间:2024/06/08 10:03

#1:

#include "iostream"
using namespace std;
int main()
{
int inchHeight;
const int p = 12;
cout << "Please Enter Your height(inch):______\b\b\b\b\b";
cin >> inchHeight;
cout << "That is " << inchHeight / p << " foot and " << inchHeight%p << " inch\n";
system("pause");
return 0;
}

#2:

#include "iostream"
using namespace std;
int main()
{
const int footToinch = 12;
const double inchTometer = 0.0254;
const double kgTopound = 2.2;
int footHeight, inchHeight, Height;
double poundWeight, Weight;
cout << "Please Enter Your Height:\n___ foot\b\b\b\b\b\b\b\b";
cin >> footHeight;
cout << "___ inch\b\b\b\b\b\b\b\b";
cin >> inchHeight;
cout << "Please Enter Your Weight:\n";
cout << "___ pounds\b\b\b\b\b\b\b\b\b\b";
cin >> poundWeight;
Height = (footHeight*footToinch + inchHeight)*inchTometer;
Weight = poundWeight / kgTopound;
double BMI = Weight / (Height*Height);
cout << "Your BMI = " << BMI << endl;
system("pause");
return 0;
}

#3:

#include "iostream"
using namespace std;
int main()
{
const int degTomin = 60;// 1度等于60分
const int minTosec = 60;//1分等于60秒
double _degrees, _minutes, _seconds;
double result;
cout << "Enter a latitude in degrees,minutes,and seconds:\n";
cout << "Firs, enter the degrees: ";
cin >> _degrees;
cout << "Next,enter the minutes of arc: ";
cin >> _minutes;
cout << "Finally,enter the seconds of arc: ";
cin >> _seconds;
result = _degrees + (_minutes + _seconds / minTosec) / degTomin;
cout << _degrees << " degrees, " << _minutes << " minutes, " << _seconds << " seconds = " << result << " degrees\n";
system("pause");
return 0;
}

#4:

#include "iostream"
using namespace std;
int main()
{
long long _seconds;
const int p = 60;
int _days, _hours, _mins, _sec;
cout << "Enter the number of seconds: ";
cin >> _seconds;
_days = _seconds / (p*p * 24);
_seconds %= (p*p * 24);
_hours = _seconds / (p*p);
_seconds %= (p*p);
_mins = _seconds / p;
_sec = _seconds % p;
cout << _seconds << " seconds = " << _days << " days, " << _hours << " hours, " << _mins << " minutes, " << _sec << " seconds\n";
system("pause");
return 0;
}

#5:

#include "iostream"
using namespace std;
int main()
{
long long worldPop, usPop;
double part;
cout << "Enter the world's population: ";
cin >> worldPop;
cout << "Enter the population of the US: ";
cin >> usPop;
part = double(usPop) / double(worldPop)*100.00;
cout << "The population of the US is " << part << "% of the world population.\6n";
system("pause");
return 0;
}

#6:

#include "iostream"
using namespace std;
int main()
{
double distance, oilWear;
cout << "Please Enter the distance: ___ km\b\b\b\b\b\b";
cin >> distance;
cout << "Please Enter the oil wear: ___ L\b\b\b\b\b";
cin >> oilWear;
double oilWear_per_100km = oilWear / distance * 100;
cout << "The oil wear per 100km is " << oilWear_per_100km <<" L"<< endl;
system("pause");
return 0;
}

#7:

#include "iostream"
using namespace std;
int main()
{
double oilwear_Europe, oilwear_US;
double kmToMile = 62.14, gallonTolitre = 3.875;
cout << "Pleas enter the oil wear per 100 km in the Europe: ___ L/100km\b\b\b\b\b\b\b\b\b\b\b";
cin >> oilwear_Europe;
oilwear_US = kmToMile / (oilwear_Europe / gallonTolitre);
cout << oilwear_Europe << " L/100km in the Europe is about " << oilwear_US << " mpg in the US.\n";
system("pause");
return 0;
}

1 0
原创粉丝点击