c++-pimer-plus-6th-chapter02
《C++ primer plus 英文版 第六版》娓娓道来。这个是上下分册。而且,出版时间是最新的2015年,买回来发现网上的勘误基本都被纠正过来了,极个别错误没有影响到理解,好哎!而且发现遣词造句特别简单,读着也顺畅。
电子版(PDF):
C++ Primer Plus Sixth Edition.pdf密码:910h
C++ Primer.Plus 第6版中文版密码:ihsq
Chpter Review 的解答参考书的 Appendix J
Programming Exercises 主要参考了下边的帖子:
C++-primer-plus(第6版)中文版编程练习答案(完全版).pdf密码:20rn
C++-Primer-Plus(第六版)编程习题解答(不完全版).doc密码:hxzs
charlesdong
下文 Programming Exercises 部分的代码亲自敲过,可运行。环境:macOS 下 Xcode
Chapter Review
- They are called functions.
- It causes the contents of the
iostreamfile to be substituted for this directive before final compilation.- It makes definitions made in the
stdnamespace available to a program.cout << "Hello, world" << endl;orcout << "Hello, world\n";int cheeses;cheeses = 32;cin >> cheeses;cout << "We have " << cheeses << " varieties of cheese\n";- The function
froop()expects to be called with one argument, which will be typedouble, and that the function will return a typeintvalue. For instance, it could be used as follows:
int gval = froop(3.14159);
The functionrattle()has no return value and expects anintargument. For instance, it could be used as follows:
rattle(37);
The functionprune()returns anintand expects to be used without an argument. For instance, it could be used as follows:
int residue = prune();- You don't have to use
returnin a function when the function has the return typevoid. However, you can use it if you don't give a return value:
return;- The likely cause it that the function loses a statement
using namespace std;to declare a directive of output.
placeusing namespace std;above themain()function;
placeusing std::cout;in themain()function;
type as following:using std::cout << "Please enter your PIN: " << std::endl;
Programming Exercises
1
#include <iostream>
int main()
{
using namespace std;
cout << "Name: NaRiSu;\n"
<< "Address: BeiJing;" << endl;
return 0;
}
2
#include <iostream>
int main()
{
using namespace std;
int furlong;
cin >> furlong;
cout << furlong << " furlong(s) = "
<< 220 * furlong << " yard(s)" << endl;
return 0;
}
3
#include <iostream>
void f1();
void f2();
using namespace std;
int main()
{
f1();
f1();
f2();
f2();
return 0;
}
void f1()
{
cout << "Three blind mice" << endl;
}
void f2()
{
cout << "See how they run\n"; // 也可以用f1()函数中的endl形式。
return; // void f2()表明无返回值,故可以这样写;也可以如f1()不写return语句。
}
4
#include <iostream>
int main()
{
using namespace std;
cout << "Enter your age: ";
int age;
cin >> age;
cout << "Your age in months is " << 12 * age << "." << endl;
return 0;
}
5
#include <iostream>
double fahrenheit(double);
int main()
{
using namespace std;
cout << "Please enter a Celsius value: ";
int celsius;
cin >> celsius;
cout << celsius << " degrees Celsius is "
<< fahrenheit(celsius) << " degrees Fahrenheit." << endl;
return 0;
}
double fahrenheit(double n)
{
return 1.8 * n + 32.0;
}
6
#include <iostream>
double astronomical(double);
int main()
{
using namespace std;
cout << "Enter the number of light years: ";
double light;
cin >> light;
cout << light << " light years = "
<< astronomical(light) << " astronomical units." << endl;
return 0;
}
double astronomical(double n)
{
return 63240 * n;
}
7
#include <iostream>
void f(int, int);
int main()
{
using namespace std;
cout << "Enter the number of hours: ";
int hour;
cin >> hour;
cout << "Enter the number of minutes: ";
int minute;
cin >> minute;
f(hour, minute);
return 0;
}
void f(int h, int m)
{
using namespace std;
cout << "Time: " << h << " : " << m << endl;
}
c++-pimer-plus-6th-chapter02的更多相关文章
- The 6th tip of DB Query Analyzer
The 6th tip of DB Query Analyzer MA Gen feng (Guangdong Unitoll Services incorporated, Guangzhou ...
- [转载]ECMA-262 6th Edition / Draft August 24, 2014 Draft ECMAScript Language Specification
http://people.mozilla.org/~jorendorff/es6-draft.html#sec-23.4 Draft Report Errors and Issues at: htt ...
- Chapter02 Java概述
Chapter02 Java概述 目录 Chapter02 Java概述 2.1 什么是程序 程序: 2.2 Java的重要特点 2.3 Java 运行机制及运行过程 2.3.1 Java 语言的特点 ...
- Si2151/41 6th Generation Silicon TV Tuner ICs
The Si2151/41 are the industry's most advanced silicon TV tuner ICs supporting all worldwide terre ...
- SQL --Chapter02 查询基础
SELECT 语句基础 SELECT <列名>,….. FROM <表名>; 查询全部列: SELECT * FROM <表名>; 使用AS关键字为列设置别名,设定 ...
- Codeforces Round #361 Jul.6th B题 ☺译
最近迈克忙着考前复习,他希望通过出门浮躁来冷静一下.迈克所在的城市包含N个可以浮躁的地方,分别编号为1..N.通常迈克在家也很浮躁,所以说他家属于可以浮躁的地方并且编号为1.迈克从家出发,去一些可以浮 ...
- Codeforces Round #361 Jul.6th A题 ☺译
A.迈克和手机 当迈克在沙滩上游泳的时候,他意外的把他的手机扔进了水里.不过你甭担心因为他立马买了个便宜些的代替品,这个代替品是老款九键键盘,这个键盘只有十个等大的数字按键,按以下方式排列: 1 2 ...
- October 6th 2016 Week 41st Thursday
The outer world you see is a reflection of your inner self. 你拥有什么样的内心,你就会看到什么样的世界. And we eventually ...
- September 6th 2016 Week 37th Tuesday
I only wish to face the sea, with spring flowers blossoming. 我只愿面朝大海,春暖花开. That scenery is beautiful ...
- July 6th, Week 28th Wednesday, 2016
Diligence is the mother of good fortune. 勤勉是好运之母. The mother of good fortune can be diligence, conti ...
随机推荐
- 尚硅谷面试第一季-09SpringMVC中如何解决POST请求中文乱码问题GET的又如何处理呢
目录结构: 关键代码: web.xml <filter> <filter-name>CharacterEncodingFilter</filter-name> &l ...
- xlrd、xlwt 操作excel表格详解
转自:https://www.cnblogs.com/jiablogs/p/9141414.html python操作excel主要用到xlrd和xlwt这两个库,即xlrd是读excel,xlwt是 ...
- eMMC之分区管理、总线协议和工作模式【转】
本文转载自:https://blog.csdn.net/u013686019/article/details/66472291 一.eMMC 简介 eMMC 是 embedded MultiMedia ...
- main.dart
import 'package:flutter/material.dart'; import 'package:flysnow_2ull/index/index.dart'; // 导入index.d ...
- linux内核中的cfq输入输出调度算法
1. 全称是什么? 完全公平调度算法(completely fair queuing) 2. 原理是怎样的? 先按照输入输出请求的地址进行排序,然后按排好的次序执行请求 3. 适用场景 适用于旋转式磁 ...
- ibus-libpinyin 无法选择除第一个外的候选词
其实不只一个人遇到这问题 https://github.com/libpinyin/ibus-libpinyin/issues/127 临时可用的解决办法是: 清理libpinyin的cache目录相 ...
- thinkphp如何省略index.php
省略index.php叫做 伪静态化; 共有四个步骤: MariaDB[(none)]: 表示, 目前没有选择/使用 任何数据库. 如果use了数据库, 会提示: MariaDB[mysql]... ...
- 【控制分片分配】控制Elasticsearch分片和副本的分配
ES集群中索引可能由多个分片构成,并且每个分片可以拥有多个副本.通过将一个单独的索引分为多个分片,我们可以处理不能在一个单一的服务器上面运行的大型索引,简单的说就是索引的大小过大,导致效率问题.不能运 ...
- LuoguP2680 运输计划
题目地址 题目链接 题解 二分答案,那么大于答案的路径都需要有一条公共边,maxlen-val>=二分出来的x.val是边权. 考虑树剖,对每条大于答案的路径都+1(线段树里),枚举边,如果(线 ...
- 《操作系统_FCFS和SJF》
先来先服务FCFS和短作业优先SJF进程调度 转自:https://blog.csdn.net/qq_34374664/article/details/73231072 一.概念介绍和案例解析 FCF ...