Mike McGrath C++
Programming Fifth Edition In easy steps is an imprint of In Easy Steps Limited 16 Hamilton Terrace . Holly Walk . Leamington Spa Warwickshire . CV32 4LY www.ineasysteps.com Fifth Edition Copyright 2017 by In Easy Steps Limited. All rights reserved. No part of this book may be reproduced or transmitted in any form or by any means, electronic or mechanical, including photocopying, recording, or by any information storage or retrieval system, without prior written permission from the publisher.
Notice of Liability Every effort has been made to ensure that this book contains accurate and current information. However, In Easy Steps Limited and the author shall not be liable for any loss or damage suffered by readers as a result of any information contained herein. Trademarks All trademarks are acknowledged as belonging to their respective companies. Contents Preface The creation of this book has provided me, Mike McGrath, a welcome opportunity to update my previous books on C++ programming with the latest techniques. All examples I have given in this book demonstrate C++ features supported by current compilers on both Windows and Linux operating systems, and in the Microsoft Visual Studio development suite, and the books screenshots illustrate the actual results produced by compiling and executing the listed code. Conventions in this book In order to clarify the code listed in the steps given in each example, I have adopted certain colorization conventions.
Components of the C++ language itself are colored blue, numeric and string values are red, programmer-specified names are black, and comments are green, like this: // Store then output a text string value. string myMessage = Hello from C++! ; cout << myMessage ; Additionally, in order to identify each source code file described in the steps, a colored icon and file name appears in the margin alongside the steps: main.cpp header.h Grabbing the source code For convenience I have placed source code files from the examples featured in this book into a single ZIP archive, providing versions for Windows and Linux platforms plus the Microsoft Visual Studio IDE. You can obtain the complete archive by following these easy steps: Browse to www.ineasysteps.com then navigate to Free Resources and choose the Downloads section Find C++ Programming in easy steps, 5th Edition in the list then click on the hyperlink entitled All Code Examples to download the archive Now, extract the archive contents to any convenient location on your computer I sincerely hope you enjoy discovering the powerful, expressive possibilities of C++ Programming and have as much fun with it as I did in writing this book. Getting started Welcome to the exciting world of C++ programming. This chapter demonstrates how to create a simple C++ program and how to store data within a program.Introducing C++ C++ is an extension of the C programming language that was first implemented on the UNIX operating system by Dennis Ritchie way back in 1972. A powerful programming language (pronounced see plus plus), designed to let you express ideas. A powerful programming language (pronounced see plus plus), designed to let you express ideas.
C++ was developed by Dr. Bjarne Stroustrup between 1983-1985 while working at AT&T Bell Labs in New Jersey. He added features to the original C language to produce what he called C with classes. These classes define programming objects with specific features that transform the procedural nature of C into the object-oriented programming language of C++. The C programming language was so named as it succeeded an earlier programming language named B that had been introduced around 1970. The name C++ displays some programmers humor because the programming ++ increment operator denotes that C++ is an extension of the C language.
C++, like C, is not platform-dependent, so programs can be created on any operating system. Most illustrations in this book depict output on the Windows operating system purely because it is the most widely used desktop platform. The examples can also be created on other platforms such as Linux or macOS. Why learn C++ programming? The C++ language is favored by many professional programmers because it allows them to create fast, compact programs that are robust and portable. Using a modern C++ Integrated Development Environment (IDE), such as Microsofts Visual Studio Community Edition, the programmer can quickly create complex applications. But to use these tools to greatest effect, the programmer must first learn quite a bit about the C++ language itself.
This book is an introduction to programming with C++, giving examples of program code and its output to demonstrate the basics of this powerful language. Microsofts free Visual Studio Community Edition IDE is used in this book to demonstrate visual programming. Should I learn C first? Opinion is divided on the question of whether it is an advantage to be familiar with C programming before moving on to C++. It would seem logical to learn the original language first in order to understand the larger extended language more readily. However, C++ is not simply a larger version of C, as the approach to object-oriented programming with C++ is markedly different to the procedural nature of C. It is, therefore, arguably better to learn C++ without previous knowledge of C to avoid confusion.
This book makes no assumption that the reader has previous knowledge of any programming language, so it is suitable for the beginner to programming in C++, whether they know C or not. If you do feel that you would benefit from learning to program in C, before moving on to C++, we recommend you try the examples in C Programming in easy steps before reading this book. Standardization of C++ As the C++ programming language gained in popularity, it was adopted by many programmers around the world as their programming language of choice. Some of these programmers began to add their own extensions to the language, so it became necessary to agree upon a precise version of C++ that could be commonly shared internationally by all programmers. A standard version of C++ was defined by a joint committee of the American National Standards Institute (ANSI) and the Industry Organization for Standardization (ISO). This version is sometimes known as ANSI C++, and is portable to any platform and to any development environment.
The examples given in this book conform to ANSI C++. Example programs run in a console window, such as the Command Prompt window on Windows systems or a shell terminal window on Linux systems, to demonstrate the mechanics of the C++ language itself. An example in the final chapter illustrates how code generated automatically by a visual development tool on the Windows platform can, once youre familiar with the C++ language, be edited to create a graphical, windowed application.
Next page