c++primerplus(第六版)课后编程练习答案 下载本文

. .

BMI=wt_kilogram/(ht_meter*ht_meter);

cout<<\体重指数) is \ return 0; }

//ex3.3 以度,分,秒输入,以度输出 #include

const int minutes_per_degree=60; const int seconds_per_minute=60; int main() {

using namespace std;

cout<<\ cout<<\ int degree; cin>>degree;

cout<<\ int minute; cin>>minute;

cout<<\ int second; cin>>second;

double show_in_degree;

show_in_degree=(double)degree+(double)minute/minutes_per_degree+(double)second/minutes_per_degree/seconds_per_minute; cout<

//ex3.4

#include

const int hours_per_day=24; const int minutes_per_hour=60; const int seconds_per_minute=60; int main() {

using namespace std;

cout<<\ long seconds; cin>>seconds;

int Day,Hour,Minute,Second;

Day=seconds/seconds_per_minute/minutes_per_hour/hours_per_day; Hour=seconds/seconds_per_minute/minutes_per_hour%hours_per_day;

word完美格式

. .

Minute=seconds/seconds_per_minute%minutes_per_hour; Second=seconds%seconds_per_minute;

cout<

//ex3.5

#include int main() {

using namespace std;

cout<<\ long long world_population; cin>>world_population;

cout<<\ long long US_population; cin>>US_population; double percentage;

percentage=(double)US_population/world_population*100;

cout<<\ return 0; }

//ex3.6 汽车耗油量-美国(mpg)or欧洲风格(L/100Km) #include int main() {

using namespace std;

cout<<\ double m_distance; cin>>m_distance;

cout<<\ double m_gasoline; cin>>m_gasoline;

cout<<\ cout<<\ cout<<\ double k_distance; cin>>k_distance;

cout<<\ double k_gasoline; cin>>k_gasoline;

cout<<\European style:\can used \

word完美格式

. .

liters of petrol per 100 kilometers\\n\ return 0; }

//ex3.7 automobile gasoline consumption-耗油量--欧洲风格(L/100Km)转换成美国风格(mpg)

#include int main() {

using namespace std;

cout<<\ <<\ double Euro_style; cin>>Euro_style;

cout<<\

cout<

// Note that 100 kilometers is 62.14 miles, and 1 gallon is 3.875 liters. //Thus, 19 mpg is about 12.4 L/100Km, and 27 mpg is about 8.7 L/100Km. Enter the automobile gasoline consumption figure in European style(liters per 100 kilometers):12.4 Converts to U.S. style(miles per gallon): 12.4 L/100Km = 19.4187 mpg Press any key to continue

// ex3.7 automobile gasoline consumption-耗油量--美国风格(mpg)转换成欧洲风格(L/100Km)

#include int main() {

using namespace std;

cout<<\ <<\ double US_style; cin>>US_style;

cout<<\ cout<

// Enter the automobile gasoline consumption figure in U.S. style(miles per gallon):19

Converts to European style(miles per gallon): 19 mpg = 12.6733L/100Km

word完美格式

. .

Press any key to continue

第四章 复合类型

//ex4.1 display the information of student #include const int Asize=20; using namespace std;

struct student//定义结构描述 {

char firstname[Asize]; char lastname[Asize]; char grade; int age; };

void display(student);//函数原型放在结构描述后 int main() {

cout<<\ student lcg;//创建结构变量(结构数据对象) cin.getline(lcg.firstname,Asize);

cout<<\ cin.getline(lcg.lastname,Asize);

cout<<\ cin>>lcg.grade;

cout<<\ cin>>lcg.age; display(lcg); return 0; }

void display(student name) {

cout<<\ cout<<\ cout<<\}

//ex4.2 use the string-class instead of char-array #include #include int main() {

using namespace std;

word完美格式