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;
}


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章