The C language was originally designed to support procedure-oriented programming. It was subsequently extended to C++ to support object-oriented programming (OOP). The symbol ++ in C++ indicates that it is an extension of C. C++ supports all features of C, as well added capability to support OOP. Thus you can C++ for both procedure-oriented and object-oriented paradigms.
C++ is one of the most popular programming languages available today. With it, you can develop all sorts of applications such as scientific and business applications and games. It is also a popular language for mircroprogramming and interfacing with hand-held devices and electronic circuit boards and for developing IoT applications.
This book is based on Microsoft Visual C++ 2017 but will equally apply to other versions of C++. This text is intended for beginners and intermediate users. It starts from the basics, but progresses rapidly to the more advanced features. So whether you are a beginner or an experienced C++ programmer, this book will help you master the essentials of C++ programming very quickly. The text is written in an easy-to-read style and contains numerous examples to illustrate the programming concepts. It also contains exercises for practice at the end of each chapter.
Table of Contents
Chapter 1 Introducing C++
1.1 About Visual C++
1.2 Programming Model
1.3 Editing, Compiling and Running Programs
1.4 Starting Visual C++
1.5 Sample programs
Chapter 2 C++ Basics
2.1 Structure of C++ Programs
2.2 Keywords, Identifiers and Variables
2.3 Data Types
2.4 Constants
2.5 Declaring Variables
2.6 Initializing Variables
2.7 Operators
2.8 Escape Sequences
2.9 Expressions
2.10 Assignment Statements
2.11 Input/Output Statements
2.12 Sample Programs
Chapter 3 Pointers
3.1 Computer Memory
3.2 Declaring Pointers
3.3 Pointer Operations
3.4 Pointers to Pointers
3.5 Sample Programs
Chapter 4 Control Flows
4.1 Sequence
4.2 Decision Making
4.3 Loops
4.4 Other Control Flows
4.5 Exceptions
4.6 Sample Programs
Chapter 5 Built-in Functions
5.1 Header Files
5.2 Categories of Header Files
5.3 Functions in Header Files
5.4 Sample Programs
Chapter 6 User-defined Functions
6.1 Defining Functions
6.2 Passing Arguments to Functions
6.3 Calling Functions
6.4 Returning Values
6.5 Function Prototypes
6.6 Passing Arguments by Reference
6.7 Passing Pointers to Functions
6.8 Macro and Inline Functions
6.9 Function Templates
6.10 Recursion
Chapter 7 Arrays
7.1 One-dimensional Arrays
7.2 Two-dimensional Arrays
7.3 Pointers to Arrays
7.4 Pointer Arrays
7.5 Sample Programs
Chapter 8 Structures
8.1 Declaring Structures
8.2 Accessing Structures
8.3 Array of Structures
8.4 Passing Structures to Functions
8.5 Nested Structures
8.6 Linked Lists
8.7 Sample Programs
Chapter 9 Text Files
9.1 File Streams
9.2 Reading Input from Text Files
9.3 Writing Output to Text Files
9.4 Reading from and Writing to Text Files
Chapter 10 Classes
10.1 Defining Classes
10.2 Data Hiding
10.3 Scope of Variables
10.4 Creating Objects
10.5 Static Class Members
10.6 This this Pointer
10.7 Polymorphism
10.8 Constructors
10.9 Destructors
10.10 Sample programs
Chapter 11 Inheritance
11.1 What is Inheritance
11.2 Declaring Derived Classes
11.3 Overriding Base Class Functions
11.4 Initializing Constructors
11.5 Multiple Inheritance
11.6 Virtual Functions
Chapter 12 Friends
12.1 The friend Feature
12.2 Declaring Function as Friend
12.3 Declaring Class as Friend
12.4 Declaring Non-Class Function as Friend
Objectives and Topics
This textbook aims to teach C++ programming to beginners and intermediate users by starting with fundamental concepts and progressing rapidly through advanced features. Using Microsoft Visual C++ 2017 as a practical basis, it provides a comprehensive overview of procedural and object-oriented programming.
- C++ programming fundamentals and the Microsoft Visual C++ 2017 environment.
- Control structures, loops, and data manipulation techniques.
- Advanced topics including pointers, structures, and file handling.
- Object-oriented programming concepts such as classes, inheritance, and polymorphism.
- Practical application through numerous code examples and end-of-chapter exercises.
Excerpt from the book
1.2 Programming Model
Computer programs typically read input data from input devices like the keyboard, store and process the data, and send output (results) to output devices like the monitor. This input-processing-output-storage (IPOS) is called the programming model (see Figure 1.1).
A computer program consists of a set of statements (commands, instructions). We will use these terms interchangeably in this text. Some of these commands perform the computations while others perform input/output. The program can be simple or complex depending on the tasks that it needs to perform to solve a problem.
A typical C++ program consists of include directives, define directives, variable declaration, assignment, control flow, as well as input/output statements. We will give a sample C++ program to explain these statements at the end of this chapter.
Summary of Chapters
Chapter 1 Introducing C++: This chapter provides an introduction to the C++ language, the programming model (IPOS), and basic instructions on how to use the Visual C++ 2017 environment.
Chapter 2 C++ Basics: This chapter covers fundamental syntax, including data types, variable declaration, operator types, and basic I/O statements used in C++ programs.
Chapter 3 Pointers: This chapter focuses on memory management using pointers, covering declaration, dereferencing, pointer arithmetic, and pointers to pointers.
Chapter 4 Control Flows: This chapter details control structures such as sequence, selection (if/switch statements), and iteration (loops) to manage program execution.
Chapter 5 Built-in Functions: This chapter explains the use of standard header files and library functions to perform math, string manipulation, and I/O tasks.
Chapter 6 User-defined Functions: This chapter discusses how to define custom functions, pass arguments by value or reference, and use recursion and inline functions.
Chapter 7 Arrays: This chapter covers one and two-dimensional arrays, searching, sorting, and using pointers with arrays.
Chapter 8 Structures: This chapter introduces user-defined structures for creating record-type data, including nested structures and linked lists.
Chapter 9 Text Files: This chapter explains how to perform permanent data storage and retrieval using file streams for input and output operations.
Chapter 10 Classes: This chapter focuses on object-oriented programming, covering class definition, data hiding, objects, constructors, destructors, and polymorphism.
Chapter 11 Inheritance: This chapter introduces class hierarchies, showing how derived classes inherit from base classes, including multiple inheritance and virtual functions.
Chapter 12 Friends: This chapter explains the friend keyword in C++ to allow external functions or classes access to private members.
Keywords
C++, Programming, OOP, Variables, Pointers, Functions, Arrays, Structures, Classes, Inheritance, Polymorphism, Recursion, File Streams, IDE, Data Hiding
Frequently Asked Questions
What is the core focus of this book?
This book is designed to teach C++ programming by providing a comprehensive guide that starts from the basics and covers intermediate and advanced features, with a focus on practical examples.
What are the central thematic areas covered?
The text covers essential C++ concepts ranging from basic syntax and control flows to more complex topics like object-oriented programming (OOP), memory management with pointers, data structures, and file handling.
What is the primary learning objective?
The primary goal is to help beginners and intermediate users master C++ programming effectively, enabling them to develop various applications, from scientific tools to games.
Which methodology is employed in this book?
The book utilizes a "learning through examples" approach, where each programming concept is explained and then demonstrated through annotated code examples, followed by practice exercises.
What subjects are addressed in the book's main body?
The main body systematically explores language structure, pointers, decision-making and loop control, built-in and user-defined functions, array and structure manipulation, text file I/O, and advanced OOP features like inheritance and friendship.
What keywords describe this work?
Key terms include C++, Object-Oriented Programming (OOP), Pointers, Classes, Inheritance, Recursion, and File I/O.
How does the book explain pointers to pointers?
Chapter 3 describes a pointer to a variable as "single indirection," and if a pointer points to another pointer, it is referred to as "double indirection," which is then illustrated using memory diagrams.
Why is the 'friend' feature introduced?
It is introduced to allow specific functions or classes to access private members of another class, providing a controlled bypass to standard data-hiding rules in object-oriented programming.
- Arbeit zitieren
- Prof. Dr. Palaniappan Sellappan (Autor:in), 2018, Learn C++ Programming. Through Examples, München, GRIN Verlag, https://www.grin.com/document/442590