Apress Memorial Day

Beginning C++

By Ivor Horton

  • eBook Price: $41.99
Buy eBook Buy Print Book
Beginning C++ is based on and supersedes Ivor Horton’s previous book, Beginning ANSI C++. This book is a tutorial for beginners in C++ and discusses a subset of C++ that is suitable for beginners. The language syntax will correspond to the proposed C++14 standard.

Full Description

  • Add to Wishlist
  • ISBN13: 978-1-484200-08-7
  • 632 Pages
  • User Level: Beginner to Advanced
  • Publication Date: November 12, 2014
  • Available eBook Formats: EPUB, MOBI, PDF

Related Titles

  • C++ Standard Library Quick Reference
  • MATLAB Recipes
  • Typed PHP
  • HTML5 Quick Markup Reference
  • Learning Groovy
  • Securing PHP Apps
  • PHP Development Tool Essentials
  • Java XML and JSON
  • Spring Persistence with Hibernate, Second Edition
  • Beginning Backdrop CMS
Full Description

Beginning C++ is a tutorial for beginners in C++ and discusses a subset of C++ that is suitable for beginners. The language syntax corresponds to the C++14 standard. This book is environment neutral and does not presume any specific operating system or program development system. There is no assumption of prior programming knowledge.

All language concepts that are explained in the book are illustrated with working program examples. Most chapters include exercises for you to test your knowledge. Code downloads are provided for examples from the text and solutions to the exercises and there is an additional download for a more substantial project for you to try when you have finished the book.

This book introduces the elements of the C++ standard library that provide essential support for the language syntax that is discussed. While the Standard Template Library (STL) is not discussed to a significant extent, a few elements from the STL that are important to the notion of modern C++ are introduced and applied.

Beginning C++ is based on and supersedes Ivor Horton’s previous book, Beginning ANSI C++.

What you’ll learn

  • How to work with fundamental C++ data types and do calculations
  • How to build logic into a program using loops, choices, decisions and more
  • How to work with arrays, vectors, and strings
  • How to use raw pointers and smart pointers
  • How to program with functions and deal with program files and pre-processing directives
  • How to define your own data types using classes and class operations
  • How to implement operator overloading for your own data types
  • How to apply class inheritance and use virtual functions to obtain polymorphism and errors/exception handling
  • How to signal and handle errors using exceptions
  • How to define and use function templates and class templates
  • How to do file input and output with C++

Who this book is for

This book is for industry practitioners and students wanting to learn C++ and use this as a reference guide for their applications.

Table of Contents

Table of Contents

Chapter 1: Basic Ideas

Chapter 2: Introducing Fundamental Types of Data

Chapter 3: Working Fundamental Types

Chapter 4: Making Decisions

Chapter 5: Arrays and Loops

Chapter 6: Pointers and References

Chapter 7: Working with Strings

Chapter 8: Defining Functions

Chapter 9: Lambda Expressions

Chapter 10: Preprocessor directives

Chapter 11: Defining your own Data Types

Chapter 12: Operator Overloading

Chapter 13: Inheritance

Chapter 14: Virtual Functions and Polymorphism

Chapter 15: Runtime Errors and Exceptions

Chapter 16: Class Templates

Chapter 17: File Input and Output

Source Code/Downloads

Downloads are available to accompany this book.

Your operating system can likely extract zipped downloads automatically, but you may require software such as WinZip for PC, or StuffIt on a Mac.

Errata

If you think that you've found an error in this book, please let us know by emailing to editorial@apress.com . You will find any confirmed erratum below, so you can check if your concern has already been addressed.

On page 12:

Superscript formatting was inadvertently dropped in the following text:

F5B9E1 as a decimal value is given by

15 X 165 + 5 X 164 + 11 x 163 +9 x 162 + 14 x 161 + 1 x 160
Author Comment:

It should read:

F5B9E1 as a decimal value is given by

15 X 16 (to the 5th power) + 5 X 16 to the 4th power) + 11 x 16 (to the 3rd power) +9 x 16 (squared) + 14 x 16 (to the first power) + 1 x 16 (to the zero power)

On page 25:

In table 2-1, I believe the range of values specified for ‘short | short int’ is incorrect. The (stated) size of 2 bytes stores a range from -32,768 to 32,767, not the stated -256 to 255.
Author Comment:

Yes, this is an error. 2-byte type short stores values from -32,768 to 32,767.

On page 205:

On page 205, in the last of the insert examples, the book says

phrase.insert(16, 7, ‘*’);

The text then goes on to say:

“This inserts five asterisks in phrase immediately before character at index 13. phrase will then contain the uninformative sentence “We can insert a *******string.”

Both the insert code and the result show 7 asterisks where inserted at index position 16, not 5 asterisks at position 13.
Author Comment:

The sentence following the code should begin:

"This inserts seven asterisks in phrase..."

On page 254:

The first code example under ‘Trailing Return Types’ define a template

template <typename Tretrun, typename T1, typename T2)
Treturn vector_product(const std::vector<T2>& data1, const std::vector<T3>& data2)
{


Presumably the author meant to say

template <typename Tretrun, typename T1, typename T2)
Treturn vector_product(const std::vector<T1>& data1, const std::vector<T2>& data2)
{

Author Comment:

Yes, there is an error here. The code should be more or less as suggested:

template <typename Treturn, typename T1, typename T2)
Treturn vector_product(const std::vector<T1>& data1, const std::vector<T2>& data2)
{


On page 254:

Please see the note of correction below from the author.
Author Comment:

The code at the bottom of P254 should be:

template <typename Treturn, typename T1, typename T2>
Treturn vector_product(const std::vector<T1>& data1, const std::vector<T2>& data2)
{
if(data1.size() != data2.size()) return 0; // Guard against unequal vectors

Treturn sum{};
for(size_t i{}; i< data1.size(); ++i) sum += data1[i]*data2[i];

return sum;
}

On page 255:

Please see the note of correction below from the author.
Author Comment:

The code at the top of P255 should be:

template <typename T1, typename T2>
auto vector_product(const std::vector<T1>& data1, const std::vector<T2>& data2) -> decltype(data1[0]*data2[0])
{
if(data1.size() != data2.size()) return 0; // Guard against unequal vectors

decltype(data1[0]*data2[0]) sum {};
for(size_t i{}; i< data1.size(); ++i) sum += data1[i]*data2[i];

return sum;
}

On page 273:

There appears to be an error with the lambda example Ex9_01.cpp on page 273.

The third lambda, accessed using the variable ‘reverse’ is used but not defined.

Author Comment:

Yes, the definition of the reverse lambda is missing. The definition is:

auto reverse = [](string& s) {
size_t start{}, end{s.length() - 1};
char temp{};
while (start < end)
{
temp = s[start];
s[start++] = s[end];
s[end--] = temp;
}
};
The code above should appear immediately preceding the line:

string original{"ma is as selfless as I am"};

Best-Sellers

    1. Modern X86 Assembly Language Programming

      $34.99

      View Book

    2. Practical OpenCV

      $41.99

      View Book

    3. C Quick Syntax Reference

      $13.99

      View Book

    4. C++ 2013 for C# Developers

      $52.99

      View Book