C++primer plus第三章编程练习自编程序

//第三章编程练习
//eg.1使用一个整数指出自己的身高,身高转化为英尺和英寸;
//    使用下划线指示输入位置,const表示转换因子
#include 
using namespace std;
const int Inch_Per_Foot = 12;
int main()
{
 cout << "请输入你的身高:____\b\b\b\b";
 int ht_inch;
 cin >> ht_inch;
 int ht_foot;
 int rm_inch;
 ht_foot = ht_inch / Inch_Per_Foot;
 rm_inch = ht_inch % Inch_Per_Foot;
 cout << "你的身高是" << ht_foot << "英尺" << rm_inch << "英寸" << endl;
 system("pause");
 return 0;
}
//eg.2输入几英尺几英寸的身高,以磅为单位输入体重;
//    使用三个变量储存信息,计算BMI,符号常量表示转换因子
//#include 
//using namespace std;
//const float Inch_Per_Foot = 12;
//const float Meter_Per_Inch = 0.0254;
//const float Kg_Per_Lb = 2.2;
//int main()
//{
// cout << "请输入你的英尺:___\b\b\b";
// float feet;
// cin >> feet;
// cout << "请输入你的英寸:___\b\b\b";
// float inch;
// cin >> inch;
// cout << "请输入你的体重:___\b\b\b";
// float weight;
// cin >> weight;
// float your_inch;
// your_inch = feet * Inch_Per_Foot + inch;
// float your_meter;
// your_meter = your_inch * Meter_Per_Inch;
// float your_weight;
// your_weight = weight / Kg_Per_Lb;
// float BMI;
// BMI = your_weight / (your_meter * your_meter);
// cout << "你的身高是" << your_inch << "英寸" << "等于" << your_meter << "米,"
//  << "你的体重是" << your_weight << "kg,你的BMI等于" << BMI << "!\n";
// system("pause");
// return 0;
//
//}
//eg.3以度分秒输入一个纬度,以度为单位显示,符号常量表示。
//#include 
//using namespace std;
//const double Du_Per_Fen = 60;
//const double Fen_Per_Miao = 60;
//int main()
//{
// cout << "请输入一个纬度(用度、分、秒表示)\n";
// cout << "请输入度:";
// int du;
// cin >> du;
// cout << "请输入分:";
// int fen;
// cin >> fen;
// cout << "请输入秒:";
// int miao;
// cin >> miao;
// double Du;
// Du = du + fen / Du_Per_Fen + miao / Fen_Per_Miao / Du_Per_Fen;
// cout << du << "度" << fen << "分" << miao << "秒等于" << Du << "度" << endl;
// cin.get();
// cin.get();
// return 0;
//}
//eg.4以整数的方式输入秒数,用天、小时、分钟、秒表示
//#include 
//using namespace std;
//const int HourToDay = 24;
//const int MinToHour = 60;
//const int SecToMin = 60;
//int main()
//{
// cout << "请输入秒数:";
// long seconds;
// cin >> seconds;
// int HOUR;
// int MINATE;
// int min_temp;
// int hor_temp;
// int SECOND;
// int DAY;
// SECOND = seconds % SecToMin;
// min_temp = seconds / SecToMin;
// MINATE = min_temp % MinToHour;
// hor_temp = min_temp / MinToHour;
// HOUR = hor_temp % HourToDay;
// DAY = hor_temp / HourToDay;
// cout << seconds << "秒=" << DAY << "天" << HOUR << "小时" << MINATE << "分钟" << SECOND << "秒\n";
// system("pause");
// return 0;
//}
//eg.5输入全球人口和美国人口,显示美/全球百分比
//#include 
//using namespace std;
//int main()
//{
// cout << "请输入全球人口:";
// long long W_people;
// cin >> W_people;
// cout << "请输入美国人口:";
// long long A_people;
// cin >> A_people;
// double percent;
// percent = double(A_people) / double(W_people) * 100;
// cout << "美国人口占全球人口的" << percent << "%\n";
// system("pause");
// return 0;
//}
//eg.6输入里程和耗油量,指出一加仑油的里程。
//#include 
//using namespace std;
//int main()
//{
// cout << "请输入驱车里程:";
// double licheng;
// cin >> licheng;
// cout << "请输入汽油量:";
// double qiyouliang;
// cin >> qiyouliang;
// double danweihaoyouliang;
// danweihaoyouliang = qiyouliang / licheng;
// cout << danweihaoyouliang << endl;
// system("pause");
// return 0;
//}
//eg.7欧洲风格转换美国风格
//#include 
//using namespace std;
//const double KM100_TO_MILES = 62.14;
//const double LITERS_PER_GALLON = 3.875;
//int main()
//{
// cout << "请输入欧洲风格的耗油量:";
// double E_haoyou;
// cin >> E_haoyou;
// double A_haoyou;
// A_haoyou = (LITERS_PER_GALLON * KM100_TO_MILES) / E_haoyou;
// cout << E_haoyou << " liters per 100 km is ";
// cout << A_haoyou << " miles per gallon.\n";
//}

你可能感兴趣的:(C++)