《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

  1. They are called functions.
  2. It causes the contents of the iostream file to be substituted for this directive before final compilation.
  3. It makes definitions made in the std namespace available to a program.
  4. cout << "Hello, world" << endl; or cout << "Hello, world\n";
  5. int cheeses;
  6. cheeses = 32;
  7. cin >> cheeses;
  8. cout << "We have " << cheeses << " varieties of cheese\n";
  9. The function froop() expects to be called with one argument, which will be type double, and that the function will return a type int value. For instance, it could be used as follows:
    int gval = froop(3.14159);
    The function rattle() has no return value and expects an int argument. For instance, it could be used as follows:
    rattle(37);
    The function prune() returns an int and expects to be used without an argument. For instance, it could be used as follows:
    int residue = prune();
  10. You don't have to use return in a function when the function has the return type void. However, you can use it if you don't give a return value:
    return;
  11. The likely cause it that the function loses a statement using namespace std; to declare a directive of output.
    place using namespace std; above the main() function;
    place using std::cout; in the main() 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的更多相关文章

  1. The 6th tip of DB Query Analyzer

      The 6th tip of DB Query Analyzer MA Gen feng (Guangdong Unitoll Services incorporated, Guangzhou ...

  2. [转载]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 ...

  3. Chapter02 Java概述

    Chapter02 Java概述 目录 Chapter02 Java概述 2.1 什么是程序 程序: 2.2 Java的重要特点 2.3 Java 运行机制及运行过程 2.3.1 Java 语言的特点 ...

  4. ​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 ...

  5. SQL --Chapter02 查询基础

    SELECT 语句基础 SELECT <列名>,….. FROM <表名>; 查询全部列: SELECT * FROM <表名>; 使用AS关键字为列设置别名,设定 ...

  6. Codeforces Round #361 Jul.6th B题 ☺译

    最近迈克忙着考前复习,他希望通过出门浮躁来冷静一下.迈克所在的城市包含N个可以浮躁的地方,分别编号为1..N.通常迈克在家也很浮躁,所以说他家属于可以浮躁的地方并且编号为1.迈克从家出发,去一些可以浮 ...

  7. Codeforces Round #361 Jul.6th A题 ☺译

    A.迈克和手机 当迈克在沙滩上游泳的时候,他意外的把他的手机扔进了水里.不过你甭担心因为他立马买了个便宜些的代替品,这个代替品是老款九键键盘,这个键盘只有十个等大的数字按键,按以下方式排列: 1 2 ...

  8. October 6th 2016 Week 41st Thursday

    The outer world you see is a reflection of your inner self. 你拥有什么样的内心,你就会看到什么样的世界. And we eventually ...

  9. September 6th 2016 Week 37th Tuesday

    I only wish to face the sea, with spring flowers blossoming. 我只愿面朝大海,春暖花开. That scenery is beautiful ...

  10. July 6th, Week 28th Wednesday, 2016

    Diligence is the mother of good fortune. 勤勉是好运之母. The mother of good fortune can be diligence, conti ...

随机推荐

  1. 如何获取sdcard的总容量

    activity_main.xml <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android& ...

  2. 【python002-设计小游戏】

    用python设计第一个游戏 一.运行idle的快捷方式:F5 二.首先设计一款小游戏: print('-------开启python学习之旅--------')temp = input(" ...

  3. linux --- 3 vim 网络 用户 权限 软连接 压缩 定时任务 yum源

    一.vi 和vim vi 是老式的字处理器,不过功能已经很齐全了,但是还是有可以进步的地方. vim 则可以说是程序开发者的一项很好用的工具 ①命令模式 移动光标 w(e) 移动光标到下一个单词 b ...

  4. (转)awesome-text-summarization

    awesome-text-summarization 2018-07-19 10:45:13 A curated list of resources dedicated to text summari ...

  5. 什么是java OOM?如何分析及解决oom问题?

    最近查找了很多关于OOM,甚至于Java内存管理以及JVM的相关资料,发现这方面的东西太多了,竟有一种眼花缭乱的感觉,要想了解全面的话,恐非一篇文章能说清的,因此按照自己的理解整理了一篇,剩下的还需要 ...

  6. mathType换行等号对齐

    例如: 输入步骤: (1) (2) (3) (4) 事实上,[ctrl+;]表示的是插入了一个对齐标记符.

  7. centos7 查看防火墙状态

    [root@xxx ~]# firewall-cmd --state not running

  8. 配置多个版本的jdk

    引言: 由于公司有多个项目都需要我开发,而各个项目所依赖的jdk版本又不同,因此需要配置多个jdk; 配置方法: 什么也不说了,直接上图: 然后在其他需要制定Tomcat的地方直接引用JAVA_HOM ...

  9. 如何将购物车信息存到Redis中?

    存到Redis中,好处是速度快.毕竟写到硬盘需要更多的时间.加入购物车的功能,操作很频繁,可以通过Redis快速写入,移除,修改. 用什么方式呢? 传统的KEY,VALUE不太合适,每次增加修改,都要 ...

  10. XML_CPP_libXml2_VC6_Code_ZC

    ZC:iconv.dll.libxml2.dll.zlib1.dll 放到 exe所在目录下 1.代码来源于 帖子:XML_CPP_资料_libXml2_01_Code_ZC(?.pro) 2.代码: ...