C++ Primer Plus 第六版(中文版)课后编程题----第三章
2015-12-24 11:18
447 查看
3.1:
不知道下划线指示输入位置理解是否有误?#include <iostream> using namespace std; #define c 12 int main() { int cun; cout << "你的身高是____英寸?" << endl; cin >> cun; int a, b; a = cun / c; b = cun%c; cout << "你的身高转换之后为 " << a << " 英尺," << b << " 英寸。" << endl; cin.get(); cin.get(); return 0; }
3.2:
#include <iostream> using namespace std; #define FEETtoINCH 12 #define INCHtoMILE 0.0254 #define KGtoPOUND 2.2 int main() { int feet, inch; float pound, mile, kg, ibm; cout << "请输入你的身高:__英尺__英寸。" << endl; cin >> feet >> inch; cout << "请输入你的体重:__磅。" << endl; cin >> pound; mile = INCHtoMILE*float(feet*FEETtoINCH + inch); kg = pound / KGtoPOUND; ibm = kg / (mile*mile); cout << "你的体重指数为:" << ibm << endl; cin.get(); cin.get(); return 0; }
3.3
#include <iostream> using namespace std; #define T 60 int main() { int degree, second, minute; double degree_d; cout << "Enter a latitude in degrees, minutes and seconds:" << endl << "First, enter the degrees:"; cin >> degree; cout << "Next, enter the minutes of arc:"; cin >> minute; cout << "Finally, enter the seconds of arc:"; cin >> second; degree_d = double(degree) + double(minute) / T + double(second) / T / T; cout << degree << " degrees, " << minute << " minutes, " << second << " seconds = " << degree_d << " degrees" << endl; cin.get(); cin.get(); return 0; }
3.4
#include <iostream> using namespace std; #define T 60 #define D 24 int main() { long long seconds; long long temp; int day, hour, minu, sec; cout << "Enter the number of seconds: "; cin >> seconds; sec = seconds%T; temp = seconds / T; minu = temp%T; temp = temp / T; hour = temp%T; temp = temp / D; day = temp; cout << seconds << " seconds = " << day << " days, " << hour << " hours, " << minu << " minutes, " << sec << " seconds." << endl; cin.get(); cin.get(); return 0; }
3.5
#include <iostream> using namespace std; int main() { long long Population_USA, Population_world; double ratio; cout << "Enter the world's population: "; cin >> Population_world; cout << "Enter the population of the US: "; cin >> Population_USA; ratio = (double(Population_USA)) / (double(Population_world)) * 100; cout << "The population of the US is " << ratio << "% of the world population." << endl; cin.get(); cin.get(); return 0; }
3.6
#include <iostream> using namespace std; #define LEN 1.609344 //1 英里 = 1.609344 千米 #define VOLUME 3.7854118 //1 美式加仑 = 3.7854118 升 int main() { double mile, gallon; cout << "请输入以英里为单位的里程数:"; cin >> mile; cout << "请输入以加仑为单位的汽油量:"; cin >> gallon; cout << "美国风格的耗油量为:每加仑 " << (double(mile)) / (double(gallon)) << " 英里。" << endl; cout << "欧洲风格的耗油量为:每 100 公里的耗油量为:" << (double(gallon*VOLUME)) / (double(mile*LEN)) * 100 << "升。" << endl; cin.get(); cin.get(); return 0; }
3.7
该题中不知是否是我的计算有误,运行结果总是和提供的例子对不上,欢迎指正:#include <iostream> using namespace std; #define TO (62.14*3.875) int main() { float mpg; cout << "请输入美国风格的耗油量(每加仑多少英里):"; cin >> mpg; cout << mpg << "mpg 对应的欧洲风格的耗油量为:" << TO / mpg << "/100km" << endl; cin.get(); cin.get(); return 0; }
相关文章推荐
- win8.1 vs2010 C++环境下 编译Android Adb.exe
- VC++内存区域
- 第三章:C语言特性
- 【c/c++】const引用
- c语言指针与数组
- C++中如何产生均匀分布的随机数
- 深入解析C++中的mutable关键字
- vc++6.0找不到类视图在哪?
- mark:一组运算符优先级---c语言
- C++构造函数调用顺序
- std::bad_alloc的处理
- 单片机modebus RTU通信实现,採用C语言,可适用于单片机,VC,安卓等
- C/C++函数调用约定详解
- VC++排序 排序算法比较
- vc++比较三个数的大小
- 【c/c++】delete和delete[]详解
- VC++ fatal error RC1004: unexpected end of file found
- C++遍历文件或文件夹
- 【C++ STL应用与实现】5: 如何使用std::array (since C++11)
- C++学习:函数指针