C++ Primer Plus(第6版) 第三章编程题答案(3.7)

1

// ConsoleApplication1.cpp : 定义控制台应用程序的入口点。
//

#include "stdafx.h"
#include<iostream>
using namespace std;
const int factor = 12;
int main()
{
    int tall;
    cout<<"Haw tall are you : ";
    cin >> tall;
    cout << "your tall is " << tall / factor << " foot and " << tall % factor << " inch." << endl;
    return 0;

}

2

// ConsoleApplication1.cpp : 定义控制台应用程序的入口点。
//

//#include "stdafx.h"
#include<iostream>
//#include<cmath>
using namespace std;
const int factor = 12;
const float vins = 2.2;
const float moon = 0.0254;
int main()
{
    int foot,inch,pound;
    cout << "Haw tall are you : ";
    cout << " foot and inch " << endl;
    cin >> foot;
    cin >> inch;
    cout << "How many yur weight : ";
    cin >> pound;
    cout << "your tall is " << foot*factor+inch << " inch or your tall is " << moon*(foot*factor+inch) << " meter." << endl;
    cout << "your weight is " << pound / vins << " kg" << endl;
    cout << "your BMI is " << (pound / vins) / pow(moon*(foot*factor + inch), 2) << endl;
    return 0;

}

3

// ConsoleApplication1.cpp : 定义控制台应用程序的入口点。
//

//#include "stdafx.h"
#include<iostream>
//#include<cmath>
using namespace std;
const int factor = 60;
int main()
{
    float d,m,s;
    cout << "Enter a latitude in degreees,minutes,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;
    cout << d << " degrees," << m << " minutes," << s << " seconds = " << d + (m + s / 60) / 60 << " degrees";
    return 0;

}

4

// ConsoleApplication1.cpp : 定义控制台应用程序的入口点。
//

//#include "stdafx.h"
#include<iostream>
//#include<cmath>
using namespace std;
const int d_factor =24*60*60;
const int h_factor = 60 * 60;
const int m_factor = 60;
int main()
{
    long long s;
    cout << "Enter the number of seconds : ";
    cin >> s;
    cout << s << " seconds = " << s / d_factor << " days, " << (s%d_factor) / h_factor << " hours, " << ((s%d_factor) % h_factor) / m_factor << " minutes, " << ((s%d_factor) % h_factor) % m_factor << " seconds" << endl;
    return 0;

}

5

// ConsoleApplication1.cpp : 定义控制台应用程序的入口点。
//

//#include "stdafx.h"
#include<iostream>
//#include<cmath>
using namespace std;
int main()
{
    long long p_w, p_a;
    cout << "Enter the world's population : ";
    cin >> p_w;
    cout << "Enter the population of the US : ";
    cin >> p_a;
    cout << "The population of the US is " << p_a*100.0/p_w << "% of the world population.";
    return 0;

}

6

// ConsoleApplication1.cpp : 定义控制台应用程序的入口点。
//

//#include "stdafx.h"
#include<iostream>
//#include<cmath>
using namespace std;
int main()
{
    float km, l;
    cout << "输入公里数 : ";
    cin >> km;
    cout << "输入耗油量(升) : ";
    cin >> l;
    cout << "百公里耗油量为:" << l*100/ km;
    return 0;

}

7

// ConsoleApplication1.cpp : 定义控制台应用程序的入口点。
//

//#include "stdafx.h"
#include<iostream>
//#include<cmath>
using namespace std;
int main()
{
    float  l;
    cout << "输入每100公里消耗的汽油量(升) : ";
    cin >> l;
    cout <<1.0/( l / (3.875*62.14)) << " mpg";
    return 0;
}

 

 

 

 

 

 


 

 

 

 

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值