2.编写一个小程序,要求以几英尺几英寸的方式输入身高,并以磅为单位输入体重。(使用3个变量来储存这些信息。)该程序报告其BMI(Body Mass Index,体重指数)。为了计算BMI,该程序以英寸的方式指出用户的身高(1英尺为12英寸),并将以隐村为单位的身高转换为以米为单位的身高(1英寸=0.0254米)。然后,将以磅为单位的体重转换为以千克为单位的体重(1千克=2.2磅)。最后,计算相应的BMI--体重(千克)除以身高(米)的平方。用符号常量表示各种转换因子。
#include
#include
#include
using namespace std;
int main()
{
int feet,inch,pound;
const int inches_per_feet= 12;
const double meters_per_inch= 0.0254;
const double pounds_per_kg= 2.2;
cout<<"Please enter your height(feet): ";
cin>>feet;
cout<<"Please enter your height(inch): ";
cin>>inch;
cout<<"Please enter your weight: ";
cin>>pound;
double BMI=(pound/pounds_per_kg)/pow(((feet*inches_per_feet+inch)*meters_per_inch),2);
cout<<"Your BMI is: "<
#include
#include
#include
int main()
{
using namespace std;
cout<<"Enter a latitude in degrees,minutes and seconds.\n";
int degree,minute,second;
cout<<"First,enter the degrees: ";
cin>>degree;
cout<<"Next,enter the minutes: ";
cin>>minute;
cout<<"Finally,enter the seconds: ";
cin>>second;
const double exchange= 60;
double latitude= degree+(minute/exchange)+second/pow(exchange,2);
cout<
4.编写一个程序,要求用户以整数方式输入秒数(使用long或long long变量存储),然后以天、小时、分钟和秒的方式显示这段时间。使用符号常量来表示每天有多少小时、每小时有多少分钟以及每分钟有多少秒。该程序的输出应与下面类似:
#include
#include
int main()
{
using namespace std;
cout<<"Enter the number of second: ";
long long sec;
cin>>sec;
int day,hour,minute,second;
const int exc1= 24;
const int exc2= 60;
second= sec%exc2;
minute= ((sec-second)/exc2)%exc2;
hour= ((((sec-second)/exc2)-minute)/exc2)%exc1;
day= int(sec/(exc1*exc2*exc2));
cout<
#include
int main()
{
using namespace std;
unsigned long long wp,usp;
cout<<"Enter the world's population: ";
cin>>wp;
cout<<"Enter the population of the US: ";
cin>>usp;
long double ldwp,ldusp;
ldwp=wp;
ldusp=usp;
double percent= double(ldusp/ldwp)*100;
cout<<"The population of the US is "<
#include
int main()
{
using namespace std;
cout<<"Please enter the oil consumption in euro(L/km): ";
double euoc;
cin>>euoc;
const double mile_km= 62.14;
const double gallon_L= 3.875;
int usoc= 1/(euoc/(mile_km*gallon_L));
cout<<"The oil consumption in the US(miles/gallon) is "<