Programming and Problem Solving with C++: Comprehensive, 6th Edition

Book description


The best-selling Programming and Problem Solving with C++, now in it's Sixth Edition, remains the clearest introduction to C++, object-oriented programming, and software development available. Renowned author team Nell Dale and Chip Weems are careful to include all topics and guidelines put forth by the ACM/IEEE to make this text ideal for the one- or two-term CS1 course. Their philosophy centers on making the difficult concepts of computer science programming accessible to all students, while maintaining the breadth of detail and topics covered.

Key Features:
-The coverage of advanced object-oriented design and data structures has been moved to later in the text.
-Provides the highly successful concise and student-friendly writing style that is a trademark for the Dale/Weems textbook series in computer science.
-Introduces C++ language constructs in parallel with the appropriate theory so students see and understand its practical application.
-Strong pedagogical elements, a hallmark feature of Dale/Weems' successful hands-on teaching approach, include Software Maintenance case studies, Problem-Solving case studies, Testing & Debugging exercises, Exam Preparation exercises, Programming Warm-up exercises, Programming Problems, Demonstration Projects, and Quick Check exercises.
-A complete package of student and instructor resources include a student companion website containing all the source code for the programs and exercises in the text, additional appendices with C++ reference material and further discussion of topics from the text, and a complete digital lab manual in C++. Instructors are provided all the solutions to the exercises in the text, the source code, a Test Bank, and PowerPoint Lecture Outlines organized by chapter.

