C++Primer Plus(第6版)中文版编程练习答案--第五章
更新时间:2023-04-23 14:37:01 阅读量: 实用文档 文档下载
C++Primer Plus(第6版)中文版编程练习答案--第五章。这些程序是唐刀在学习的时候编写的,其中可能存在错误和不足,大家做个参考就好。
注释:这些程序是唐刀在学习的时候编写的,其中可能存在错误和不足,大家做个参考就好。
1.
#include<iostream>
intmain()
{
usingnamespacestd;
intnum_big;
intnum_small;
cout<<"pleaseinputthesmallnumber:"<<endl;
cin>>num_small;
cout<<"pleaseinputthebignumber:"<<endl;
cin>>num_big;
inttotal=0;
for(inti=num_small;i<=num_big;i++)
{
total+=i;
}
cout<<"totalis"<<total<<endl;
return0;
}
2.
#include<iostream>
#include<ArrayList>
usingnamespacestd;
intmain()
{
array<longdouble,100>arr;
arr[1]=arr[0]=1LD;
for(inti=2;i<=100;i++)
arr[i]=i*arr[i-1];
for(inti=2;i<=100;i++)
cout<<i<<"!="<<arr[i]<<endl;
return0;
}
C++Primer Plus(第6版)中文版编程练习答案--第五章。这些程序是唐刀在学习的时候编写的,其中可能存在错误和不足,大家做个参考就好。
3.
#include<iostream>
usingnamespacestd;
intmain()
{
doublenum=0;
doubletotal=0;
cout<<"inputthenumber:"<<endl;
cin>>num;
while(num!=0)
{
total+=num;
cout<<"inputthenumberagain:"<<endl;
cin>>num;
}
cout<<"gameover!"<<endl;
cout<<"thetotalofthesenumberis"<<total<<endl;
return0;
}
4.
#include<iostream>
usingnamespacestd;
intmain()
{
doubled_value=0;
doublec_value=0;
intyear;
d_value=100+100*0.1;
c_value=100+100*0.05;
for(inti=2;d_value>=c_value;i++)
{
d_value=d_value+100*0.1;
c_value=c_value*1.05;
year=i;
}
cout<<"after"<<year<<"years,Cleo'smoneywillmuchthanDaphne!"<<endl;return0;
C++Primer Plus(第6版)中文版编程练习答案--第五章。这些程序是唐刀在学习的时候编写的,其中可能存在错误和不足,大家做个参考就好。
}
5.
#include<iostream>
#include<string>
usingnamespacestd;
intmain()
{
/*char*month[12]={"January","February","March","April","May","June",
"July","August","September","October","November","December"};intnum[12];
for(inti=0;i<12;i++)
{
cout<<"pleaseinputthenumberofbooksin"<<month[i]<<":"<<endl;cin>>num[i];
}
inttotal=0;
for(inti=0;i<12;i++)
{
total+=num[i];
}
cout<<"thetotalofbooksis"<<total<<endl;;*/
stringmonth[12]={"January","February","March","April","May","June",
"July","August","September","October","November","December"};intnum[12];
for(inti=0;i<12;i++)
{
cout<<"pleaseinputthenumberofbooksin"<<month[i]<<":"<<endl;cin>>num[i];
}
inttotal=0;
for(inti=0;i<12;i++)
{
total+=num[i];
}
C++Primer Plus(第6版)中文版编程练习答案--第五章。这些程序是唐刀在学习的时候编写的,其中可能存在错误和不足,大家做个参考就好。
cout<<"thetotalofbooksis"<<total<<endl;
return0;
}
6.
#include<iostream>
#include<string>
usingnamespacestd;
intmain()
{
stringmonth[12]={"January","February","March","April","May","June",
"July","August","September","October","November","December"};intnum[3][12];
for(intj=0;j<3;j++)
{
cout<<"year"<<j+1<<endl;
for(inti=0;i<12;i++)
{
cout<<"pleaseinputthenumberofbooksin"<<month[i]<<":"<<endl;cin>>num[j][i];
}
}
inttotal=0;
for(intj=0;j<3;j++)
{
for(inti=0;i<12;i++)
{
total+=num[j][
i];
}
}
cout<<"thetotalofbooksis"<<total<<endl;
return0;
}
7.
#include<iostream>
#include<string>
C++Primer Plus(第6版)中文版编程练习答案--第五章。这些程序是唐刀在学习的时候编写的,其中可能存在错误和不足,大家做个参考就好。
#include<cstring>
usingnamespacestd;
intmain()
{
structcar
{
stringname;
intyear;
};
intnum;
cout<<"howmanycarsdoyouwanttocatalog?"<<endl;cin>>num;
car*cars=newcar[num];
for(inti=0;i<num;i++)
{
cout<<"Car#"<<i+1<<":"<<endl;
cout<<"pleaseenterthemake:";
cin.sync();
getline(cin,cars[i].name);
cout<<"pleaseentertheyearmade:";
cin>>cars[i].year;
}
cout<<"hereisyourcellection:"<<endl;
for(inti=0;i<num;i++)
{
cout<<cars[i].year<<""<<cars[i].name<<endl;}
return0;
}
8.
#include<iostream>
#include<cstring>
usingnamespacestd;
intmain()
{
charword[20];
inti=0;
C++Primer Plus(第6版)中文版编程练习答案--第五章。这些程序是唐刀在学习的时候编写的,其中可能存在错误和不足,大家做个参考就好。
cout<<"enterwords(tostop,typetheworddone):"<<endl;cin>>word;
while(strcmp(word,"done")!=0)
{
i++;
cin>>word;
}
cout<<"youenteredatotalof"<<i<<"words."<<endl;return0;
}
9.
#include<iostream>
#include<cstring>
#include<string>
usingnamespacestd;
intmain()
{
stringword;
inti=0;
cout<<"enterwords(tostop,typetheworddone):"<<endl;cin>>word;
while(word!="done")
{
i++;
cin>>word;
}
cout<<"youenteredatotalof"<<i<<"words."<<endl;return0;
}
10.
#include<iostream>
usingnamespacestd;
voidshow(intn)
{
for(inti=1;i<=n;i++)
{
for(intj=0;j<n-i;j++)
{
cout<<".";
C++Primer Plus(第6版)中文版编程练习答案--第五章。这些程序是唐刀在学习的时候编写的,其中可能存在错误和不足,大家做个参考就好。
}
for(intk=0;k<i;k++)
{
cout<<"*";
}
cout<<endl;
}
}
intmain()
{
cout<<"pleaseenternumberofrows:"<<endl;intnum;
cin>>num;
show(num);
return0;
}
正在阅读:
C++Primer Plus(第6版)中文版编程练习答案--第五章04-23
中小学校心理咨询室必备档案资料(表格、记录单)等文档05-12
MIMO干扰信道下的协作干扰对齐优化算法05-15
行政法学试题及答案05-26
公共关系学教案103-03
第一初级中学化学学科导学案06-11
2012中医、中西医医师实践技能考前辅导 - 图文01-09
土地储备贷款管理办法 2012 修订版03-11
关于音乐的作文800字(精选8篇)04-01
- 教学能力大赛决赛获奖-教学实施报告-(完整图文版)
- 互联网+数据中心行业分析报告
- 2017上海杨浦区高三一模数学试题及答案
- 招商部差旅接待管理制度(4-25)
- 学生游玩安全注意事项
- 学生信息管理系统(文档模板供参考)
- 叉车门架有限元分析及系统设计
- 2014帮助残疾人志愿者服务情况记录
- 叶绿体中色素的提取和分离实验
- 中国食物成分表2020年最新权威完整改进版
- 推动国土资源领域生态文明建设
- 给水管道冲洗和消毒记录
- 计算机软件专业自我评价
- 高中数学必修1-5知识点归纳
- 2018-2022年中国第五代移动通信技术(5G)产业深度分析及发展前景研究报告发展趋势(目录)
- 生产车间巡查制度
- 2018版中国光热发电行业深度研究报告目录
- (通用)2019年中考数学总复习 第一章 第四节 数的开方与二次根式课件
- 2017_2018学年高中语文第二单元第4课说数课件粤教版
- 上市新药Lumateperone(卢美哌隆)合成检索总结报告
- 中文版
- 练习
- 答案
- 编程
- Primer
- Plus
- 重庆市2022版高一上学期语文期末考试试卷B卷
- 凝聚班级力量主题班会
- 长生小学安全日教育活动总结
- 一个社区的直接选举
- 中国特色幼儿教育行业研究及投资战略研究报告(2013版)
- 第四章 选修3课程内容的作用和定位
- 新编英语教程5Unit 3
- 基于FPGA的逆变电源控制器的研究
- 新概念英语第一册第9-10课件
- 机房工程施工组织设计方案(莱安常用版)
- 职业道德与法律知识竞赛(决赛)
- 自己写的一份关于人才储备计划的初步思路
- 英语四级作文万能模板汇总
- 海域使用论证技术导则(2010版)
- AA-A29LLAE-FREQ中文资料
- 2014年历史中考模拟试卷(必考题型最新热点有答案)精细排版直接使
- 信仰是什么 班会PPT
- 天津财经大学经济学专业培养方向说明
- 古人的诗文中赞美荷花的确实不少
- 基础巩固训练Book6 Unit 4Global warming