运行环境是vs2017。稍加调试可用。
3.7.1习题
//C++ primer plus 3.7.1习题 #includeconst int moon=12; using namespace std; int main() { int a,b,c; cout << "请输入一个整数值:______bbbbbb"; cin >> a; b = a / moon; c = a % moon; cout << a << "英寸 = " << b << "英尺" << c << "英寸" << endl; return 0; }
3.7.2习题
//C++ primer plus 3.7.2习题 #includeusing namespace std; int main() { //输入身高计算bmi,并换算成英制,为下一段程序提供英尺和英寸数据 double a, b, c, d, e,bmi,gao; cout<<"输入a(英尺)和b(英寸)的值:_______bbbbbbb:"; cin >> a >> b; gao = 0.0254*(a * 12 + b); cout << a<<"英尺"<> 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//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习题 #includeconst 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, "< int:2147483647,也足够存储示例里的31600000。
3.7.5习题
//C++ primer plus 3.7.5习题 #include//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 "< 3.7.6 习题
每加仑英里数(mpg):里程(英里)/汽油量(加仑)
每100公里耗油量:汽油量(升)/[距离(公里)/100]
//C++ primer plus 3.7.6习题 #includeusing namespace std; int main() { double a, b, x, c, d, y; cout<<"输入里程(英里)和汽油量(加仑)的值:"; cin >> a >> b; x = a / b; cout << "汽车耗油量为一加仑的里程: "< > c >> d; y = d / (c / 100); cout << "每100公里的耗油量: " << y<<"升"<< endl; return 0; } 3.7.7习题
//C++ primer plus 3.7.7习题 #includeusing namespace std; int main() { double a, b, x, c, d, y; cout<< "输入"每100公里的耗油量": "; cin >> a ; x = 1/(a/(3.875*62.14)); cout << "每加仑燃料"< 美国方法=1/ [ (升/3.875)/(公里/100*62.14)]



