您的位置:首页 > 编程语言 > C语言/C++

C++ Primer Plus第6版—第3章课后习题答案

2019-01-13 12:42 375 查看
[code]//第1题
#include<iostream>

int main()
{
using namespace std;
int n_,m;
const int c= 12;
cout << "输入自己身高:";
cin >> n_;
m = n_ * c;
cout << m << endl;
return 0;
}
[code]//第2题
#include<iostream>
#include<cmath>

int main()
{
using namespace std;
float a, b, c, d, e, f;
const int m = 12;
const float n = 0.0254;
const float p = 2.2;
cout << "输入英尺:";
cin >> a;
cout << "\n输入英寸:";
cin >> b;
cout << "\n输入体重:";
cin >> c;
d = c*p;
e = pow((a*m+b)*n, 2);
f = d / e;
cout << f << endl;
return 0;
}
[code]//第3题
#include<iostream>
#include<cmath>

int main()
{
using namespace std;
double d, m, s,n;
cout << "Enter a latitude in degrees,minutes,and seconds:";
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;
n = d + (m * 60 + s) / 3600;
cout << d << " degrees," << m << " minutes," << s << " seconds=" << n << " degrees" << endl;
return 0;
}
[code]//第4题
#include<iostream>
#include<cmath>

int main()
{
using namespace std;
int d,h,m,n,s;
const int a = 24;
const int b = 60;
const int c = 60;
cout << "Enter the number of seconds:";
cin >> n;
d = n / (a*b*c);
h = (n - d*a*b*c) / (b*c);
m = (n - d*a*b*c - h*b*c)/b;
s = n - d * a*b*c - h * b*c - m * b;
cout <<n << " seconds=" << d << " days," << h << " hours," << m << " minutes," <<s<<" seconds"<< endl;
return 0;
}
[code]//第5题
#include<iostream>
#include<cmath>

int main()
{
using namespace std;
double w, u, p;
cout << "Enter the world's population:";
cin >> w;
cout << "Enter the population of the US:";
cin >> u;
p = (u / w)*100;
cout << "The population of the US is " << p << "% of the world population." << endl;
return 0;
}
[code]//第6题
#include<iostream>
#include<cmath>

int main()
{
using namespace std;
double a, b, c;
cout << "输入驱车里程(英里):";
cin >> a;
cout << "使用汽油量(加仑):";
cin >> b;
c = a/b;
cout << "汽车耗油量为一加仑里程即" << c <<endl;
return 0;
}
[code]//第7题
#include<iostream>
#include<cmath>

int main()
{
using namespace std;
double l,z;
float a = 62.14;
float b = 3.875;
cout << "输入每100公里消耗的汽油量(升):";
cin >> l;
z = a * b / l;
cout << "每加仑" << z <<"英里"<<endl;
return 0;
}

 

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: