c++ primer plus 6th 第三章答案

//1

#include <iostream>


int main()
{
using namespace std;
const int pos=12;
int n;
cout<<"Enter your height_";
cin>>n;
cout<<"your height is "<<n/pos<<" ft "<<n%pos<<" in."<<endl;
return 0;
}

//2

#include <iostream>


int main()
{
using namespace std;
const int fti=12;
const double itm=0.0254,ktp=2.2;
int ft,in,pounds;
double height,weight;
cout<<"Please enter your ft:";
cin>>ft;
cout<<"Please enter your in:";
cin>>in;
cout<<"Please enter your pounds:";
cin>>pounds;
height=(ft*fti+in)*itm;
weight=pounds/ktp;
cout<<"Your BMI is "<<(weight/height)*(weight/height)<<endl;


return 0;
}

//3

#include <iostream>


int main()
{
using namespace std;
const double dtm=60,mts=60;
int d,m,s;
cout<<"Enter a latitude in degrees minutes and seconds"<<endl;
cout<<"First,enter the degrees:";
cin>>d;
cout<<"Next,enter the minutes of arc:";
cin>>m;
cout<<"Finally,enter the seconds of arc:";
cin>>s;
double ds;
ds=double(d)+((double)(m)+(double)(s)/mts)/dtm;
cout<<d<<" degrees,"<<m<<" minutes,"<<s<<" seconds = "<<ds<<" degrees"<<endl;
return 0;
}

//4

#include <iostream>


int main()
{
using namespace std;
const int dth=24,htm=60,mts=60;
long seconds=0;
int days=0,hours=0,minutes=0,second=0;
cout<<"Enter the number of seconds :";
cin>>seconds;
second=seconds%mts;
minutes=seconds/mts%mts;
hours=seconds/mts/htm%htm;
days=seconds/mts/htm/dth;
cout<<seconds<<" seconds = "<<days<<" days,"<<hours<<" hours,"<<minutes<<" minutes,"<<second<<" seconds"<<endl;
return 0;
}

//5

#include <iostream>




int main()
{
using namespace std;
long long q,a;
long double p;
cout<<"Enter the world's population:";
cin>>q;
cout<<"Enter the population of the US:";
cin>>a;
p=(long double)a/(long double)q;
cout<<"The population of the US is "<<p*100<<"% of the world population."<<endl;
return 0;
}


//6

#include <iostream>


int main()
{
using namespace std;
double s,k;
cout<<"enter s:";
cin>>s;
cout<<"enter k:";
cin>>k;
cout<<"v is :"<<s/k<<endl;
return 0;
}

//7

#include <iostream>


int main()
{
using namespace std;
double v;
cout<<"enter a v:";
cin>>v;
cout<<62.14/(v/3.875)<<endl;
return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值