Table of
Contents
Learn to Program with C++ Using the Borland C++ Compiler
Chapter 1---Where Do I Begin?
Where Do We Begin
Programming the Easy Way
Planning a Program is Like Planning a House
We Receive a Call from our 'client'
We Meet with Our Client
The Systems Development Life Cycle (SDLC)
Phase 1: The Preliminary Investigation
Phase 2: Analysis Phase
Phase 3: Design Phase
Output Design
Input Design
Processing Design
Phase 4: Development Phase
Phase 5: Implementation Phase
Phase 6: Audit and Maintenance Phase
Where To From Here?
Summary
Chapter 2--- Getting Comfortable With C++
Getting Comfortable with C++
Writing Our First C++ program
Create the Source File with a file name extension of .cpp
Compile the C++ Source File into an Executable File
Common Compiler Errors
Oops: Could Not Find File
Oops: Can’t Find the Compiler
Run the C++ Program
Elements of a C++ program
Program Comments
The Include Statement
The main() Function
Chapter 3---Data
Computer Data
Variables
Our first variable: The Local Variable
Declaring a Variable
Assigning a Value to a Variable
Declaration and Assignment Combined
A Quick Look at the Global Variable
Variable Scope and Lifetime
Constants
C++ Data Types
Numeric Data Types
short
unsigned short
int and long
unsigned int and unsigned long
float
double
Nonnumeric Data Types
bool
char and wchar_t
The String Object
Operations on Data
Arithmetic Operations
The Addition Operator (+)
The Subtraction Operator (-)
The Multiplication Operator (*)
The Division Operator (/)
The Remainder Operator (%)
The Increment Operator (++)
The Decrement Operator (--)
Order of Operations
Comparison Operators
Logical Operators
The And Operator (&&)
The Or Operator (||)
The Not Operator (!)
Summary
Chapter 4---Selection Structures
Selection Structures
Getting Input Into Your Program
The Sequence Structure---Falling Rock
The C++ Selection Structure---the If Statement
The If…Else Statement
The Switch Statement
Continuing with the Grades Calculation Project
Summary
Chapter 5---Loops
Why Loops?
The For Loop
Variations on the For Loop Theme
While Loops
The While Loop
Do-While Loop
Adding a Loop to the Grades Calculation Project
Summary
Chapter 6---Creating Your Own Functions
Modular programs are easier to maintain and understand
What is a Function?
Creating your own Functions…
Function Prototype
Method Header
The Return Type
Function Parameters and Arguments
By Default, Arguments Are Passed by Value in C++
Using Functions to Fine-tune Your Code
Function Overloading
Chapter 7---Creating Objects from Instantiable Classes
Creating Objects from Instantiable Classes
Creating Classes Is an Extension of Modular Programming
Objects Have Properties that Simulation Object Characteristics
Objects Have Behavior (Methods)
Creating objects from your classes
Changing an Object's Attributes
Calling an Object's Functions (Methods)
Creating Multiple Objects from Your Classes
Class Constructors
Class Contracts
Overloaded Constructors
Static Variables
Destroying an Object
Class Destructors
Working With Objects
Summary
Chapter 8---Controlling Access To The Data In Your Object
Controlling Access to Your Object's data
Member Variables--Public or Private?
Creating a Property: get() and set() Accessor methods
Set() Accessor Methods
get() Accessor Methods
Let's Analyze the Grades Calculation Project for Data Integrity
A surprise visit from Frank Olley
Summary
Chapter 9---Inheritance and Interfaces
Inheritance
Before Inheritance Came Along...
Creating Classes from Other Classes Using Inheritance
The Base (Parent) Class
The Derived (Child) Class
Planning Your Object Hierarchy in Advance
Abstract Classes and Pure Virtual Functions
Creating a Base Class and Derived Classes in the Grades Calculation Project
Summary
Chapter 10---Arrays
Why Arrays
What's an Array?
Declaring an Array
Adding data to the Elements of an Array
The Wonders of Array Processing
Using an Array for Averaging
A Problem with our Array
Multiple dimensioned Arrays
Creating Arrays of Objects
Summary
Chapter 11---Pointers
Why Pointers?
The Classic Example: The Swap Program
What Is A Pointer?
Declaring and Naming a Pointer
The AddressOf Operator (&)
The Indirection Operator (*)
The Swap() Function Using Pointers
Pointers and Arrays
Pointer Arithmetic
Pointers to Objects
The Free Store
Declaring Variables and Objects on the Free Store
Creating and Destroying Arrays on the Free Store---Dynamic Memory
Summary
Chapter 12---Errors and Exception Handling
Errors and Error Handling
Common Beginner Errors
Compiler Errors
C++ is Case Sensitive
Spelling 'main' as 'Main'
Forgetting to reference the std Namespace
Forgetting to include the iostream Library
Forgetting the Semicolon at the End of a Statement
A Semicolon (;) Must End a Class Definition
Braces (and Parentheses) Must Occur in Matching Pairs
Forgetting the Left and Right Parentheses for the Condition in an If Structure
Confusing the Equality Operator (==) with the Assignment Operator (=)
Forgetting to Code a Function Prototype
Forgetting to Specify a Return Type for a Function You Write
Forgetting to Return a Value from a Function You Write
Returning the Wrong 'Type' of Return Value for a Function You Write
Returning a Value from a Function Whose Return Type is Void
Creating an Overloaded Method with What You Believe to Be a Different Signature
Runtime Errors/Logic Errors
Not Initializing a Variable Is a Logic Error
Referring to an Element Outside the Array Bounds Is a Logic Error
Forgetting to Increment a Counter Variable
Forgetting to Add to an Accumulator
Not Providing a Way for a While Structure to End
Forgetting to Code a Break Statement in a Switch Structure
Division by Zero
Dealing With Errors in Your Program
C++ Exceptions and Error Handling
Basic Error Handling
Try-Catch
Should We Modify the Grades Calculation Project to Include Error Handling?
Testing the Program
Delivering and Implementing the Grades Calculation Project
Summary