C++_Primer_Plus第二章习题解答.pdf_第1页
C++_Primer_Plus第二章习题解答.pdf_第2页
C++_Primer_Plus第二章习题解答.pdf_第3页
C++_Primer_Plus第二章习题解答.pdf_第4页
C++_Primer_Plus第二章习题解答.pdf_第5页
已阅读5页,还剩4页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1 编写一个C 程序 它显示你的姓名和地址 源程序 include include using namespace std int main string name string address cout name cout endl cout address cout endl return 0 运行结果 2 编写一个 C 程序 它要求用户输入一个以浪为单位的距离 然后将它转换为码 一浪等于 220 码 include using namespace std double feetToF double furlongs int main cout furlongs double feet feet feetToF furlongs cout furlongs furlongs feet feet endl return 0 double feetToF double furlongs return 220 furlongs 运行结果 3 编写一个C 程序 它使用3个用户定义的函数 包括main 并生成下面的输出 Three blind mice Three blind mice See how they run See how they run 其中一个函数要调用两次 该函数生成前两行 另一个函数也被调用两次 并生成其余的输出 include using namespace std void mice void run int main mice mice run run return 0 void mice cout Three blind mice endl void run cout See how they run endl 运行结果 4 编写一个程序 其中的 main 调用一个用户定义的函数 以摄氏温度值为参数 并返回相应的 华氏温度值 该程序按下面的格式要求用户输入摄氏温度值 并显示结果 Please enter a Celsius value 20 20 degrees Celsius is 68 degrees Fahrenheit 下面是转换公式 华氏温度 1 8 摄氏温度 32 0 include using namespace std double C convert F double int main double celsius double fahrenheit cout celsius fahrenheit C convert F celsius cout celsius degree Celsius is fahrenheit degrees Fahrenheit endl return 0 double C convert F double cel return 1 8 cel 32 0 运行结果 5 编写一个程序 其 main 调用一个用户定义的函数 以光年值为参数 并返回对应天文单位 的值 该程序按下面的格式要求用户输入光年值 并显示结果 Enter the number of light years 4 2 4 2 light years 265608 astronomical units 天文单位是从地球到太阳的平均距离 约 150 000 000 千米活 93 000 000 英里 光年是光一 年走的距离 约 10 万亿千米或 6 万亿英里 除太阳外 最近的恒星大约离地球 4 2 光年 请使用 double 类型 参见程序清单 2 4 转换公式为 1 光年 63 240 天文单位 include using namespace std double LY convert AU double int main double light years double astronomical units cout light years astronomical units LY convert AU light years cout light years light years astronomical units astronomical units endl double LY convert AU double light years return light years 63240 运行结果 6 编写一个程序 要求用户输入小时数和分钟数 在main 函数中 将这两个 值传递给一个void函数 后者以下面这样的格式显示这两个值 Enter the number of hours 9 Enter the number of munites 28 Time 9 28 include using namespace std void print time int int int main int hours int munite

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论