c++primer plus第三章复习题和编程练习

15 篇文章 0 订阅
14 篇文章 0 订阅

复习题 

C++为什么有多种整型?根据程序的需要选择最合适的大小 

没有提供措施,程序员使用头文件limitis自己确定 

33l的类型是long整型,33是默认的int整型字面量

 不等价,第一条通过某种码表映射整型赋值,第二条直接赋码值

把88储存在char类型打印,把88强制转换成char类型打印  

 编程题

#include<iostream>
int main(int argc, char* argv[])
{
	using std::cout;
	using std::cin;
	using std::endl;

	const int C_{ 12 };
	const double H_{ 0.0254 };
	const double K_{ 2.2 };
	const int HOUR{ 24 };
	const int MI{ 60 };
	const int S{ 60 };
	//1
	double high;
	cout << "pelase enter___\b\b\b";
	cin >> high;
	double lh = high * C_ ;
	//2
	int h;
	int lh;
	double weight;
	cout << "...\n";
	cin >> lh;
	cout << "...\n";
	cin >> h;
	cout << "...\n";
	cin >> weight;
	h += lh * C_;
	double hight = h * H_;
	double k = weight / K_;
	double BMI= k / (high * high);
	//3
	int degree;
	int minutes;
	int seconds;
	cout << "degree: ";
	cin >> degree;
	cout << "minutes: ";
	cin >> minutes;
	cout << "seconds: ";
	cin >> seconds;
	double Gegree = degree + minutes / 60.0 + seconds / 60.0;
	cout << degree << "./." << minutes << "..." << seconds << "..." << degree << endl;
	//4
	long s;
	cout << "...:  ";
	cin >> s;
	cout << s / S / MI / HOUR <<"..." << s / S / MI <<"..." << s / S <<"..." << s << endl;
	//5
	long long allp;
	long long p;
	cout << "...:   ";
	cin >> allp;
	cout << "...:  ";
	cin >> p;
	cout << long double(p) / long double(allp) << endl;
	//6
	//重复太多,注意整型溢出和浮点数
	system("pause");
	return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值