第一范文网 - 专业文章范例文档资料分享平台

c++-primer-plus(第六版)第二至第六章课后编程练习全部答案

来源:用户分享 时间:2025/7/31 2:32:30 本文由loading 分享 下载这篇文档手机版
说明:文章内容仅供预览,部分内容可能不全,需要完整文档或者需要复制内容,请下载word后使用。下载word有问题请添加微信号:xxxxxxx或QQ:xxxxxx 处理(尽可能给您提供完整文档),感谢您的支持与谅解。

}

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; 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;

days,\hours,\

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 \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 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; string name,dessert; cout<<\ getline(cin,name);

c++-primer-plus(第六版)第二至第六章课后编程练习全部答案.doc 将本文的Word文档下载到电脑,方便复制、编辑、收藏和打印
本文链接:https://www.diyifanwen.net/c6zd7e9tdla9ersa9pruq6ksx797jw500wme_2.html(转载请注明文章来源)
热门推荐
Copyright © 2012-2023 第一范文网 版权所有 免责声明 | 联系我们
声明 :本网站尊重并保护知识产权,根据《信息网络传播权保护条例》,如果我们转载的作品侵犯了您的权利,请在一个月内通知我们,我们会及时删除。
客服QQ:xxxxxx 邮箱:xxxxxx@qq.com
渝ICP备2023013149号
Top