Starting Out with C++ From Control Structures through Objects plus MyProgrammingLab with Pearso...

Why Rent from Knetbooks?

Because Knetbooks knows college students. Our rental program is designed to save you time and money. Whether you need a textbook for a semester, quarter or even a summer session, we have an option for you. Simply select a rental period, enter your information and your book will be on its way!

This package contains Starting Out with C++: From Control Structures through Objects, 7e & MyProgrammingLab with Pearson eText Student Access Code Card for Starting Out with C++: From Control Structures through Objects, 7e. In Starting Out with C++: From Control Structures through Objects,Gaddis covers control structures, functions, arrays, and pointers before objects and classes. 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. MyProgrammingLabis a database of programming exercises correlated to specific Pearson CS1/Intro to Programming textbooks. The exercises are short, focused on a particular programming topic, and are assignable and automatically evaluated. MyProgrammingLab provides immediate, personalized feedback which helps students master the syntax, semantics and basic usage of the programming language, freeing instructors to focus on problem-solving strategies, design and analysis, abstraction, algorithms, and style. Learn more atwww.myprogramminglab.com.

Tony Gaddis is the lead author of the Starting Out with series including Starting Out with Alice, C++, Java™, Visual Basic® 2010 and 2008, Programming Logic & Design, and Python. Visit the Gaddis Books website for more information on Gaddis’ titles. Gaddis teaches computer science courses at Haywood Community College in North Carolina. He previously taught programming for several corporations and government agencies, including NASA's Kennedy Space Center. Gaddis is a highly acclaimed instructor who was selected as the North Carolina Community College "Teacher of the Year" in 1994, and who received the Teaching Excellence award from the National Institute for Staff and Organizational Development in 1997.

<>Contents

Preface xiii

CHAPTER 1 Introduction to Computers and Programming 1

1.1 Why Program? 1

1.2 Computer Systems: Hardware and Software 3

1.3 Programs and Programming Languages 8

1.4 What Is a Program Made of? 13

1.5 Input, Processing, and Output 17

1.6 The Programming Process 18

1.7 Procedural and Object-Oriented Programming 22

CHAPTER 2 Introduction to C++ 27

2.1 The Parts of a C++ Program 27

2.2 The cout Object 31

2.3 The #include Directive 36

2.4 Variables and Literals 37

2.5 Identifiers 41

2.6 Integer Data Types 42

2.7 The char Data Type 47

2.8 The C++ string Class 51

2.9 Floating-Point Data Types 53

2.10 The bool Data Type 56

2.11 Determining the Size of a Data Type 57

2.12 Variable Assignments and Initialization 58

2.13 Scope 59

2.14 Arithmetic Operators 60

2.15 Comments 68

2.16 Named Constants 70

2.17 Programming Style 72

2.18 If You Plan to Continue in Computer Science: Standard and Prestandard C++ 74

CHAPTER 3 Expressions and Interactivity 85

3.1 The cin Object 85

3.2 Mathematical Expressions 91

3.3 When You Mix Apples and Oranges: Type Conversion 100

3.4 Overflow and Underflow 102

3.5 Type Casting 103

3.6 Multiple Assignment and Combined Assignment 107

3.7 Formatting Output 111

3.8 Working with Characters and string Objects 120

3.9 More Mathematical Library Functions 127

3.10 Focus on Debugging: Hand Tracing a Program 130

3.11 Focus on Problem Solving: A Case Study 132

CHAPTER 4 Making Decisions 149

4.1 Relational Operators 149

4.2 The if Statement 154

4.3 Expanding the if Statement 162

4.4 The if/else Statement 166

4.5 Nested if Statements 169

4.6 The if/else if Statement 176

4.7 Flags 181

4.8 Logical Operators 182

4.9 Checking Numeric Ranges with Logical Operators 189

4.10 Menus 190

4.11 Focus on Software Engineering: Validating User Input 193

4.12 Comparing Characters and Strings 195

4.13 The Conditional Operator 199

4.14 The switch Statement 202

4.15 More About Blocks and Scope 211

CHAPTER 5 Loops and Files 227

5.1 The Increment and Decrement Operators 227

5.2 Introduction to Loops: The while Loop 232

5.3 Using the while Loop for Input Validation 239

5.4 Counters 241

5.5 The do-while Loop 242

5.6 The for Loop 247

5.7 Keeping a Running Total 257

5.8 Sentinels 260

5.9 Focus on Software Engineering: Deciding Which Loop to Use 261

5.10 Nested Loops 262

5.11 Using Files for Data Storage 265

5.12 Optional Topics: Breaking and Continuing a Loop 285

CHAPTER 6 Functions 301

6.1 Focus on Software Engineering: Modular Programming 301

6.2 Defining and Calling Functions 303

6.3 Function Prototypes 311

6.4 Sending Data into a Function 313

6.5 Passing Data by Value 318

6.6 Focus on Software Engineering: Using Functions in a Menu-Driven Program 320

6.7 The return Statement 324

6.8 Returning a Value from a Function 326

6.9 Returning a Boolean Value 334

6.10 Local and Global Variables 336

6.11 Static Local Variables 344

6.12 Default Arguments 347

6.13 Using Reference Variables as Parameters 350

6.14 Overloading Functions 356

6.15 The exit() Function 360

6.16 Stubs and Drivers 363

CHAPTER 7 Arrays 377

7.1 Arrays Hold Multiple Values 377

7.2 Accessing Array Elements 379

7.3 No Bounds Checking in C++ 386

7.4 Array Initialization 389

7.5 Processing Array Contents 394

7.6 Focus on Software Engineering: Using Parallel Arrays 402

7.7 Arrays as Function Arguments 405

7.8 Two-Dimensional Arrays 416

7.9 Arrays with Three or More Dimensions 423

7.10 Focus on Problem Solving and Program Design: A Case Study 424

7.11 If You Plan to Continue in Computer Science: Introduction to the STL vector 427