logo资料库

Starting Out with C++ Early Objects 9th Edition.pdf

第1页 / 共1274页
第2页 / 共1274页
第3页 / 共1274页
第4页 / 共1274页
第5页 / 共1274页
第6页 / 共1274页
第7页 / 共1274页
第8页 / 共1274页
资料共1274页,剩余部分请下载后查看
Cover
Title Page
Coppyright Page
Contents at a Glance
Contents
Preface
Acknowledgments
About the Authors
Chapter 1 Introduction to Computers and Programming
1.1 Why Program
1.2 Computer Systems: Hardware and Software
1.3 Programs and Programming Languages
1.4 What Is a Program Made Of?
1.5 Input, Processing, and Output
1.6 The Programming Process
1.7 Tying It All Together: Hi! It's Me
Chapter 2 Introduction to C++
2.1 The Parts of a C++ Program
2.2 The count Object
2.3 The #include Directive
2.4 Variables and the Assignment Statement
2.5 Literals
2.6 Identifiers
2.7 Integer Data Types
2.8 Floating-Point Data Tyes
2.9 The char Data Type
2.10 The C++ string Class
2.11 The bool Data Type
2.12 Determining the Size of a Data Type
2.13 More on Variable Assignments and Initialization
2.14 Scope
2.15 Arithmetic Operators
2.16 Comments
2.17 Programming Style
2.18 Tying It All Together: Smile!
Chapter 3 Expressions and Interactivity
3.1 The cin object
3.2 Mathematical Expressions
3.3 Data Types Conversion and Type Casting
3.4 Overflow and Underflow
3.5 Named Constants
3.6 Multiple and Combined Assignment
3.7 Formatting Output
3.8 Working with Characters and Strings
3.9 More Mathematical Library Functions
3.10 Random Numbers
3.11 Focus on Debugging: Hand Tracing a Program
3.12 Green Fields Landscaping Case Study-Part 1
3.13 Tying It All Together: Word Game
Chapter 4 Making Decisions
4.1 Relational Operators
4.2 The if Statement
4.3 The if/else Statement
4.4 The if/else if Statement
4.5 Menu-Driven Programs
4.6 Nested if Statements
4.7 Logical Operators
4.8 Validating User Input
4.9 More about Blocks and Scope
4.10 More about Characters and Strings
4.11 The Conditional Operator
4.12 The switch Statement
4.13 Enumerated Data Types
4.14 Focus on Testing and Debugging: Validating Output Results
4.15 Green Fields Landscaping Case Study-Part 2
4.16 Tying It All Together: Fortune Teller
Chapter 5 Looping
5.1 Introduction to Loops: The while Loop
5.2 Using the while Loop for Input Validation
5.3 The Increment and Decrement Operators
5.4 Counters
5.5 Keeping a Running Total
5.6 Sentinels
5.7 The do-while Loop
5.8 The for Loop
5.9 Focus on Software Engineering: Deciding Which Loop to Use
5.10 Nested Loops
5.11 Breaking Out of a Loop
5.12 Using Files for Data Storage
5.13 Focus on Testing and Debugging: Creating Good Test Data
5.14 Central Mountain Credit Union Case Study
5.15 Tying It All Together: What a Colorful World
Chapter 6 Functions
6.1 Modular Programming
6.2 Defining and Calling Functions
6.3 Function Prototypes
6.4 Sending Data into a Function
6.5 Passing Data by Value
6.6 The return Statement
6.7 Returning a Value from a Function
6.8 Returning a Boolean Value
6.9 Using Functions in a Menu-Driven Program
6.10 Local and Global Variables
6.11 Static Local Values
6.12 Default Arguments
6.13 Using Reference Variables as Parameters
6.14 Overloading Functions
6.15 The exit() Function
6.16 Stubs and Drivers
6.17 Little Lotto Case Study
6.18 Tying It All Together: Glowing Jack-o-lantern
Chapter 7 Introduction to Classes and Objects
7.1 Abstract Data Types
7.2 Object-Oriented Programming
7.3 Introduction to Classes
7.4 Creating and Using Objects
7.5 Defining Member Functions
7.6 Constructors
7.7 Destructors
7.8 Private Member Functions
7.9 Passing Objects to Functions
7.10 Object Composition
7.11 Focus on Software Engineering: Seperating Class Specification, Implementation, and Client Code
7.12 Structures
7.13 More about Enumerated Data Types
7.14 Home Software Company OOP Case Study
7.15 Introduction to Object-Oriented Analysis and Design
7.16 Screen Control
7.17 Tying It All Together: Yoyo Animation
Chapter 8 Arrays
8.1 Arrays Hold Multiple Values
8.2 Accessing Array Elements
8.3 Inputting and Displaying Array Data
8.4 Array Initialization
8.5 The Range-Based for Loop
8.6 Processing Array Contents
8.7 Using Parallel Arrays
8.8 The typedef Statement
8.9 Arrays Function Arguments
8.10 Two-Dimensional Arrays
8.11 Arrays with Three or More Dimensions
8.12 Vectors
8.13 Arrays of Objects
8.14 National Commerce Bank Case Study
8.15 Tying It All Together: Rock, Paper, Scissors
Chapter 9 Searching, Sorting, and Algorithm Analysis
9.1 Introduction to Search Algorithms
9.2 Searching an Array of Objects
9.3 Introduction to Sorting Algorithms
9.4 Sorting an Array of Objects
9.5 Sorting and Searching Vectors
9.6 Introduction to Analysis of Algorithms
9.7 Case Studies
9.8 Tying It All Together: Secret Messages
Chappter 10 Pointers and the Address Oerator
10.1 Pointers and the Address Operator
10.2 Pointer Variables
10.3 The Relationship Between Arrays and Pointers
10.4 Pointer Arithmetic
10.5 Initializing Pointers
10.6 Comparing Pointers
10.7 Pointers as Function Parameters
10.8 Pointers to Constants and Constant Pointers
10.9 Focus on Software Engineering: Dynamic Memory Allocation
10.10 Focus on Software Engineering: Returning Pointers from Functions
10.11 Pointers to Class Objects and Structures
10.12 Focus on Software Engineering: Selecting Members of Objects
10.13 Smart Pointers
10.14 Tying It All Together: Pardon Me, Do You Have the Time?
Chapter 11 More about Classes and Object-Oriented Programming
11.1 The this Pointer and Constant Member Functions
11.2 Static Members
11.3 Friends of Classes
11.4 Memberwise Assignment
11.5 Copy Constructors
11.6 Operator Overloading
11.7 Rvalue References and Move Operations
11.8 Function Objects and Lambda Expressions
11.9 Type Conversion Operators
11.10 Convert Constructors
11.11 Aggregation and Composition
11.12 Inheritance
11.13 Protected Members and Class Access
11.14 Constructors, Destructors, and Inheritance
11.15 Overriding Base Class Functions
11.16 Tying It All Together: Putting Data on the World Wide Web
Chapter 12 More on C-Strings and the string Class
12.1 C-Strings
12.2 Library Functions for Working with C-Strings
12.3 Converstions Between Numbers and Strings
12.4 Writng Your Own C-String Handling Functions
12.5 More about the C++ string Class
12.6 Advanced Software Enterprises Case Study
12.7 Tying It All Together: Program Execution Environments
Chapter 13 Advanced File and I/O Operations
13.1 Input and Output Streams
13.2 More Detailed Error Testing
13.3 Member Functions for Reading and Writing Files
13.4 Binary Files
13.5 Creating Records with Structures
13.6 Random-Access Files
13.7 Opening a File for Both Input and Output
13.8 Online Friendship Connections Case Study: Object Serialization
13.9 Tying It All Together: File Merging and Color-Coded HTML
Chapter 14 Recursion
14.1 Introduction to Recursion
14.2 The Recursive Factorial Function
14.3 The Recursive gcd Function
14.4 Solving Recursively Defined Problems
14.5 A Recursive Binary Search Function
14.6 Focus on Problem Solving and Program Design: The QuickSort Algorithm
14.7 The Towers of Hanoi
14.8 Focus on Problem Solving: Exhaustive and Enumeration Algorithms
14.9 Focus on Software Engineering: Recursion versus Iteration
14.10 Tying It All Together: Infix and Prefix Expressions
Chapter 15 Polymorphism and Virtual Functions
15.1 Type Compatibility in Inheritance Hierarchies
15.2 Polymorphism and Virtual Member Functions
15.3 Abstract Base Classes and Pure Virtual Functions
15.4 Focus on Object-Oriented Programming: Composition versus Inheritance
15.5 Secure Encryption Systems, Inc., Case Study
15.6 Tying It All Together: Let's Move It
Chapter 16 Exceptions, Templates, and the Standard Template Library (STL)
16.1 Exceptions
16.2 Fucntion Templates
16.3 Class Templates
16.4 Class Templates and Inheritance
16.5 Introduction to the Standard Template Library
16.6 Tying It All Together: Word Transformers Game
Chapter 17 Linked Lists
17.1 Introduction to the Linked List ADT
17.2 Linked List Operations
17.3 A Linked List Template*
17.4 Recursive Linked List Operations
17.5 Variations of the Linked List
17.6 The STL list Container*
17.7 Reliable Software Systems, Inc., Case Study
17.8 Tying It All Together: More on Graphics and Animation
Chapter 18 Stacks and Queues
18.1 Introduction to the Stack ADT
18.2 Dynamic Stacks
18.3 The STL stack Container*
18.4 Introduction to the Queue ADT
18.5 Dynamic Queues
18.6 The STL deque and queue Containers*
18.7 Focus on Problem Solving and Program Design: Eliminating Recursion
18.8 Tying It All Together: Converting Postfix Expressions to Infix
Chapter 19 Binary Trees
19.1 Definition and Applications of Binary Trees
19.2 Binary Search Tree Operations
19.3 Template Considerations for Binary Search Trees
19.4 Tying It All Together: Genealogy Trees
Appendix A: The ASCII Character Set
Appendix B: Operator Precedence and Associativity
Appendix C: Answers to Checkpoints
Appendix D: Answers to Odd-Numbered Review Questions
Index
A
B
C
D
E
F
G
H
I
J
K
L
M
N
O
P
Q
R
S
T
U
V
W
start·ng out wi h >>> EARLY OBJECTS T DIT ON
Digital Resources for Students Your new textbook provides 12-month access to digital resources that may include VideoNotes (step-by-step video tutoria ls on programm ing concepts), source code, web chapters, quizzes, and more. Refer to the preface in the textbook for a detailed list of resources. Follow the instructions below to register for the Companion Website for Tony Gaddis, Judy Walters, and Godfrey Muganda's Staring Out with C++: Early Objects, Ninth Edition . I. Go to www.pearso nhighered.com/cs -resources 2. Enter the title of your textboo k or browse by author name. 3. Click Companion Website 4. Click Register and follow the on-screen instructions to create a login name and password . Use a coin to scratch off the coating and reveal your access code. Do not use a sharp knife or other sharp object as it may damage the code. Use the login name and password you created during registration to start using the digital resources that accompany your textboo k. IMPORTANT: This prepaid subscription does not include access to MyProgamminglab, which is available at www.myprog ramm inglab.com for purchase. This access code can only be used once. This subscription is valid for 12 months upon activation and is not transferrable. If the access code has already been revealed it may no longer be valid. If this is the case you can purchase a subscription on the login page for the Companion Website. For tec hnical support go to http://247pea rsoned.cust help.com
This page intentionally left blank
LOCATION OF VIDEONOTES IN THE TEXT ~ VideoNote - - Chapter 1 Chapter 2 Chapter 3 Chapter4 Chapter 5 Chapter6 Chapter 7 Chapter8 Chapter9 Designing a Program with Pseudocode, p. 20 Designing the Account Balance Program, p. 25 Predicting the Output of Problem 30, p. 25 Solving the Candy Bar Sales Problem, p. 26 Using cout to Display Output, p. 32 Assignment Statements, p. 59 Arithmetic Operators, p. 62 Solving the Restaurant Bill Problem, p. 74 Using ci n to Read Input, p. 77 Evaluating Mathematical Expressions, p. 84 Combined Assignment Operators, p. 102 Solving the Stadium Seating Problem, p. 148 Using an if Statement, p. 161 Using an if I else Statement, p. 170 Using an if I else Using Logical Operators, p. 189 Solving the Time Calculator Problem, p. 238 i f Statement, p. 176 The while Loop, p. 244 The for Loop, p. 271 Nested Loops, p. 279 Solving the Ocean Levels Problem, p. 317 Defining and Calling Functions, p. 324 Using Function Arguments, p. 333 Value-Returning Functions, p. 343 Solving the Markup Problem, p. 399 Creating a Class, p. 412 Creating and Using Class Objects, p. 414 Creating and Using Structures, p. 454 Solving the Car Class Problem, p. 500 Accessing Array Elements, p. 509 Passing an Array to a Function, p. 543 Two-Dimensional Arrays, p. 553 Solving the Chips and Salsa Problem, p. 593 Performing a Binary Search, p. 606 Sorting a Set of Data, p. 613 Solving the Lottery Winners Problem, p. 641 (continued on next page)
LOCATION OF VIDEONOTES IN THE TEXT (continued) ~ VideoNote - Chapter 10 Chapter 11 Chapter 12 Chapter 13 Chapter 14 Pointer Variables, p. 647 Dynamically Allocating an Array, p. 671 Solving the Days in Current Month Problem, p. 702 Operator Overloading , p. 730 Aggregation and Composition, p. 776 Overriding Base Class Functions, p. 797 Solving the Number of Days Worked Problem, p . 811 Converting Strings to Numbers , p. 829 Writing a C-String Handling Function, p. 833 Solving the Case Manipulator Problem, p. 850 The get Family of Member Functions, p. 869 Rewinding a File, p. 873 Solving the File Encryption Filter Problem, p. 912 Recursive Binary Search, p. 927 QuickSort, p. 929 Solving the Recursive Multiplication Problem, p. 947 Polymorph ism, p. 955 Composition versus Inheritance, p. 969 Solving the Sequence Sum Problem, p. 985 Throwing and Handling Exceptions, p. 988 Writing a Function Template, p. 1000 Iterators, p. 1017 Solving the Arithmetic Exceptions Problem, p. 1034 Adding an Element to a Linked List, p. 1045 Removing an Element from a Linked List, p. 1052 Solving the Member Insertion by Position Problem, p. 1083 Storing Objects in an STL Stack, p. 1097 Storing Obj ects in an STL Queue, p. 1111 Solving the File Reverser Problem, p. 1123 Inserting an Element into a Binary Tree, p. 1132 Removing an Element from a Binary Tree, p. 1136 Solving the Tree Size Problem, p. 1152 Chapter 15 - Chapter 16 Chapter 17 Chapter 18 Chapter 19
Ninth Edition C++ Early Objects Tony Gaddis Judy Walters Godfrey Muganda PEARSON Boston Columbus Indianapolis New York San Francisco Hoboken Amsterdam Cape Town Dubai London Madrid Milan Munich Paris Montreal Toronto Delhi Mexico City Sao Paulo Sydney Hong Kong Seoul Singapore Taipei Tokyo
Vice President, Editorial Director , ECS: Marcia Horton Acquisitions Editor: Ma tt Goldstein Editorial Assistant: Kristy Alaura Vice President of Marketin g: Christy Lesko Director of Field Marketing: Tim Ga lligan Product Mark eting Mana ger: Bram Van Kempen Field Marketin g Mana ger: Demetrius Ha ll Marketin g Assistant: Jon Bryant Director of Product Mana gement: Erin Gregg Tea m Lead, Program and Project Management: Scott Disanno Program Mana ger: Carole Snyder Project Mana ger: RPK Editorial Services, Inc. Senior Specialist, Program Planning and Support: Maura Zaldivar -Garcia Cover Designer: Joyce Wells Cover: Sabyna 7 5/Shutterstock Mana ger, Right.s and Permissions: Rachel Youdelman Project Mana ger, Rights and Permissions: William Opa luch Inventory Mana ger: Meredith Maresca Media Project Mana ger: Renata Butera Full-Service Project Mana gement: Deepthi Mohan, Aptara® Corporation Compos ition: Aptara ® Corporation Printer/Binder: Edwar ds Brothers Mallo y, Inc. Cover and Insert Printer: Phoenix Color Microsoft and/or its respective supp liers make no representations about the suitability of the information containe d in the documents and related graphics pub lished as part of the services for any purpose. All such documents and related graphics are provided "as is" without warranty of any kind. Microsoft and/or its respective supp liers hereby disclaim a ll warranties and conditions with regard to this information, including all warranties and conditions of merchantability , whether express, implied or statutory, fitness for a particular purpose, title and non -infringement. In no event shall Microsoft and/or its respective suppliers be liab le for any special, indirect or consequential damages or any damages whatsoever resulting from loss of use, data or profits, whether in an action of contract, negligence or otl1er tortious action, arising out of or in connection with the use or performance of information available from the services. The documents and related graphics contained herein could include technical inaccuracies or typograp hical errors. Changes are periodically added to the information herein. Microsoft and/or its respective supp liers may make improvements and/or changes in the product(s) and/or the program(s) described herein at any time. Partia l screen shots may be viewed in full within the software version specified. Microsoft® Windows®, and Microsoft Office® are registered trademarks of the Microsoft corporation in the U.S.A. and other countries. This book is not sponsored or endorsed by or affiliated with tl1e Microsoft corporation. The programs and app lications presented in this book have been included for their instructional value. They have been tested with care, but are not guaranteed for any particular purpose. The pub lisher does not offer any warranties or representations, nor does it accept any liabilities with respect to the programs or applications. Copyright© 201 7, 2014 Pearson Education, Inc. All rights reserved. Manufactured in the United States of America. This pub lication is protected by Copyright, and permission should be obtained from the pub lisher prior to any prohibited repro duction, storage in a retrieva l system, or transmission in any form or by any means, electronic, mechanica l, photocopying, recording, or likewise. For information regarding permissions, request forms and the appropriate contacts within the Pearson Education Globa l Rights & Permissions department, please visit www.pearsonhig hed.com/permissions/. Many of the designations by manufacturers and sellers to distinguish their products are claimed as trademarks. Where those designations appear in this book, and the pub lisher was aware of a trademark claim, the designations have been printe d in initial caps or all caps. Library of Congress Cataloging-in-Publication Data Names: Gaddis, Tony. I Walters, Judy. I Muganda, Godfrey. Title: Starting out with C++. Early objects/ Tony Gaddis, Judy Walters, Godfrey Muganda. Description: Ninth edition. I Boston : Pearson, 201 7. I Includes index. Identifiers: LCCN 20150488 47 I ISBN 01344002 40 Subjects: LCSH: C++ (Computer program language) Classification: LCC QA76.73.C153 G333 2017 1 DOC 005.13/3-dc23 LC record availab le at http://lccn.loc.gov/20150488 47 10 9 8 7 6 5 4 3 2 1 PEARSON ISBN 10: 0-13-440024 -0 ISBN 13: 978 -0-13-440024 -2
" Preface xv and Programming Introduction Introduction to Computers to C++ 27 Chapter 1 Chapter 2 Chapter 3 Expressions and Interactivity Chapter 4 Making Decisions Chapter 5 Looping Chapter 6 Functions Chapter 7 Chapter 8 Arrays Chapter 9 Searching, Sorting , and Algorithm Analysis 323 to Classes and Objects Introduction 407 243 155 507 77 1 603 645 Pointers Chapter 10 Chapter 11 More about Classes and Object -Oriented Programming Chapter 12 More on ( -Strings and the string Class Chapter 13 Advanced File and 1/ 0 Operations Chapter 14 Recursion Chapter 15 Chapter 16 Exceptions, Templates, Chapter 17 Linked Lists Chapter 18 Chapter 19 Binary Trees and Virtual Functions Stacks and Queues Polymorphism 103 7 1085 1125 915 815 853 949 703 and the Standard Template Library (STL) 987 Appendix A: The ASCII Character Set Appendix B: Operator Precedence Appendix C: Answers Appendix D: Answers Index 1221 1155 and Associativity 1159 to Checkpoints to Odd -Numbered Review Questions 1161 1201 V
分享到:
收藏