Table of contents

  1. Cover
  2. Title Page
  3. Copyright
  4. Contents
  5. Preface
  6. 1 Overview of Programming and Problem Solving
    1. 1.1 Overview of Programming
      1. What Is Programming?
      2. How Do We Write a Program?
      3. What Is an Algorithm?
      4. What Is a Programming Language?
    2. 1.2 How Does a Computer Run a Program?
      1. What Kinds of Instructions Can Be Written in a Programming Language?
      2. What Is Software Maintenance?
    3. Software Maintenance Case Study: An Introduction to Software Maintenance
    4. 1.3 What’s Inside the Computer?
    5. 1.4 Ethics and Responsibilities in the Computing Profession
      1. Software Piracy
      2. Privacy of Data
      3. Use of Computer Resources
      4. Software Engineering
    6. 1.5 Problem-Solving Techniques
      1. Ask Questions
      2. Look for Things That Are Familiar
      3. Solve by Analogy
      4. Means-Ends Analysis
      5. Divide and Conquer
      6. The Building-Block Approach
      7. Merging Solutions
      8. Mental Blocks: The Fear of Starting
      9. Algorithmic Problem Solving
    7. Problem-Solving Case Study: Leap Year Algorithm
    8. Summary
    9. Quick Check Answers
    10. Exam Preparation Exercises
    11. Programming Warm-Up Exercises
    12. Case Study Follow-Up
    13. Line Number
  7. 2 C++ Syntax and Semantics, and the Program Development Process
    1. 2.1 The Elements of C++ Programs
      1. C++ Program Structure
      2. Syntax and Semantics
      3. Syntax Templates
      4. Naming Program Elements: Identifiers
      5. Data and Data Types
      6. Naming Elements: Declarations
      7. Taking Action: Executable Statements
      8. Beyond Minimalism: Adding Comments to a Program
    2. 2.2 Program Construction
      1. Blocks (Compound Statements)
      2. The C++ Preprocessor
    3. Software Maintenance Case Study: Adding Titles to Names
    4. 2.3 More About Output
      1. Creating Blank Lines
      2. Inserting Blanks Within a Line
      3. Special Characters
    5. 2.4 Program Entry, Correction, and Execution
      1. Entering a Program
      2. Compiling and Running a Program
    6. Problem-Solving Case Study: Printing a Chessboard
    7. Testing and Debugging
    8. Summary
    9. Quick Check Answers
    10. Exam Preparation Exercises
    11. Programming Warm-Up Exercises
    12. Programming Problems
    13. Case Study Follow-Up
  8. 3 Numeric Types, Expressions, and Output
    1. 3.1 Overview of C++ Data Types
    2. 3.2 Numeric Data Types
      1. Integral Types
      2. Floating-Point Types
    3. 3.3 Declarations for Numeric Types
      1. Named Constant Declarations
      2. Variable Declarations
    4. 3.4 Simple Arithmetic Expressions
      1. Arithmetic Operators
      2. Increment and Decrement Operators
    5. 3.5 Compound Arithmetic Expressions
      1. Precedence Rules
      2. Type Coercion and Type Casting
    6. Software Maintenance Case Study: Precedence Error
    7. 3.6 Function Calls and Library Functions
      1. Value-Returning Functions
      2. Library Functions
      3. Void Functions
    8. 3.7 Formatting Output
      1. Integers and Strings
      2. Floating-Point Numbers
    9. 3.8 Additional string Operations
      1. The length and size Functions
      2. The find Function
      3. The substr Function
      4. Accessing Characters Within a String: The at Function
      5. Converting to Lowercase and Uppercase
    10. Problem-Solving Case Study: Mortgage Payment Calculator
    11. Testing and Debugging
    12. Summary
    13. Quick Check Answers
    14. Exam Preparation Exercises
    15. Programming Warm-Up Exercises
    16. Programming Problems
    17. Case Study Follow-Up
  9. 4 Program Input and the Software Design Process
    1. 4.1 Getting Data into Programs
      1. Input Streams and the Extraction Operator (>>)
      2. The Reading Marker and the Newline Character
      3. Reading Character Data with the get Function
      4. Skipping Characters with the ignore Function
      5. Reading String Data
    2. 4.2 Interactive Input/Output
    3. 4.3 Noninteractive Input/Output
    4. 4.4 File Input and Output
      1. Files
      2. Using Files
    5. Software Maintenance Case Study: Adding File Input/Output to a Program
      1. Run-Time Input of File Names
    6. 4.5 Input Failure
    7. 4.6 Software Design Methodologies
    8. 4.7 Functional Decomposition
      1. Modules
      2. Implementing the Design
      3. A Perspective on Design
    9. Problem-Solving Case Study: Displaying a Name in Multiple Formats
    10. Testing and Debugging
    11. Summary
    12. Quick Check Answers
    13. Exam Preparation Exercises
    14. Programming Warm-Up Exercises
    15. Programming Problems
    16. Case Study Follow-Up
  10. 5 Conditions, Logical Expressions, and Selection Control Structures
    1. 5.1 Flow of Control
      1. Selection
    2. 5.2 Conditions and Logical Expressions
      1. The bool Data Type
      2. Logical Expressions
    3. 5.3 The If Statement
      1. The If-Then-Else Form
      2. Blocks (Compound Statements)
      3. The If-Then Form
      4. A Common Mistake
    4. Software Maintenance Case Study: Incorrect Output
    5. 5.4 Nested If Statements
      1. The Dangling else
    6. 5.5 Logical Operators
      1. Precedence of Operators
      2. Relational Operators with Floating-Point Types
    7. 5.6 Testing the State of an I/O Stream
    8. Problem-Solving Case Study: BMI Calculator
    9. Testing and Debugging
      1. Testing in the Problem-Solving Phase: The Algorithm Walk-Through
      2. Testing in the Implementation Phase
      3. The Test Plan
      4. Tests Performed Automatically During Compilation and Execution
    10. Summary
    11. Quick Check Answers
    12. Exam Preparation Exercises
    13. Programming Warm-Up Exercises
    14. Programming Problems
    15. Case Study Follow-Up
  11. 6 Looping
    1. 6.1 The While Statement
    2. 6.2 Phases of Loop Execution
    3. 6.3 Loops Using the While Statement
      1. Count-Controlled Loops
      2. Event-Controlled Loops
      3. Looping Subtasks
    4. Software Maintenance Case Study: Make a Program General
    5. 6.4 How to Design Loops
      1. Designing the Flow of Control
      2. Designing the Process Within the Loop
      3. The Loop Exit
    6. 6.5 Nested Logic
      1. Designing Nested Loops
    7. Problem-Solving Case Study: Recording Studio Design
    8. Testing and Debugging
      1. Loop-Testing Strategy
      2. Test Plans Involving Loops
    9. Summary
    10. Quick Check Answers
    11. Exam Preparation Exercises
    12. Programming Warm-Up Exercises
    13. Programming Problems
    14. Case Study Follow-Up
  12. 7 Additional Control Structures
    1. 7.1 The Switch Statement
    2. 7.2 The Do-While Statement
    3. 7.3 The For Statement
    4. Software Maintenance Case Study: Changing a Loop Implementation
    5. 7.4 The Break and Continue Statements
    6. 7.5 Guidelines for Choosing a Looping Statement
    7. 7.6 Additional C++ Operators
      1. Assignment Operators and Assignment Expressions
      2. Increment and Decrement Operators
      3. Bitwise Operators
      4. The Cast Operation
      5. The sizeof Operator
      6. The ?: Operator
      7. Operator Precedence
      8. Type Coercion in Arithmetic and Relational Expressions
    8. Problem-Solving Case Study: The Rich Uncle
    9. Testing and Debugging
    10. Summary
    11. Quick Check Answers
    12. Exam Preparation Exercises
    13. Programming Warm-Up Exercises
    14. Programming Problems
    15. Case Study Follow-Up
  13. 8 Functions
    1. 8.1 Functional Decomposition with Void Functions
      1. When to Use Functions
      2. Why Do Modules Need an Interface Design?
      3. Designing Interfaces
      4. Writing Modules as Void Functions
    2. 8.2 An Overview of User-Defined Functions
      1. Flow of Control in Function Calls
      2. Function Parameters
    3. 8.3 Syntax and Semantics of Void Functions
      1. Function Call (Invocation)
      2. Function Declarations and Definitions
      3. Local Variables
      4. The Return Statement
    4. 8.4 Parameters
      1. Value Parameters
      2. Reference Parameters
    5. Software Maintenance Case Study: Refactoring a Program
      1. Using Expressions with Parameters
      2. A Last Word of Caution About Argument and Parameter Lists
      3. Writing Assertions as Function Documentation
    6. Problem-Solving Case Study: Lawn Care Company Billing
    7. Testing and Debugging
      1. The assert Library Function
    8. Summary
    9. Quick Check Answers
    10. Exam Preparation Exercises
    11. Programming Warm-Up Exercises
    12. Programming Problems
    13. Case Study Follow-Up
  14. 9 Scope, Lifetime, and More on Functions
    1. 9.1 Scope of Identifiers
      1. Scope Rules
      2. Variable Declarations and Definitions
      3. Namespaces
    2. 9.2 Lifetime of a Variable
      1. Initializations in Declarations
    3. Software Maintenance Case Study: Debug a Simple Program
    4. 9.3 Interface Design
      1. Side Effects
      2. Global Constants
    5. 9.4 Value-Returning Functions
      1. Complete Example
      2. Boolean Functions
      3. Interface Design and Side Effects
      4. When to Use Value-Returning Functions
    6. 9.5 Type Coercion in Assignments, Argument Passing, and Return of a Function Value
    7. Problem-Solving Case Study: Health Profile
    8. Testing and Debugging
      1. Stubs and Drivers
    9. Summary
    10. Quick Check Answers
    11. Exam Preparation Exercises
    12. Programming Warm-Up Exercises
    13. Programming Problems
    14. Case Study Follow-Up
  15. 10 User-Defined Data Types
    1. 10.1 Built-In Simple Types
      1. Numeric Types
      2. Characters
    2. 10.2 User-Defined Simple Types
      1. The Typedef Statement
      2. Enumeration Types
      3. Named and Anonymous Data Types
    3. 10.3 Simple Versus Structured Data Types
    4. 10.4 Records (Structs)
      1. Accessing Individual Components
      2. Aggregate Operations on Structs
      3. More About Struct Declarations
      4. Binding Like Items
    5. Software Maintenance Case Study: Changing a Loop Implementation
    6. 10.5 Hierarchical Records
    7. 10.6 Unions
    8. 10.7 Pointers
      1. Pointer Variables
      2. Pointers Expressions
    9. 10.8 Reference Types
    10. Problem-Solving Case Study: Stylistical Analysis of Text
    11. Testing and Debugging
      1. Coping with Input Errors
      2. Debugging with Pointers
    12. Summary
    13. Quick Check Answers
    14. Exam Preparation Exercises
    15. Programming Warm-Up Exercises
    16. Programming Problems
    17. Case Study Follow-Up
  16. 11 Arrays
    1. 11.1 One-Dimensional Arrays
      1. Declaring Arrays
      2. Accessing Individual Components
      3. Out-of-Bounds Array Indexes
      4. Initializing Arrays in Declarations
      5. (Lack of) Aggregate Array Operations
      6. Examples of Declaring and Accessing Arrays
      7. Passing Arrays as Arguments
      8. Commenting Arrays
    2. Software Maintenance Case Study: Modularizing a Program
      1. Using Typedef with Arrays
      2. Pointer Expressions and Arrays
      3. C-Style Strings
      4. Strings as Arrays
      5. C String Operations
      6. Converting C Strings to C++ Strings
      7. Which String Representation to Use
    3. 11.2 Arrays of Records
      1. Arrays of Records
    4. 11.3 Special Kinds of Array Processing
      1. Subarray Processing
      2. Indexes with Semantic Content
    5. 11.4 Two-Dimensional Arrays
    6. 11.5 Passing Two-Dimensional Arrays as Arguments
    7. 11.6 Processing Two-Dimensional Arrays
      1. Sum the Rows
      2. Sum the Columns Revised
      3. Sum the Columns
      4. Initialize the Array
      5. Print the Array
    8. 11.7 Another Way of Defining Two-Dimensional Arrays
    9. 11.8 Multidimensional Arrays
    10. Problem-Solving Case Study: Calculating Exam Statistics
    11. Problem-Solving Case Study: Favorite Rock Group
    12. Testing and Debugging
      1. One-Dimensional Arrays
      2. Complex Structures
      3. Multidimensional Arrays
    13. Summary
    14. Quick Check Answers
    15. Exam Preparation Exercises
    16. Programming Warm-Up Exercises
    17. Programming Problems
    18. Case Study Follow-Up
  17. 12 Classes and Abstraction
    1. 12.1 Abstract Data Types
    2. 12.2 C++ Classes
      1. Implementing the Member Functions
      2. Classes, Objects, and Members
      3. Built-in Operations on Objects
      4. Class Scope
    3. 12.3 Information Hiding
      1. User-Written Header Files
      2. Specification and Implementation Files
      3. Compiling and Linking a Multifile Program
    4. 12.4 What Is an Object?
    5. 12.5 Class Design Principles
      1. Encapsulation
      2. Abstraction
      3. Designing for Modifiability and Reuse
      4. Mutability
    6. Software Maintenance Case Study: Comparing Two TimeOfDay Objects
    7. 12.6 The Name ADT
      1. Specification of the ADT
      2. Implementation File
    8. 12.7 Composition
      1. Design of an Entry Class
    9. 12.8 UML Diagrams
      1. Diagramming a Class
      2. Diagramming Composition of Classes
    10. Problem-Solving Case Study: Create an Array of Name Objects
    11. Testing and Debugging
    12. Summary
    13. Quick Check Answers
    14. Exam Preparation Exercises
    15. Programming Warm-Up Exercises
    16. Programming Problems
    17. Case Study Follow-Up
  18. 13 Array-Based Lists
    1. 13.1 What Is a List?
    2. 13.2 The List as an Abstract Data Type
      1. Refining Responsibilities
      2. Data Representation
      3. Example Program
    3. 13.3 Implementation of List ADT
      1. Basic Operations
      2. Insertion and Deletion
      3. Sequential Search
      4. Iterators
    4. Software Maintenance Case Study: Enhancing Class List with a Sort
    5. 13.4 Sorted Lists
      1. Basic Operations
      2. Insertion
      3. Sequential Search
      4. Binary Search
      5. Deletion
    6. 13.5 Sorted List of Classes
      1. IsThere
      2. Insert and Delete
    7. 13.6 More on UML Diagrams
    8. Problem-Solving Case Study: Calculating Exam Statistics Revisited
    9. Testing and Debugging
    10. Summary
    11. Quick Check Answers
    12. Exam Preparation Exercises
    13. Programming Warm-Up Exercises
    14. Programming Problems
    15. Case Study Follow-Up
  19. 14 Dynamic Data and Linked Lists
    1. 14.1 Dynamic Data
      1. Allocating Dynamic Data
      2. Deleting Dynamic Data
      3. Constants and Dynamic Data
    2. 14.2 Sequential Versus Linked Structures
    3. 14.3 Creating a Dynamic Linked List: A Walk-Through Example
    4. 14.4 Dynamic Implementation of ADT List
      1. Creating an Empty Linked List
      2. Inserting into a Linked List
      3. Traversals of a Linked List
      4. Deleting from a Linked List
      5. Resetting the List
      6. Getting the Next Item
      7. Testing for the Full Linked List
      8. Searching the List
    5. 14.5 Destructors and Copy Constructors
      1. Destructor
      2. Shallow Versus Deep Copying
      3. Copy-Constructor
    6. 14.6 Sorted Linked List
      1. Insert(20)
      2. Insert(60) (pick up with loop)
      3. Insert(100)
      4. Deleting from a Linked List
      5. Delete(30)
      6. Delete(50)
    7. Problem-Solving Case Study: Creating a Sorted List of Entry Objects
    8. Testing and Debugging
    9. Summary
    10. Quick Check Answers
    11. Exam Preparation Exercises
    12. Programming Warm-Up Exercises
    13. Programming Problems
    14. Case Study Follow-Up
  20. 15 Inheritance, Polymorphism, and Object-Oriented Design
    1. 15.1 Object-Oriented Programming
    2. 15.2 Inheritance
      1. An Analogy
      2. Inheritance and the Object-Oriented Design Process
      3. Deriving One Class from Another Class
      4. Specification of the ExpandedEntry Class
      5. Implementation of the ExpandedEntry Class
      6. Constructor Execution Order
    3. Software Maintenance Case Study: Extending TimeOfDay with Support for a Time Zone
    4. 15.3 Dynamic Binding and Virtual Functions
      1. The Slicing Problem
      2. Virtual Functions
    5. 15.4 Object-Oriented Design
      1. Brainstorming
      2. Filtering
      3. Scenario Exploration
      4. Responsibility Algorithms
      5. A Final Word
    6. 15.5 Implementing a Design
    7. Problem-Solving Case Study: Creating an Appointment Calendar
    8. Testing and Debugging
    9. Summary
    10. Quick Check Answers
    11. Exam Preparation Exercises
    12. Programming Warm-Up Exercises
    13. Programming Problems
    14. Case Study Follow-Up
  21. 16 Templates, Operator Overloading, and Exceptions
    1. 16.1 Template Classes
      1. Defining a Class Template
      2. Instantiating a Class Template
      3. Another Way of Implementing Incoming Parameters: const References
      4. Organization of Program Code
      5. A Word of Caution
    2. 16.2 Generic Functions
      1. Function Overloading
      2. Defining a Function Template Outside a Class
      3. Instantiating a Function Template
    3. 16.3 Operator Overloading
      1. Using *this
    4. 16.4 Exceptions
      1. The throw Statement
      2. The try-catch Statement
      3. Nonlocal Exception Handlers
      4. Rethrowing an Exception
      5. Standard Exceptions
    5. Software Maintenance Case Study: Adding Exceptions to the Date Class
    6. Problem-Solving Case Study: Starship Weight and Balance
    7. Testing and Debugging
    8. Summary
    9. Quick Check Answers
    10. Exam Preparation Exercises
    11. Programming Warm-Up Exercises
    12. Programming Problems
    13. Case Study Follow-Up
  22. 17 Introduction to Data Structures Using the Standard Template Library
    1. 17.1 Abstract Data Structures versus Implementations
    2. 17.2 Additional Linear Structures
      1. Stacks
      2. Queues
      3. Priority Queues
    3. 17.3 Bidirectional Linear Structures
      1. Bidirectional Lists
      2. Deques
    4. 17.4 An Introduction to the STL
      1. Iterators
      2. The vector Template
      3. The list Template
      4. The stack Template
      5. The queue Template
      6. The priority_queue Template
      7. The deque Template
    5. Software Maintenance Case Study: Appointment Calendar Using STL List
    6. 17.5 Nonlinear Structures
      1. Binary Trees
      2. Hash Tables
    7. 17.6 Associative Containers
      1. The set Template
      2. The map Template
    8. Problem-Solving Case Study: Creating a Deck of Cards
    9. Testing and Debugging
    10. Summary
    11. Quick Check Answers
    12. Exam Preparation Exercises
    13. Programming Warm-Up Exercises
    14. Programming Problems
    15. Case Study Follow-Up
  23. 18 Recursion
    1. 18.1 What Is Recursion?
    2. 18.2 Recursive Algorithms with Simple Variables
    3. 18.3 Towers of Hanoi
    4. 18.4 Recursive Algorithms with Structured Variables
    5. Software Maintenance Case Study: Substituting Binary Search for Linear Search
    6. 18.5 Recursion Using Pointer Variables
      1. Printing a Dynamic Linked List in Reverse Order
      2. Copying a Dynamic Linked List
    7. 18.6 Recursion or Iteration?
    8. Problem-Solving Case Study: Quicksort
    9. Testing and Debugging
    10. Summary
    11. Quick Check Answers
    12. Exam Preparation Exercises
    13. Programming Warm-Up Exercises
    14. Programming Problems
    15. Case Study Follow-Up
  24. Appendices
    1. Appendix A: Reserved Words
    2. Appendix B: Operator Precedence
    3. Appendix C: A Selection of Standard Library Routines
    4. Appendix D: Using This Book with a Prestandard Version of C++
    5. Appendix E: Character Sets
    6. Appendix F: Program Style, Formatting, and Documentation
    7. Appendix G: More on Floating-Point Numbers
    8. Appendix H: Using C Strings
    9. Appendix I: C++ char Constants
  25. Index

Product information

  • Title: Programming and Problem Solving with C++: Comprehensive, 6th Edition
  • Author(s): Nell Dale, Chip Weems
  • Release date: March 2013
  • Publisher(s): Jones & Bartlett Learning
  • ISBN: 9781449694272