| |
| |
| |
Overview of Programming and Problem Solving | |
| |
| |
| |
Overview of Programming | |
| |
| |
What 1s Programming? | |
| |
| |
How Do We Write a Program? | |
| |
| |
| |
What Is a Programming Language? | |
| |
| |
| |
What Is a Computer? | |
| |
| |
| |
Ethics and Responsibilities in the Computing Profession | |
| |
| |
Software Piracy | |
| |
| |
Privacy of Data | |
| |
| |
Use of Computer Resources | |
| |
| |
Software Engineering | |
| |
| |
| |
Problem-Solving Techniques | |
| |
| |
Ask Questions | |
| |
| |
Look for Things That Are Familiar | |
| |
| |
Solve by Analogy | |
| |
| |
Means-Ends Analysis | |
| |
| |
Divide and Conquer | |
| |
| |
The Building-Block Approach | |
| |
| |
Merging Solutions | |
| |
| |
Mental Blocks: The Fear of Starting | |
| |
| |
Algorithmic Problem Solving | |
| |
| |
Summary | |
| |
| |
| |
C++ Syntax and Semantics, and the Program Development Process | |
| |
| |
| |
The Elements of C++ Programs | |
| |
| |
C++ Program Structure | |
| |
| |
Syntax and Semantics | |
| |
| |
Syntax Templates | |
| |
| |
Naming Program Elements: Identifiers | |
| |
| |
Data and Data Types | |
| |
| |
Naming Elements: Declarations | |
| |
| |
Taking Action: Executable Statements | |
| |
| |
Beyond Minimalism: Adding Comments to a Program | |
| |
| |
| |
Program Construction | |
| |
| |
Blocks (Compound Statements) | |
| |
| |
The C++ Preprocessor | |
| |
| |
An Introduction to Namespaces | |
| |
| |
| |
More About Output | |
| |
| |
Creating Blank Lines | |
| |
| |
Inserting Blanks Within a Line | |
| |
| |
Programming Example: Contest Letter | |
| |
| |
Testing and Debugging | |
| |
| |
Summary | |
| |
| |
Quick Check | |
| |
| |
Exam Preparation Exercises | |
| |
| |
Programming Warm-up Exercises | |
| |
| |
Programming Problems | |
| |
| |
| |
Numeric Types, Expressions, and Output | |
| |
| |
| |
Overview of C++ Data Types | |
| |
| |
| |
Numeric Data Types | |
| |
| |
Integral Types | |
| |
| |
Floating-Point Types | |
| |
| |
| |
Declarations for Numeric Types | |
| |
| |
Named Constant Declarations | |
| |
| |
Variable Declarations | |
| |
| |
| |
Simple Arithmetic Expressions | |
| |
| |
Arithmetic Operators | |
| |
| |
Increment and Decrement Operators | |
| |
| |
| |
Compound Arithmetic Expressions | |
| |
| |
Precedence Rules | |
| |
| |
Type Coercion and Type Casting | |
| |
| |
| |
Function Calls and Library Functions | |
| |
| |
Value-Returning Functions | |
| |
| |
Library Functions | |
| |
| |
Void Functions | |
| |
| |
| |
Formatting the Output | |
| |
| |
Integers and Strings | |
| |
| |
Floating-Point Numbers | |
| |
| |
| |
Additional string Operations | |
| |
| |
The length and size Functions | |
| |
| |
The find Function | |
| |
| |
The substr Function | |
| |
| |
Programming Example: Map Measurements | |
| |
| |
Testing and Debugging | |
| |
| |
Summary | |
| |
| |
Quick Check | |
| |
| |
Exam Preparation Exercises | |
| |
| |
Programming Warm-up Exercises | |
| |
| |
Programming Problems | |
| |
| |
| |
Program Input and the Software Design Process | |
| |
| |
| |
Getting Data into Programs | |
| |
| |
Input Streams and the Extraction Operator (]]) | |
| |
| |
The Reading Marker and the Newline Character | |
| |
| |
Reading Character Data with the get Function | |
| |
| |
Skipping Characters with the ignore Function | |
| |
| |
Reading String Data | |
| |
| |
| |
Interactive Input/Output | |
| |
| |
| |
Noninteractive Input/Output | |
| |
| |
| |
File Input and Output | |
| |
| |
Files | |
| |
| |
Using Files | |
| |
| |
An Example Program Using Files | |
| |
| |
Run-Time Input of File Names | |
| |
| |
| |
Input Failure | |
| |
| |
| |
Software Design Methodologies | |
| |
| |
| |
What Are Objects? | |
| |
| |
| |
Object-Oriented Design | |
| |
| |
| |
Functional Decomposition | |
| |
| |
Modules | |
| |
| |
A Perspective on Design | |
| |
| |
Programming Example: Stretching a Canvas | |
| |
| |
Testing and Debugging | |
| |
| |
Testing and Debugging Hints | |
| |
| |
Summary | |
| |
| |
Quick Check | |
| |
| |
Exam Preparation Exercises | |
| |
| |
Programming Warm-up Exercises | |
| |
| |
Programming Problems | |
| |
| |
| |
Conditions, Logical Expressions, and Selection Control Structures | |
| |
| |
| |
Flow of Control | |
| |
| |
Selection | |
| |
| |
| |
Conditions and Logical Expressions | |
| |
| |
The bool Data Type | |
| |
| |
Logical Expressions | |
| |
| |
Precedence of Operators | |
| |
| |
Relational Operators with Floating-Point Types | |
| |
| |
| |
The If Statement | |
| |
| |
The If-Then-Else Form | |
| |
| |
Blocks (Compound Statements) | |
| |
| |
The If-Then Form | |
| |
| |
A Common Mistake | |
| |
| |
| |
Nested If Statements | |
| |
| |
The Dangling else | |
| |
| |
| |
Testing the State of an I/O Stream | |
| |
| |
Programming Example: Warning Notices | |
| |
| |
Testing and Debugging | |
| |
| |
Testing in the Problem-Solving Phase: The Algorithm Walk-Through | |
| |
| |
Testing in the Implementation Phase | |
| |
| |
The Test Plan | |
| |
| |
Tests Performed Automatically During Compilation and Execution | |
| |
| |
Testing and Debugging Hints | |
| |
| |
Summary | |
| |
| |
Quick Check | |
| |
| |
Exam Preparation Exercises | |
| |
| |
Programming Warm-up Exercises | |
| |
| |
Programming Problems | |
| |
| |
| |
Looping | |
| |
| |
| |
The While Statement | |
| |
| |
| |
Phases of Loop Execution | |
| |
| |
| |
Loops Using the While Statement | |
| |
| |
Count-Controlled Loops | |
| |
| |
Event-Controlled Loops | |
| |
| |
Looping Subtasks | |
| |
| |
| |
How to Design Loops | |
| |
| |
Designing the Flow of Control | |
| |
| |
Designing the Process Within the Loop | |
| |
| |
The Loop Exit | |
| |
| |
| |
Nested Logic | |
| |
| |
Designing Nested Loops | |
| |
| |
Programming Example: Average Income by Gender | |
| |
| |
Testing and Debugging | |
| |
| |
Loop-Testing Strategy | |
| |
| |
Test Plans Involving Loops | |
| |
| |
Testing and Debugging Hints | |
| |
| |
Summary | |
| |
| |
Quick Check | |
| |
| |
Exam Preparation Exercises | |
| |
| |
Programming Warm-up Exercises | |
| |
| |
Programming Problems | |
| |
| |
| |
Functions | |
| |
| |
| |
Functional Decomposition with Void Functions | |
| |
| |
Writing Modules as Void Functions | |
| |
| |
| |
An Overview of User-Defined Functions | |
| |
| |
Flow of Control in Function Calls | |
| |
| |
Function Parameters | |
| |
| |
| |
Syntax and Semantics of Void Functions | |
| |
| |
Function Call (Invocation) | |
| |
| |
Function Declarations and Definitions | |
| |
| |
Local Variables | |
| |
| |
The Return Statement | |
| |
| |
Header Files | |
| |
| |
| |
Parameters | |
| |
| |
Value Parameters | |
| |
| |
Reference Parameters | |
| |
| |
| |
Designing Functions | |
| |
| |
Writing Assertions as Program Comments | |
| |
| |
Documenting the Direction of Data Flow | |
| |
| |
Programming Example: Comparison of Furniture-Store Sales | |
| |
| |
Testing and Debugging | |
| |
| |
The assert Library Function | |
| |
| |
Testing and Debugging Hints | |
| |
| |
Summary | |
| |
| |
Quick Check | |
| |
| |
Exam Preparation Exercises | |
| |
| |
Programming Warm-up Exercises | |
| |
| |
Programming Problems | |
| |
| |
| |
Scope, Lifetime, and More on Functions | |
| |
| |
| |
Scope of Identifiers | |
| |
| |
Scope Rules | |
| |
| |
Variable Declarations and Definitions | |
| |
| |
Namespaces | |
| |
| |
| |
Lifetime of a Variable | |
| |
| |
Initializations in Declarations | |
| |
| |
| |
Interface Design | |
| |
| |
Side Effects | |
| |
| |
Global Constants | |
| |
| |
| |
Value-Returning Functions | |
| |
| |
Boolean Functions | |
| |
| |
Interface Design for Value-Returning Functions | |
| |
| |
When to Use Value-Returning Functions | |
| |
| |
Programming Example: Starship Weight and Balance | |
| |
| |
Testing and Debugging | |
| |
| |
Stubs and Drivers | |
| |
| |
Testing and Debugging Hints | |
| |
| |
Summary | |
| |
| |
Quick Check | |
| |
| |
Exam Preparation Exercises | |
| |
| |
Programming Warm-up Exercises | |
| |
| |
Programming Problems | |
| |
| |
| |
Additional Control Structures | |
| |
| |
| |
The Switch Statement | |
| |
| |
| |
The Do-While Statement | |
| |
| |
| |
The For Statement | |
| |
| |
| |
The Break and Continue Statements | |
| |
| |
| |
Guidelines for Choosing a Looping Statement | |
| |
| |
Programming Example: Monthly Rainfall Averages | |
| |
| |
Testing and Debugging | |
| |
| |
Testing and Debugging Hints | |
| |
| |
Summary | |
| |
| |
Quick Check | |
| |
| |
Exam Preparation Exercises | |
| |
| |
Programming Warm-up Exercises | |
| |
| |
Programming Problems | |
| |
| |
| |
Simple Data Types: Built-In and User-Defined | |
| |
| |
| |
Built-In Simple Types | |
| |
| |
Integral Types | |
| |
| |
Floating-Point Types | |
| |
| |
| |
Additional C++ Operators | |
| |
| |
Assignment Operators and Assignment Expressions | |
| |
| |
Increment and Decrement Operators | |
| |
| |
Bitwise Operators | |
| |
| |
The Cast Operation | |
| |
| |
The sizeof Operator | |
| |
| |
The?: Operator | |
| |
| |
Operator Precedence | |
| |
| |
| |
Working with Character Data | |
| |
| |
Character Sets | |
| |
| |
C++ char Constants | |
| |
| |
Programming Techniques | |
| |
| |
| |
More on Floating-Point Numbers | |
| |
| |
Representation of Floating-Point Numbers | |
| |
| |
Arithmetic with Floating-Point Numbers | |
| |
| |
| |
User-Defined Simple Types | |
| |
| |
The Typedef Statement | |
| |
| |
Enumeration Types | |
| |
| |
Named and Anonymous Data Types | |
| |
| |
User-Written Header Files | |
| |
| |
| |
More on Type Coercion | |
| |
| |
Type Coercion in Arithmetic and Relational Expressions | |
| |
| |
Type Coercion in Assignments, Argument Passing, and Return of a Function Value | |
| |
| |
Programming Example: Rock, Paper, Scissors | |
| |
| |
Testing and Debugging | |
| |
| |
Floating-Point Data | |
| |
| |
Coping with Input Errors | |
| |
| |
Testing and Debugging Hints | |
| |
| |
Summary | |
| |
| |
Quick Check | |
| |
| |
Exam Preparation Exercises | |
| |
| |
Programming Warm-up Exercises | |
| |
| |
Programming Problems | |
| |
| |
| |
Structured Types, Data Abstraction, and Classes | |
| |
| |
| |
Simple Versus Structured Data Types | |
| |
| |
| |
Records (C++ Structs) | |
| |
| |
Accessing Individual Components | |
| |
| |
Aggregate Operations on Structs | |
| |
| |
More About Struct Declarations | |
| |
| |
Hierarchical Records | |
| |
| |
| |
Unions | |
| |
| |
| |
Data Abstraction | |
| |
| |
| |
Abstract Data Types | |
| |
| |
| |
C++ Classes | |
| |
| |
Classes, Class Objects, and Class Members | |
| |
| |
Built-in Operations on Class Objects | |
| |
| |
Class Scope | |
| |
| |
Information Hiding | |
| |
| |
| |
Specification and Implementation Files | |
| |
| |
The Specification File | |
| |
| |
The Implementation File | |
| |
| |
Compiling and Linking a Multifile Program | |
| |
| |
| |
Guaranteed Initialization with Class Constructors | |
| |
| |
Invoking a Constructor | |
| |
| |
Revised Specification and Implementation Files for TimeType | |
| |
| |
Guidelines for Using Class Constructors | |
| |
| |
Programming Example: Manipulating Dates | |
| |
| |
Programming Example: Birthday Calls | |
| |
| |
Testing and Debugging | |
| |
| |
Testing and Debugging Hints | |
| |
| |
Summary | |
| |
| |
Quick Check | |
| |
| |
Exam Preparation Exercises | |
| |
| |
Programming Warm-up Exercises | |
| |
| |
Programming Problems | |
| |
| |
| |
Arrays | |
| |
| |
| |
One-Dimensional Arrays | |
| |
| |
Declaring Arrays | |
| |
| |
Accessing Individual Components | |
| |
| |
Out-of-Bounds Array Indexes | |
| |
| |
Initializing Arrays in Declarations | |
| |
| |
(Lack of) Aggregate Array Operations | |
| |
| |
Examples of Declaring and Accessing Arrays | |
| |
| |
Passing Arrays as Arguments | |
| |
| |
Assertions About Arrays | |
| |
| |
Using Typedef with Arrays | |
| |
| |
| |
Arrays of Records and Class Objects | |
| |
| |
Arrays of Records | |
| |
| |
Arrays of Class Objects | |
| |
| |
| |
Special Kinds of Array Processing | |
| |
| |
Subarray Processing | |
| |
| |
Indexes with Semantic Content | |
| |
| |
| |
Two-Dimensional Arrays | |
| |
| |
| |
Processing Two-Dimensional Arrays | |
| |
| |
Sum the Rows | |
| |
| |
Sum the Columns | |
| |
| |
Initialize the Array | |
| |
| |
Print the Array | |
| |
| |
| |
Passing Two-Dimensional Arrays as Arguments | |
| |
| |
| |
Another Way of Defining Two-Dimensional Arrays | |
| |
| |
| |
Multidimensional Arrays | |
| |
| |
Programming Example: Comparison of Two Lists | |
| |
| |
Programming Example: City Council Election | |
| |
| |
Testing and Debugging | |
| |
| |
One-Dimensional Arrays | |
| |
| |
Complex Structures | |
| |
| |
Multidimensional Arrays | |
| |
| |
Testing and Debugging Hints | |
| |
| |
Summary | |
| |
| |
Quick Check | |
| |
| |
Exam Preparation Exercises | |
| |
| |
Programming Warm-up Exercises | |
| |
| |
Programming Problems | |
| |
| |
| |
Array-Based Lists | |
| |
| |
| |
The List as an Abstract Data Type | |
| |
| |
| |
Unsorted Lists | |
| |
| |
Basic Operations | |
| |
| |
Insertion and Deletion | |
| |
| |
Sequential Search | |
| |
| |
Sorting | |
| |
| |
| |
Sorted Lists | |
| |
| |
Basic Operations | |
| |
| |
Insertion | |
| |
| |
Sequential Search | |
| |
| |
Binary Search | |
| |
| |
Deletion | |
| |
| |
| |
Understanding Character Strings | |
| |
| |
Initializing C Strings | |
| |
| |
C String Input and Output | |
| |
| |
C String Library Routines | |
| |
| |
String Class or C Strings? | |
| |
| |
Programming Example: Exam Attendance | |
| |
| |
Testing and Debugging | |
| |
| |
Testing and Debugging Hints | |
| |
| |
Summary | |
| |
| |
Quick Check | |
| |
| |
Exam Preparation Exercises | |
| |
| |
Programming Warm-up Exercises | |
| |
| |
Programming Problems | |
| |
| |
| |
Object-Oriented Software Development | |
| |
| |
| |
Object-Oriented Programming | |
| |
| |
| |
Objects | |
| |
| |
| |
Inheritance | |
| |
| |
Deriving One Class from Another | |
| |
| |
Specification of the ExtTime Class | |
| |
| |
Implementation of the ExtTime Class | |
| |
| |
Avoiding Multiple Inclusion of Header Files | |
| |
| |
| |
Composition | |
| |
| |
Design of a TimeCard Class | |
| |
| |
Implementation of the TimeCard Class | |
| |
| |
| |
Dynamic Binding and Virtual Functions | |
| |
| |
The Slicing Problem | |
| |
| |
Virtual Functions | |
| |
| |
| |
Object-Oriented Design | |
| |
| |
| |
Identify the Objects and Operations | |
| |
| |
| |
Determine the Relationships Among Objects | |
| |
| |
| |
Design the Driver | |
| |
| |
| |
Implementing the Design | |
| |
| |
Programming Example: Time Card Lookup | |
| |
| |
Testing and Debugging | |
| |
| |
Testing and Debugging Hints | |
| |
| |
Summary | |
| |
| |
Quick Check | |
| |
| |
Exam Preparation Exercises | |
| |
| |
Programming Warm-up Exercises | |
| |
| |
Programming Problems | |
| |
| |
| |
Recursion | |
| |
| |
| |
What Is Recursion? | |
| |
| |
| |
Towers of Hanoi | |
| |
| |
| |
Recursive Algorithms with Structured Variables | |
| |
| |
| |
Recursion or Iteration? | |
| |
| |
Testing and Debugging | |
| |
| |
Testing and Debugging Hints | |
| |
| |
Summary | |
| |
| |
Quick Check | |
| |
| |
Exam Preparation Exercises | |
| |
| |
Programming Warm-up Exercises | |
| |
| |
Programming Problems | |
| |
| |
| |
Reserved Words | |
| |
| |
| |
Operator Precedence | |
| |
| |
| |
A Selection of Standard Library Routines | |
| |
| |
| |
Using This Book with a Prestandard Version of C++ | |
| |
| |
| |
Character Sets | |
| |
| |
| |
Program Style, Formatting, and Documentation | |
| |
| |
Glossary | |
| |
| |
Answers to Selected Exercises | |
| |
| |
Index | |