#include "stdafx.h"
#include <iostream>
#include <string>
#include <climits>
using namespace std;
const int foot2in = 12;
const double in2m = 0.0254;
const double kg2pd = 2.2;
const int de2mi2se = 60;
const int se2mi = 60;
const int se2hour = 3600;
const int se2day = 86400;
const double gl2yl = 62.14;
const double jl2s = 3.875;
void Xiti1()
{
int high;
cout << "请输入自己的身高(单位英寸):___\b\b\b";
cin >> high;
int foot = high / foot2in;
int in = high % foot2in;
cout << endl << "身高为:" << foot << "英尺" << in << "英寸\n";
return;
}
void Xiti2()
{
cout << "请输入你的身高(以英尺和英寸的模式)\n";
cout << "首先输入英尺:\n";
double height_foot = 0;
cin >> height_foot;
cout << "然后输入英寸:\n";
double height_inch = 0;
cin >> height_inch;
cout << "输入重量(磅为单位):\n";
double weight_pd = 0;
cin >> weight_pd;
double height = height_foot*foot2in + height_inch;
cout << "你的身高为" << height << "英寸\n";
double height_mi = height*in2m;
cout << "你的身高为" << height_mi << "米\n";
double weight_kg = weight_pd / kg2pd;
cout << "你的体重为" << weight_kg << "千克\n";
cout << "BMI为" << weight_kg/(height_mi*height_mi)<<endl;
return;
}
void Xiti3_1()
{
cout << "请输入一个纬度(以度、分、秒的模式)\n";
cout << "首先输入度数:\n";
double degrees = 0;
cin >> degrees;
cout << "然后输入分:\n";
double minute = 0;
cin >> minute;
cout << "最后输入秒:\n";
double second = 0;
cin >> second;
cout << degrees << "度" << minute << "分" << second << "秒" << "也就是" << degrees + minute / de2mi2se + second / de2mi2se / de2mi2se << "度。\n";
return;
}
void Xiti4()
{
long long seconds;
cout << "请输入秒数:" << endl;
cin >> seconds;
long long day= seconds/se2day;
int hour=seconds%se2day/se2hour;
int minute=seconds%se2day%se2hour/se2mi;
int second=seconds%60;
cout << seconds << "秒=" << day << "天," << hour << "小时," << minute << "分钟," << second << "秒\n";
return;
}
void Xiti5()
{
long long popu_world,popu_china;
cout << "请输入全球的人口数:\n" << endl;
cin >> popu_world;
cout << "请输入中国的人口数:\n" << endl;
cin >> popu_china;
double bili=((double)popu_china/popu_world)*100.00;
cout << "中国的人口占世界人口的"<<bili<<"%\n";
return ;
}
void Xiti6()
{
double distance, gallon;
cout << "请输入公里数:\n" << endl;
cin >> distance;
cout << "请输入油量(升):\n" << endl;
cin >> gallon;
double bili = 100*gallon/distance;
cout << "油耗:100公里" << bili << "升\n";
return ;
}
void Xiti7()
{
double youhao_ou, youhao_mei;
cout << "请输入欧洲标准油耗(100公里):\n" << endl;
cin >> youhao_ou;
youhao_mei = gl2yl*jl2s / youhao_ou;
cout << "美国油耗:" << youhao_mei << "英里每加仑\n";
return;
}
int main()
{
int XitiNo = 1;
cout << "第三章编程练习答案:\n";
while (XitiNo>0 && XitiNo <= 7)
{
cout << "请输入习题编号或按(0)退出:\n";
cin >> XitiNo;
switch (XitiNo)
{
case 0:
{
cout << "即将退出程序啦!\n";
}break;
case 1:
{
cout << "第" << XitiNo << "题如下:\n";
Xiti1();
}break;
case 2:
{
cout << "第" << XitiNo << "题如下:\n";
Xiti2();
}break;
case 3:
{
cout << "第" << XitiNo << "题如下:\n";
Xiti3_1();
}break;
case 4:
{
cout << "第" << XitiNo << "题如下:\n";
Xiti4();
}break;
case 5:
{
Xiti5();
}break;
case 6:
{
Xiti6();
}break;
case 7:
{
Xiti7();
}break;
default:
{
cout << "即将退出程序啦\n";
}
break;
}
}
system("pause");
return 0;
}