概述
记录自己的一些学习过程,如有错误,请指出!谢谢~
//3.7-1
#include<iostream>
#include <stdlib.h>
using namespace std;
int main() {
/*
注意点
1.b 退格键 控制光标的位置 达到下划线字符指示输入位置
2. 整除与取余
*/
const int cm_to_m = 100;
int height;
cout << "请输入身高:___厘米bbbbbbb";
cin >> height;
cout << "身高为:" << height / 100 << "米" << height % 100 << "厘米" << endl;
system("pause");
return 0;
}
//3.7-2
#include<iostream>
#include <stdlib.h>
using namespace std;
int main() {
const int FEET_TO_INCH = 12;//1英尺=12英寸
const
float INCN_TO_METER = 0.0254;//1英寸=0.0254米
const float POUND_TO_KG = 1.0 / 2.2;//1kg=2.2磅
float feet;
float inch;
float pound;
cout << "Please enter your feet and inch:";
cin >> feet;
cin >> inch;
cout << "Please enter your pound:";
cin >> pound;
cout << "your BMI is " << (pound*POUND_TO_KG) / (feet*FEET_TO_INCH + inch)*INCN_TO_METER << endl;
system("pause");
return 0;
}
//3.7-3
#include<iostream>
#include <stdlib.h>
using namespace std;
int main() {
const int DEGREE_TO_MINUTE = 60;//1度=60秒
const int MINUTE_TO_SECOND = 60;//1秒=60分
float degrees;
float minutes;
float seconds;
cout << "Enter a latitude in degrees, minutes, and seconds:" << endl;
cout << "First,enter the degrees:";
cin >> degrees;
cout << "Next,enter the minutes of arc:";
cin >> minutes;
cout << "Finally,enter the seconds of arc:";
cin >> seconds;
cout << degrees << " degress, " << minutes << " minutes, " << seconds
<< " seconds = " << (degrees + (minutes + seconds / MINUTE_TO_SECOND) / DEGREE_TO_MINUTE )<< " degress " << endl;
system("pause");
return 0;
}
//3.7-4
#include<iostream>
#include <stdlib.h>
using namespace std;
int main() {
const int DAY_HOUR = 24;
const int HOUR_TO_MINUTE = 60;
const int MINUTE_TO_SECOND = 60;
long seconds;
long sec;
int days;
int hours;
int minutes;
cout << "Enter the number of seconds: ";
cin >> seconds;
sec = seconds;
days = seconds / (DAY_HOUR*HOUR_TO_MINUTE*MINUTE_TO_SECOND);
seconds = seconds % (DAY_HOUR*HOUR_TO_MINUTE*MINUTE_TO_SECOND);
hours = seconds / (HOUR_TO_MINUTE*MINUTE_TO_SECOND);
seconds = seconds % (HOUR_TO_MINUTE*MINUTE_TO_SECOND);
minutes = seconds / MINUTE_TO_SECOND;
seconds = seconds % MINUTE_TO_SECOND;
cout << sec << " seconds = " << days << " days, " << hours << " hours, " << minutes << " minutes, " << seconds << " seconds" << endl;
system("pause");
return 0;
}
最后
以上就是孤独柜子为你收集整理的c++ Primer Plus (第3章编程练习)的全部内容,希望文章能够帮你解决c++ Primer Plus (第3章编程练习)所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复