Tony Gaddis’s accessible, step-by-step presentation helps beginning students understand the important details necessary to become skilled programmers at an introductory level. Gaddis motivates the study of both programming skills and the C++ programming language by presenting all the details needed to understand the “how” and the “why”—but never losing sight of the fact that most beginners struggle with this material. His approach is both gradual and highly accessible, ensuring that students understand the logic behind developing high-quality programs.In Starting Out with C++: Early Objects, Gaddis covers objects and classes early after functions and before arrays and pointers. As with all Gaddis texts, clear and easy-to-read code listings, concise and practical real-world examples, and an abundance of exercises appear in every chapter. This text is intended for either a one-semester accelerated introductory course or a traditional two-semester sequence covering C++ programming.
Author(s): Tony Gaddis, Judy Walters, Godfrey Muganda
Edition: 7th Edition
Publisher: Addison Wesley
Year: 2010
Language: English
Pages: 1198
Cover ......Page 1
Title Page ......Page 4
Copyright ......Page 5
Contents......Page 8
Preface......Page 16
1.1 Why Program?......Page 30
1.2 Computer Systems: Hardware and Software......Page 31
1.3 Programs and Programming Languages......Page 35
1.4 What Is a Program Made of?......Page 41
1.5 Input, Processing, and Output......Page 45
1.6 The Programming Process......Page 46
1.7 Tying It All Together: Hi! It’s Me......Page 51
2.1 The Parts of a C++ Program......Page 56
2.2 The cout Object......Page 60
2.3 The #include Directive......Page 64
2.5 Variables, Constants, and the Assignment Statement......Page 66
2.6 Identifiers......Page 70
2.7 Integer Data Types......Page 72
2.8 The char Data Type......Page 77
2.9 The C++ string Class......Page 81
2.10 Floating-Point Data Types......Page 83
2.11 The bool Data Type......Page 86
2.12 Determining the Size of a Data Type......Page 87
2.13 More on Variable Assignments and Initialization......Page 88
2.14 Scope......Page 89
2.15 Arithmetic Operators......Page 90
2.16 Comments......Page 93
2.17 Focus on Software Engineering: Programming Style......Page 94
2.18 Tying It All Together: Smile!......Page 96
3.1 The cin Object......Page 104
3.2 Mathematical Expressions......Page 110
3.3 Implicit Type Conversion......Page 118
3.4 Explicit Type Conversion......Page 119
3.5 Overflow and Underflow......Page 123
3.6 Named Constants......Page 126
3.7 Multiple and Combined Assignment......Page 130
3.8 Formatting Output......Page 134
3.9 Working with Characters and String Objects......Page 144
3.10 Using C-Strings......Page 149
3.11 More Mathematical Library Functions......Page 155
3.12 Introduction to Files......Page 159
3.13 Focus on Debugging: Hand Tracing a Program......Page 167
3.14 Green Fields Landscaping Case Study—Part 1......Page 169
3.15 Tying It All Together: Word Game......Page 171
4.1 Relational Operators......Page 186
4.2 The if Statement......Page 191
4.3 The if/else Statement......Page 201
4.4 The if/else if Statement......Page 204
4.5 Menu-Driven Programs......Page 210
4.6 Nested if Statements......Page 212
4.7 Logical Operators......Page 216
4.8 Validating User Input......Page 225
4.9 More About Variable Definitions and Scope......Page 226
4.10 Comparing Characters and Strings......Page 231
4.11 The Conditional Operator......Page 235
4.12 The switch Statement......Page 239
4.13 Enumerated Data Types......Page 248
4.14 Testing for File Open Errors......Page 251
4.15 Focus on Testing and Debugging: Validating Output Results......Page 252
4.16 Green Fields Landscaping Case Study—Part 2......Page 254
4.17 Tying It All Together: Fortune Teller......Page 258
5.1 The Increment and Decrement Operators......Page 272
5.2 Introduction to Loops: The while Loop......Page 278
5.3 Using the while Loop for Input Validation......Page 282
5.4 Counters......Page 285
5.5 The do-while Loop......Page 287
5.6 The for Loop......Page 292
5.7 Keeping a Running Total......Page 298
5.8 Sentinels......Page 300
5.9 Using a Loop to Read Data from a File......Page 302
5.10 Focus on Software Engineering: Deciding Which Loop to Use......Page 305
5.11 Nested Loops......Page 306
5.12 Breaking Out of a Loop......Page 308
5.13 The continue Statement......Page 310
5.14 Focus on Testing and Debugging: Creating Good Test Data......Page 313
5.15 Central Mountain Credit Union Case Study......Page 316
5.16 Tying It All Together: What a Colorful World......Page 320
6.1 Modular Programming......Page 334
6.2 Defining and Calling Functions......Page 335
6.3 Function Prototypes......Page 343
6.4 Sending Data into a Function......Page 345
6.5 Passing Data by Value......Page 350
6.6 The return Statement......Page 354
6.7 Returning a Value from a Function......Page 355
6.8 Returning a Boolean Value......Page 361
6.9 Using Functions in a Menu-Driven Program......Page 363
6.10 Local and Global Variables......Page 366
6.11 Static Local Variables......Page 373
6.12 Default Arguments......Page 376
6.13 Using Reference Variables as Parameters......Page 379
6.14 Overloading Functions......Page 388
6.15 The exit ( ) Function......Page 392
6.16 Stubs and Drivers......Page 395
6.17 Little Lotto Case Study......Page 397
6.18 Tying It All Together: Glowing Jack-o-lantern......Page 402
7.1 Abstract Data Types......Page 416
7.2 Object-Oriented Programming......Page 418
7.3 Introduction to Classes......Page 420
7.4 Introduction to Objects......Page 422
7.5 Defining Member Functions......Page 424
7.6 Constructors......Page 431
7.7 Destructors......Page 436
7.8 Private Member Functions......Page 439
7.9 Passing Objects to Functions......Page 442
7.10 Object Composition......Page 449
7.11 Focus on Software Engineering: Separating Class Specification, Implementation, and Client Code......Page 453
7.12 Input Validation Objects......Page 460
7.13 Structures......Page 464
7.14 Home Software Company OOP Case Study......Page 478
7.15 Introduction to Object-Oriented Analysis and Design......Page 484
7.16 Screen Control......Page 493
7.17 Tying It All Together: Yoyo Animation......Page 498
8.1 Arrays Hold Multiple Values......Page 514
8.2 Accessing Array Elements......Page 516
8.3 Inputting and Displaying Array Contents......Page 518
8.4 Array Initialization......Page 525
8.5 Processing Array Contents......Page 531
8.6 Using Parallel Arrays......Page 542
8.7 The typedef Statement......Page 545
8.8 Arrays as Function Arguments......Page 546
8.9 Two-Dimensional Arrays......Page 555
8.10 Arrays with Three or More Dimensions......Page 563
8.11 Vectors......Page 566
8.12 Arrays of Class Objects......Page 578
8.13 National Commerce Bank Case Study......Page 588
8.14 Tying It All Together: Rock, Paper, Scissors......Page 590
9.1 Introduction to Search Algorithms......Page 606
9.2 Searching an Array of Objects......Page 613
9.3 Introduction to Sorting Algorithms......Page 616
9.4 Sorting an Array of Objects......Page 625
9.5 Sorting and Searching Vectors......Page 628
9.6 Introduction to Analysis of Algorithms......Page 630
9.7 Case Studies......Page 638
9.8 Tying It All Together: Secret Messages......Page 639
10.1 Pointers and the Address Operator......Page 648
10.2 Pointer Variables......Page 650
10.3 The Relationship Between Arrays and Pointers......Page 654
10.4 Pointer Arithmetic......Page 658
10.5 Initializing Pointers......Page 659
10.6 Comparing Pointers......Page 661
10.7 Pointers as Function Parameters......Page 664
10.8 Pointers to Constants and Constant Pointers......Page 668
10.9 Focus on Software Engineering: Dynamic Memory Allocation......Page 672
10.10 Focus on Software Engineering: Returning Pointers from Functions......Page 677
10.11 Pointers to Class Objects and Structures......Page 681
10.12 Focus on Software Engineering: Selecting Members of Objects......Page 688
10.13 United Cause Relief Agency Case Study......Page 690
10.14 Tying It All Together: Pardon Me, Do You Have the Time?......Page 698
11.1 The this Pointer and Constant Member Functions......Page 706
11.2 Static Members......Page 710
11.3 Friends of Classes......Page 718
11.4 Memberwise Assignment......Page 723
11.5 Copy Constructors......Page 724
11.6 Operator Overloading......Page 733
11.7 Type Conversion Operators......Page 757
11.8 Convert Constructors......Page 760
11.9 Aggregation and Composition......Page 763
11.10 Inheritance......Page 769
11.11 Protected Members and Class Access......Page 774
11.12 Constructors, Destructors, and Inheritance......Page 779
11.13 Overriding Base Class Functions......Page 784
11.14 Tying It All Together: Putting Data on the World Wide Web......Page 786
12.1 C-Strings......Page 800
12.2 Library Functions for Working with C-Strings......Page 805
12.3 Conversions Between Numbers and Strings......Page 816
12.4 Character Testing......Page 822
12.5 Character Case Conversion......Page 826
12.6 Writing Your Own C-String Handling Functions......Page 829
12.7 More About the C++ string Class......Page 834
12.8 Creating Your Own String Class......Page 839
12.9 Advanced Software Enterprises Case Study......Page 846
12.10 Tying It All Together: Program Execution Environments......Page 848
13.1 Files......Page 858
13.2 Output Formatting......Page 867
13.3 Passing File Stream Objects to Functions......Page 874
13.4 More Detailed Error Testing......Page 876
13.5 Member Functions for Reading and Writing Files......Page 878
13.6 Binary Files......Page 891
13.7 Creating Records with Structures......Page 895
13.8 Random-Access Files......Page 900
13.9 Opening a File for Both Input and Output......Page 907
13.10 Online Friendship Connections Case Study......Page 912
13.11 Tying It All Together: File Merging and Color-Coded HTML......Page 917
14.1 Introduction to Recursion......Page 930
14.2 The Recursive Factorial Function......Page 937
14.3 The Recursive gcd Function......Page 939
14.4 Solving Recursively Defined Problems......Page 940
14.5 A Recursive Binary Search Function......Page 942
14.6 Focus on Problem Solving and Program Design: The QuickSort Algorithm......Page 944
14.7 The Towers of Hanoi......Page 948
14.8 Focus on Problem Solving: Exhaustive and Enumeration Algorithms......Page 951
14.9 Focus on Software Engineering: Recursion Versus Iteration......Page 955
14.10 Tying It All Together: Infix and Prefix Expressions......Page 956
15.1 Type Compatibility in Inheritance Hierarchies......Page 964
15.2 Polymorphism and Virtual Member Functions......Page 970
15.3 Abstract Base Classes and Pure Virtual Functions......Page 975
15.4 Focus on Object-Oriented Programming: Composition Versus Inheritance......Page 981
15.5 Secure Encryption Systems, Inc., Case Study......Page 986
15.6 Tying It All Together: Let’s Move It......Page 990
16.1 Exceptions......Page 1002
16.2 Function Templates......Page 1014
16.3 Class Templates......Page 1022
16.4 Class Templates and Inheritance......Page 1028
16.5 Introduction to the Standard Template Library......Page 1031
16.6 Tying It All Together: Word Transformers Game......Page 1044
17.1 Introduction to the Linked List ADT......Page 1052
17.2 Linked List Operations......Page 1058
17.3 A Linked List Template......Page 1070
17.4 Recursive Linked List Operations......Page 1074
17.6 The STL list Container......Page 1083
17.7 Reliable Software Systems, Inc., Case Study......Page 1085
17.8 Tying It All Together: More on Graphics and Animation......Page 1089
18.1 Introduction to the Stack ADT......Page 1100
18.2 Dynamic Stacks......Page 1108
18.3 The STL Stack Container......Page 1111
18.4 Introduction to the Queue ADT......Page 1113
18.5 Dynamic Queues......Page 1121
18.6 The STL deque and queue Containers......Page 1125
18.7 Focus on Problem Solving and Program Design: Eliminating Recursion......Page 1127
18.8 Tying It All Together: Converting Postfix Expressions to Infix......Page 1132
19.1 Definition and Applications of Binary Trees......Page 1140
19.2 Binary Search Tree Operations......Page 1144
19.4 Tying It All Together: Genealogy Trees......Page 1160
Appendix A: The ASCII Character Set......Page 1170
Appendix B: Operator Precedence and Associativity......Page 1174
A......Page 1176
B......Page 1178
C......Page 1179
D......Page 1181
E......Page 1182
F......Page 1183
I......Page 1185
L......Page 1187
M......Page 1188
N......Page 1189
O......Page 1190
P......Page 1191
R......Page 1193
S......Page 1194
U......Page 1197
W......Page 1198