C++ primer plus(3.7习题程序)

运行环境是vs2017。稍加调试可用。

3.7.1习题

//C++ primer plus  3.7.1习题
#include <iostream>
const int moon=12;
using namespace std;
int main()
{
	
	int a,b,c;
	cout << "请输入一个整数值:\_\_\_\_\_\_\b\b\b\b\b\b";
	cin >> a;
	b = a / moon;
	c = a % moon;
	cout << a << "英寸 = " << b << "英尺" << c << "英寸" << endl;

	return 0;
}

 3.7.2习题

//C++ primer plus  3.7.2习题
#include <iostream>
using namespace std;
int main()
{


	//输入身高计算bmi,并换算成英制,为下一段程序提供英尺和英寸数据
	/*    double gao,c,a,bmi,zhong;
	    cin >> gao;
	    cout << "身高为" << gao << "厘米" << endl;
	    c = (double)gao / 100.0 / 0.0254;
	    cout << "身高" << gao << "cm等于" << c << "英寸" << endl;
	    cin >> zhong;
	    a = zhong / 2.2;
	    cout << "体重" << zhong << "kg等于" << a << "磅" << endl;
	    bmi = zhong / (gao/100*gao/100);
	    cout << bmi;
	*/

	
	
	double a, b, c, d, e,bmi,gao;
		cout<<"输入a(英尺)和b(英寸)的值:\_\_\_\_\_\_\_\b\b\b\b\b\b\b:";
		cin >> a >> b;
		gao = 0.0254*(a * 12 + b);
		cout << a<<"英尺"<<b<<"英寸="<<gao<<"米"<<endl;
		cout << "请输入c的值表示体重值(磅):\_\_\_\_\_\_\_\b\b\b\b\b\b\b";
		cin >> c;
		d = c *2.2;
		cout << c << "磅=" << d << "千克" << endl;
		bmi = d / (gao*gao);
		cout << "身高为" << a << "英尺" << b << "英寸,体重为" << c << "磅,则bmi为" << bmi << endl;

	return 0;
}

3.7.3 习题

//C++ primer plus  3.7.3习题
#include <iostream>
//const int moon=12;
const int dul = 60;
using namespace std;
int main()
{
	
	double a, b, c, d;
	cout << "Enter a latitude in degrees,minutes,and seconds:" << endl
		<< "First,enterr the degrees:";
	cin >> a;
	cout << "Next,enter the minutes of arc:";
	cin >> b;
	cout << "Finally,enter the minutes of arc:";
	cin >> c;
	d = a + b / dul + c / dul / dul;
	cout << a << " degrees, " << b << " minutes, " << c << " seconds =" << d << " degrees";
	
	return 0;
}

3.7.4 习题

//C++ primer plus  3.7.4习题
#include <iostream>
const int dul = 60;
using namespace std;
int main()
{

	int a, b, c, d, e,zan;
//	cout << INT_MAX;
	cout << "Enter the number of seconds:";
	cin >> a;
	e = a % dul;//秒
	zan = a / dul;

	d = zan % dul;//分
	zan = zan / dul;

	c = zan % dul;//时
	b = zan/24;//天

	cout << a << " seconds = " << b << " day, " << c << " hours, " << d << " minutes, "<<e<<" seconds";

	return 0;
}

 int:2147483647,也足够存储示例里的31600000。

3.7.5习题

//C++ primer plus  3.7.5习题
#include <iostream>
//const int moon=12;
using namespace std;
int main()
{
	long long a, b;
	double c;
	cout<<"Enter the world's population: ";
	cin >> a;
	cout << "Enter the population of the US:";
	cin >> b;
	c = (double)b /(double) a * 100;

	cout << "The population of the US is "<<c<<"% of the world population";

	return 0;
}

3.7.6 习题

每加仑英里数(mpg):里程(英里)/汽油量(加仑)

每100公里耗油量:汽油量(升)/[距离(公里)/100]

//C++ primer plus  3.7.6习题
#include <iostream>
using namespace std;
int main()
{	


	double a, b, x, c, d, y;
	cout<<"输入里程(英里)和汽油量(加仑)的值:";
	cin >> a >> b;
	x = a / b;
	cout << "汽车耗油量为一加仑的里程: "<<x<<"英里"<<endl;
	cout << "输入距离(公里)和汽油量(升):";
	cin >> c >> d;
	y = d / (c / 100);
	cout << "每100公里的耗油量: " <<  y<<"升"<< endl;

	return 0;
}

3.7.7习题

//C++ primer plus  3.7.7习题
#include <iostream>
using namespace std;
int main()
{	
	double a, b, x, c, d, y;
	cout<< "输入\"每100公里的耗油量\": ";
	cin >> a ;
	x = 1/(a/(3.875*62.14));
	cout << "每加仑燃料"<<x<<"英里"<<endl;

	return 0;
}

美国方法=1/ [ (升/3.875)/(公里/100*62.14)]

  • 2
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值