An Introduction to C++ | p. 1 |
Chapter Objectives | p. 1 |
Chapter Overview | p. 1 |
The History of C++ | p. 1 |
Object-Oriented Programming | p. 2 |
Characteristics of an OOP Language | p. 2 |
Advantages of C++ | p. 3 |
Portability | p. 3 |
A Large Selection of Operators | p. 3 |
Flexibility | p. 3 |
Disadvantages of C++ | p. 3 |
Cryptic Appearance | p. 3 |
Operator Confusion | p. 3 |
Misused Pointer Access | p. 4 |
Running a C++ Program | p. 4 |
Editors, Compilers, and Linkers | p. 4 |
A First Program | p. 4 |
The main() Function | p. 5 |
The Include Directive | p. 6 |
Output | p. 6 |
Screen Output | p. 6 |
Advancing to a New Line | p. 7 |
Ending a Line with endl | p. 8 |
Sending Output to the Printer | p. 9 |
Skipping Blank Lines | p. 10 |
Documentation | p. 11 |
Dividing a Program Into Parts | p. 12 |
Creating Functions | p. 12 |
Declaring a Function | p. 12 |
Defining a Function | p. 12 |
Calling the Function You Create | p. 13 |
Having Trouble Getting Printer Output? | p. 14 |
Programming Style | p. 14 |
Programming/Debugging Hint | p. 15 |
Key Terms | p. 16 |
Summary | p. 16 |
Review Questions | p. 16 |
Exercises | p. 17 |
Hayley Office Supplies | p. 17 |
Basic Data Types and Structures | p. 19 |
Chapter Objectives | p. 19 |
Chapter Overview | p. 19 |
Data Items and Data Types | p. 19 |
Constants and Literals | p. 20 |
Identifiers | p. 21 |
Named Constants | p. 22 |
Variables | p. 23 |
Declaring a Variable | p. 23 |
String Variables | p. 23 |
Declaring Multiple Variables of the Same Type | p. 24 |
Location of Declarations | p. 24 |
Initializing Variables | p. 25 |
Initializing String Variables | p. 25 |
Multiple Variables and Initialization | p. 25 |
Assigning Values to a Variable | p. 26 |
Assigning a Value to Multiple Variables | p. 26 |
Assigning Values to a String Variable | p. 27 |
Moving a Portion of a String | p. 28 |
Printing Variables | p. 28 |
Formatting Data | p. 29 |
Column Width | p. 29 |
Justification | p. 29 |
Avoiding Exponential Format of Numbers | p. 29 |
Combining Multiple Flags and Manipulators | p. 29 |
Precision of Decimal Numbers | p. 30 |
Resetting Manipulators | p. 31 |
Setting the Manipulators Before the Print Line | p. 31 |
Entering Data | p. 32 |
Solving the Skipped String Entry Problem | p. 32 |
Prompts | p. 33 |
Structures | p. 35 |
Structure Variables | p. 36 |
Size of a Structure | p. 37 |
Referring to a Field within a Structure | p. 37 |
Structures within Structures | p. 38 |
Programming Style | p. 40 |
Key Terms | p. 40 |
Chapter Summary | p. 41 |
Review Questions | p. 41 |
Exercises | p. 41 |
Hayley Office Supplies | p. 43 |
Creating Objects | p. 45 |
Chapter Objectives | p. 45 |
Chapter Overview | p. 45 |
Creating Data Types Containing Functions | p. 45 |
A Structure with a Member Function | p. 46 |
Functions Defined Outside of the Structure Declaration | p. 46 |
Use of Properties by Methods | p. 47 |
Classes | p. 47 |
Objects | p. 47 |
Constructors | p. 48 |
Inline Functions | p. 49 |
Data Types for Functions | p. 50 |
Returning a Value from a Function | p. 51 |
Using the Return Value from a Function | p. 51 |
Constructors with Arguments | p. 54 |
Overloading Constructors | p. 55 |
Default Values | p. 57 |
Overloading Operators | p. 57 |
Destructors | p. 58 |
Naming a Destructor Function | p. 58 |
Contents of a Destructor | p. 58 |
Programming Hint | p. 58 |
Creating Header Files | p. 59 |
Implied Object | p. 60 |
Key Terms | p. 61 |
Chapter Summary | p. 61 |
Review Questions | p. 61 |
Exercises | p. 61 |
Hayley Office Supplies | p. 62 |
Processing Data: Calculations | p. 63 |
Chapter Overview | p. 63 |
Arithmetic Operators | p. 63 |
Binary Operators | p. 63 |
Precedence of Operators | p. 64 |
Modulus | p. 65 |
Unary Operators | p. 66 |
Increment Operator | p. 66 |
Decrement Operator | p. 66 |
Prefix versus Postfix | p. 66 |
Another Look at Precedence | p. 67 |
Assignment Operators | p. 68 |
Precedence | p. 70 |
Mixing Data Types in Calculations | p. 70 |
The sizeof Operator | p. 72 |
Exponentiation | p. 72 |
Using Calculations in a Method | p. 73 |
Manipulating String Data | p. 73 |
Combining String Fields--Concatenation | p. 73 |
Concatenating the Beginning of a String | p. 74 |
Key Terms | p. 78 |
Chapter Summary | p. 78 |
Review Questions | p. 78 |
Exercises | p. 78 |
Hayley Office Supplies | p. 81 |
Decisions | p. 83 |
Chapter Objectives | p. 83 |
Chapter Overview | p. 83 |
Making Comparisons Using Relational Operators | p. 83 |
Comparing Numeric Data | p. 84 |
Comparing Character Data | p. 84 |
Implied Conditions--True or False | p. 86 |
The Logical Operators | p. 86 |
Precedence of And and Or in Compound Conditions | p. 87 |
String Comparisons | p. 88 |
Comparaing a Specified Number of Characters | p. 88 |
Comparing Strings and Ignoring the Case | p. 89 |
Finding the Length of a String | p. 89 |
Decisions--The if Statement | p. 90 |
Using if in a Member Function | p. 93 |
Nested if Statements | p. 93 |
Compound Conditions | p. 94 |
Conditional Operator | p. 96 |
Precedence of Assignment, Logical, and Relational Operators | p. 100 |
Combining Assignment and Increment Operators | p. 101 |
Combining Increment and Logical Operators | p. 102 |
Programming Style | p. 104 |
Key Terms | p. 105 |
Chapter Summary | p. 105 |
Review Questions | p. 105 |
Exercises | p. 106 |
Hayley Office Supplies | p. 108 |
Loops and Arrays | p. 109 |
Chapter Objectives | p. 109 |
Chapter Overview | p. 109 |
Loops | p. 109 |
The while Loop | p. 110 |
Infinite Loops | p. 110 |
Priming Input | p. 111 |
The do loop | p. 113 |
The for Loop | p. 114 |
Multiple Initialization, Condition, or Action | p. 116 |
Nested Loops | p. 118 |
Highest/Lowest Logic Using the if | p. 120 |
Single Dimension Arrays | p. 121 |
Declaring an Array | p. 122 |
Initializing an Array | p. 122 |
Initializing an Array of Unspecified Size | p. 122 |
Partially Filled Array | p. 123 |
Subscripts | p. 123 |
for Loops and Arrays | p. 124 |
Using a for Loop on Partially Filled Arrays | p. 125 |
A Report Program | p. 128 |
Key Terms | p. 131 |
Chapter Summary | p. 132 |
Review Questions | p. 132 |
Exercises | p. 133 |
Hayley Office Supplies | p. 136 |
Creating Menu Programs Using the switch Statement | p. 137 |
Chapter Objectives | p. 137 |
Chapter Overview | p. 137 |
The switch Statement | p. 137 |
Break | p. 138 |
More than One Alternative for a Case | p. 138 |
Using the switch for a Range of Values | p. 143 |
Menu Programs | p. 145 |
Structure of a Menu Program | p. 146 |
Using Letters or Numbers for Menu Options | p. 149 |
Menu Hints | p. 151 |
Creating a More Generic Menu Class | p. 153 |
Running Executable Files or DOS Commands from the Menu | p. 156 |
Clearing the Screen | p. 157 |
Using Menu Bars | p. 158 |
Programming/Debugging Hint | p. 161 |
Reverse Video | p. 161 |
Printers | p. 162 |
Key Terms | p. 162 |
Chapter Summary | p. 162 |
Review Questions | p. 162 |
Exercises | p. 163 |
Hayley Office Supply | p. 164 |
Pointers | p. 165 |
Chapter Objectives | p. 165 |
Chapter Overview | p. 165 |
Pointer Variables | p. 165 |
Pointer Operators | p. 166 |
Declaring a Pointer | p. 166 |
Assigning a Pointer to the Address of a Variable | p. 166 |
Combining Declaration and Assignment of Pointers | p. 167 |
Dereferencing a Pointer Variable | p. 168 |
A Pointer Contains an Integer | p. 168 |
Summary of Pointer Characteristics | p. 170 |
Pointers to Pointers and Levels of Indirection | p. 170 |
Decreases, and Increases | p. 171 |
Pointers as Function Arguments | p. 172 |
Function Call by Reference to a Local Variable Address | p. 173 |
Reference Operator | p. 174 |
Passing Addresses of Functions | p. 175 |
Menu Revisited | p. 176 |
The Header File | p. 176 |
The MENU Program | p. 178 |
Multiple Level Menus | p. 179 |
Inheritance | p. 180 |
Key Terms | p. 186 |
Chapter Summary | p. 186 |
Review Questions | p. 186 |
Exercises | p. 186 |
Hayley Office Supplies | p. 187 |
Pointers and Arrays | p. 189 |
Chapter Objectives | p. 189 |
Chapter Overview | p. 189 |
Pointer Calculations | p. 190 |
Pointers and Arrays | p. 191 |
Accessing a Single-Dimensional Array with Pointers | p. 192 |
Accessing a String Using Pointers | p. 192 |
Multidimensional Arrays | p. 193 |
Initializing Multidimensional Arrays | p. 194 |
Accessing a Two-Level Array with Nested Loops | p. 194 |
Multidimensional Arrays and Pointers | p. 196 |
Pointers to Pointers and Multidimensional Arrays | p. 196 |
Incrementing the Pointers | p. 197 |
Accessing a Multidimensional Array with Pointers | p. 198 |
Accessing a Multidimensional Array as a Single Array | p. 198 |
Accessing Data in an Array | p. 199 |
Searching an Array | p. 200 |
Serial Search | p. 200 |
Binary Search | p. 203 |
Sorting Data in an Array | p. 208 |
An Exchange Sort | p. 208 |
Using the qsort() Function | p. 209 |
The Compare Function in qsort() and bsearch() | p. 211 |
Pointers and Structures | p. 212 |
The new and delete Operators | p. 215 |
Programming/Debugging Tip | p. 217 |
Key Terms | p. 217 |
Chapter Summary | p. 217 |
Review Questions | p. 218 |
Exercises | p. 218 |
Hayley Office Supplies | p. 222 |
File Input/Output Using Structures | p. 223 |
Chapter Objectives | p. 223 |
Chapter Overview | p. 223 |
Sequential vs. Random File Access | p. 223 |
Using Structures in Data Files | p. 224 |
Random File Access | p. 224 |
Data Files | p. 224 |
File Modes | p. 224 |
Attaching a File to a stream | p. 225 |
The open() function | p. 225 |
Closing a File | p. 226 |
Testing If the File Exists | p. 227 |
Writing to the File | p. 227 |
Reading Data from a Disk File | p. 228 |
The seekp() function | p. 229 |
The seekg() function | p. 229 |
The tellg() Function | p. 229 |
Updating a Random File | p. 230 |
The Class for the File | p. 231 |
The Write Routine | p. 232 |
The Read Routine | p. 233 |
Using the Same Screen | p. 233 |
Adding Records to the File | p. 234 |
Deleting or Editing a Record | p. 234 |
Flagging a Record for Delete | p. 235 |
Using a Delete Code | p. 235 |
Editing Records | p. 237 |
Listing Records from the File | p. 239 |
Printing to the Screen | p. 240 |
Printing to the Printer | p. 240 |
The List Routine | p. 240 |
Replacing Deleted Record Positions during Add | p. 242 |
Complete Update Class | p. 242 |
Programming/Debugging Tip | p. 255 |
Hash Addressing | p. 255 |
Hashing Algorithm | p. 255 |
Key Terms | p. 257 |
Chapter Summary | p. 258 |
Review Questions | p. 258 |
Exercises | p. 258 |
Hayley Office Supplies | p. 261 |
Table of Contents provided by Syndetics. All Rights Reserved. |