编程环境Visual Studio 2017
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 |
#include <iostream> using std::cout; using std::cin; using std::endl; //practice 1 const int Foot2Inch = 12; void p3_1(void) { int inch_input = 0; int inch_output = 0; int foot = 0; cout << "Please input you height in inch:___\b\b\b"; cin >> inch_input; foot = inch_input / Foot2Inch; inch_output = inch_input % Foot2Inch; cout << "Your height in inch was: " << inch_input << "; Your height in foot and inch was: " << foot << " foot " << inch_output << " inch!" << endl; return; } // practice 2 const double Inch2Meter = 0.254; const double Kilo2Pound = 2.2; void p3_2(void) { double height_foot = 0.0; double height_inch = 0.0; double height_meter = 0.0; double weight_pound = 0.0; double weight_kilo = 0.0; double BMI = 0.0; cout << "Enter your height in foot and inch" << endl; cout << "First enter the foot: "; cin >> height_foot; cout << "Second enter the inch: "; cin >> height_inch; cout << "Enter you weight in pound: "; cin >> weight_pound; height_meter = (height_foot * Foot2Inch + height_inch) * Inch2Meter; weight_kilo = weight_pound / Kilo2Pound; BMI = weight_kilo / (height_meter * height_meter); cout << "Your BIM is " << BMI << endl; } // practice 3 void p3_3(void) { int degrees = 0; int minutes = 0; int seconds = 0; double total = 0.0; cout << "Enter a latitude in degrees, minute and seconds:" << endl; cout << "First, enter the degrees: "; cin >> degrees; cout << "Next, enter the minucts of arc: "; cin >> minutes; cout << "Finally, enter the seconds of arc: "; cin >> seconds; total = degrees + minutes / 60.0 + seconds / 3600.0; cout << degrees << " degrees, " << minutes << " minutes, " << seconds << " seconds = " << total << " degrees." << endl; } // practice 4 void p3_4(void) { long long total_seconds = 0; int days = 0; int hours = 0; int minutes = 0; int seconds = 0; cout << "Enter the number of seconds: "; cin >> total_seconds; days = total_seconds / (24 * 60 * 60); hours = ((total_seconds % (24 * 60 * 60)) / (60 * 60)); minutes = ((total_seconds % (60 * 60)) / 60); seconds = (total_seconds % 60); cout << total_seconds << " seconds = " << days << " days, " << hours << " hours, " << minutes << " minutes, " << seconds << " seconds" << endl; } // practice 5 void p3_5(void) { long long world_population = 0; long long US_population = 0; double rate = 0.0; cout << "Enter the world's population :"; cin >> world_population; cout << "Enter the population of the US: "; cin >> US_population; rate = double(US_population) / (world_population); cout << "The population of the US is " << rate * 100 << "% of the world population." << endl; } // practice 6 void p3_6(void) { double mile = 0.0; double gallon = 0.0; double mile_per_gallon = 0.0; cout << "Enter the distance in mile you drive: "; cin >> mile; cout << "Enter the comsumption of oil: "; cin >> gallon; mile_per_gallon = mile / gallon; cout << "Average fuel comsuption: " << mile_per_gallon << " mile/gallon" << endl; } // practice 7 void p3_7(void) { double fuel_comsuption_eu = 0.0; double fuel_comsuption_us = 0.0; cout << "Enter the fuel comsuption in Europ standard: "; cin >> fuel_comsuption_eu; fuel_comsuption_us = fuel_comsuption_eu / 19 * 12.41; cout << "the fuel comsuption in US standard is " << fuel_comsuption_us << "/100KM" << endl; } int main(int argc, char **argv) { p3_7(); while (getchar()); return 0; } |
此文为博主原创文章,转载请标明出处
void p3_2(void)中的行
height_meter = (height_foot * Foot2Inch + height_foot) * Inch2Meter;
是否变量不对?应该为:
height_meter = (height_foot * Foot2Inch + height_inch) * Inch2Meter;
Yeah, you are right!文章改回来了,Thanks!
第三题不是要求要用符号常量的方式表示吗?
这些答案没有用到符号常量啊。。。