CONTENTS
1 - INTRODUCTION TO COMPUTERS AND PROGRAMMING = 1
1.1 Electronic Computers : Then and Now = 2
1.2 Components of a Computer = 7
1.3 Problem-Solving, Abstraction, and Program Engineering = 12
1.4 Programming Languages = 14
1.5 Processing a High-Level Language Program = 18
1.6 Using the Computer = 20
Chapter Review = 26
2 - PROGRAM DESIGN = 29
2.1 The Software Development Method = 30
CASE STUDY : Converting Units of Measurement = 34
2.2 Overview of C++ = 37
2.3 Declarations of Variables and Constants = 41
2.4 Executable Statements = 44
2.5 Recapitulation : The General Form of a C++ Program = 52
2.6 Abstraction : Data Types and Expressions = 56
CASE STUDY : Finding the Value of a Coin Collection = 59
2.7 Interactive Mode, Batch Mode, and Data Files = 71
2.8 Common Programming Errors = 74
Chapter Review = 80
3 - TOP-DOWN DESIGN = 85
3.1 Problem-Solving and Program Development = 86
CASE STUDY : Finding the Area and Circumference of a Circle = 89
3.2 Subproblems and Independent Modules = 93
CASE STUDY : Drawing Simple Figures = 93
3.3 Functions without Arguments = 96
3.4 Functions with Input Arguments and Return Values = 108
3.5 How We Use Functions = 111
3.6 Functions as Program Building Blocks ; C++ Libraries = 124
3.7 Some Comments on the Software Engineering Process = 132
3.8 Common Programming Errors = 132
Chapter Review = 136
4 - SELECTION STRUCTURES : if AND switch STATEMENTS = 141
4.1 Control Structures = 142
4.2 Logical Expressions = 143
4.3 Introduction to the if Control Statement = 151
4.4 if Statements with Compound Alternatives = 155
4.5 Decision Steps in Algorithms = 158
CASE STUDY : Payroll Problem = 158
4.6 Formatted Output : Introduction to Manipulators and Flags = 165
4.7 Checking Correctness of an Algorithm = 169
CASE STUDY : Finding the Alphabetically First Letter = 169
4.8 More Problems-Solving Strategies = 173
CASE STUDY : Computing Overtime Pay = 174
CASE STUDY : Computing Insurance Dividends = 177
4.9 Nested if Statements and Multiple-Alternative Decisions = 182
4.10 The switch Control Statement = 189
4.11 Common Programming Errors = 194
Chapter Review = 195
5 - REPETITION : while, for, AND do-while STATEMENTS = 203
5.1 Repetition in Programs :The while Statement = 204
5.2 Accumulating a Sum or Product in a Loop = 209
5.3 Counting Loops and Conditional Loops = 215
5.4 Loop Design = 218
5.5 The for Statement = 227
5.6 More for Statement Examples = 233
5.7 The do-while Statement = 237
5.8 Review of while, for, and do-while Loops = 240
5.9 Nested Loops = 242
5.10 Debugging and Testing Programs = 246
5.11 Common Programming Errors = 249
Chapter Review = 251
6 - PROGRAM DESIGN AND FUNCTIONS REVISITED = 259
6.1 Functions in the Design Process = 260
6.2 Using Function Return Values for Decision and Loop Control = 26?????
6.3 Output Arguments = 269
CASE STUDY : Sorting Three Numbers = 277
6.4 Syntax Rules for Functions with Argument Lists = 283
6.5 Stepwise Design with Functions = 287
CASE STUDY : General Sum and Average Problem = 287
6.6 Solving a More Complex Problem = 302
CASE STUDY : Checking Account Balance Problem = 303
6.7 More Aspects of Software Engineering = 316
6.8 Debugging and Testing a Program System = 318
6.9 Common Programming Errors = 320
Chapter Review = 321
7 - SIMPLE DATA TYPES = 329
7.1 Constants Revisited = 330
7.2 Internal representations of Integer, Floating-Point, and Character Data Types = 332
7.3 Logical Expressions = 346
7.4 Character Variables and Functions = 348
7.5 Enumeration Types = 353
7.6 Common Programming Errors = 362
Chapter Review = 365
8 - FORMATTING AND FILES = 371
8.1 The Standard Input / Output Streams = 372
8.2 Streams and External Files = 381
8.3 Accessing and Using External Files = 382
8.4 Using External File Functions : An Example = 391
CASE STUDY : Preparing a Payroll File = 391
8.5 Putting It All Together = 398
CASE STUDY : Preparing Semester Grade Reports = 398
8.6 Stream I/O Manipulator Functions and Flags = 422
8.7 Common Programming Errors = 424
Chapter Review = 426
9 - ARRAYS AND STRUCTURES = 433
9.1 The Array Data Type = 434
9.2 Selecting Array Elements for Processing = 439
9.3 Arrays as Arguments = 444
9.4 Reading Part of an Array = 452
9.5 Searching and Sorting Arrays = 456
9.6 Character Strings = 463
9.7 The struct Data Type = 473
9.8 Structs as Operands and Arguments = 476
9.9 Hierarchical Structs = 480
9.10 Unions (Optional) = 483
9.11 Common Programming Errors = 487
Chapter Review = 489
10 - INTRODUCTION TO SOFTWARE ENGINEERING = 497
10.1 The Software Challenge = 498
10.2 The Software Life Cycle = 500
CASE STUDY : Telephone Directory Program = 504
10.3 Procedural Abstraction Revisited = 507
10.4 Data Abstraction and Abstract Data Types : Program Objects = 511
10.5 Analysis of Algorithm Efficiency : Big-O Notation = 516
10.6 Software Testing = 519
10.7 Formal Methods of Program Verification = 522
10.8 Professional Ethics and Responsibilities = 530
Chapter Review = 531
11 - DATA ABSTRACTION IN C++ : THE C++ CLASS = 537
11.1 The C++ Class = 538
11.2 Classes versus Structs = 547
11.3 The Abstract Data Type day = 548
11.4 Automatic Initialization :Class Constructors = 553
11.5 Problem Analysis and Design Using Classes = 555
CASE STUDY : Areas and Perimeters of Different Figures Revisited = 555
11.6 A Complex Number Class (Optional) = 566
11.7 Defining and Using Functions and Classes : Summary of Rules and Restrictions = 573
11.8 Common Programming Errors = 576
Chapter Review = 578
12 - SOFTWARE ENGINEERING : BUILDING ABSTRACT DATA TYPES = 585
12.1 The Indexed Collection as an Abstract Data Type = 587
12.2 Class Extensions : An Introduction to Inheritance = 596
CASE STUDY : Home Budget Problem = 596
12.3 Extending Reuse : An Introduction to Templates = 611
12.4 Using Old Components to Solve New Problems = 618
CASE STUDY : Cryptogram Generator Problem = 625
12.5 Common Programming Errors = 637
Chapter Review = 640
13 - THE STRING DATA TYPE = 649
13.1 String Functions in the string.h Library = 650
13.2 An Illustration of Character String Processing = 663
CASE STUDY : Printing a Form Letter = 663
13.3 Variable-Length Strings (Optional) = 676
13.4 Common Programming Errors = 685
Chapter Review = 688
14 - ARRAYS WITH STRUCTURED ELEMENTS = 697
14.1 Arrays of Arrays : Multidimensional Arrays = 698
14.2 Creating Arrays of Arrays = 700
14.3 Arrays of Structs = 703
14.4 Arrays of Class Elements = 706
14.5 Abstraction and Generalization : Triangle and Polygon Classes = 708
14.6 Modeling the Triangle : Illustrating Alternative Approaches = 709
14.7 Design and Use of Abstract Data Types = 727
CASE STUDY : Assigning Final Grades for a Semester = 727
14.8 Common Programming Errors = 746
Chapter Review = 747
15 - RECURSION = 755
15.1 The Nature of Recursion = 756
15.2 Tracing Recursive Functions = 761
15.3 Recursive Mathematical Functions = 767
15.4 Recursive Functions with Array Arguments = 773
CASE STUDY : Recursive Selection Sort = 773
15.5 Problem-Solving with Recursion = 776
CASE STUDY : Towers of Hanoi Problem = 776
15.6 Picture-Processing with Recursion = 780
CASE STUDY : Counting Cells in a Blob = 780
15.7 Common Programming Errors = 784
Chapter Review = 785
16 - DYNAMIC DATA STRUCTURES = 791
16.1 Review of Pointers and the new Operator = 792
16.2 Manipulating the Heap = 799
16.3 Linked Lists = 801
16.4 The Stack as an Abstract Data Type = 809
CASE STUDY : Evaluating Postfix Expressions = 813
16.5 Implementing a Stack Using an Array = 820
16.6 Linked-List Representation of a Stack = 824
16.7 The Queue Abstract Data Type = 830
16.8 Queue Application = 833
CASE STUDY : Maintaining a Queue of Passengers = 833
16.9 Implementing a Queue Using an Array = 841
16.10 Linked-List Representation of a Queue = 846
16.11 Common Programming Errors = 850
Chapter Review = 852
APPENDIXES
A Character Sets = 861
B Reserved Worlds and Special Characters = 863
C Selected C++ Library Facilities = 864
D Operators = 869
E A Brief Introduction to Inheritance and Polymorphism = 871
ANSWERS A-1
INDEX I-1