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

复习题 

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

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

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

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

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

 编程题

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

你可能感兴趣的:(C++,编程练习,日常记录,c++,学习)