You are previewing Programming and Problem Solving with C++: Brief Edition, 5th Edition.
O'Reilly logo
Programming and Problem Solving with C++: Brief Edition, 5th Edition

Book Description

Based off the highly successful Programming and Problem Solving with C++ which Dale is famous for, comes the new Brief Edition, perfect for the one-term course. The text was motivated by the need for a text that covered only what instructors and students are able to move through in a single semester without sacrificing the breadth and detail necessary for the introductory programmer. The authors excite and engage students in the learning process with their accessible writing style, rich pedagogy, and relevant examples. This Brief Edition introduces the new Software Maintenance Case Studies element that teaches students how to read code in order to debug, alter, or enhance existing class or code segments.

Table of Contents

  1. Cover Page
  2. Title Page
  3. Copyright Page
  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
    3. 1.3 What's Inside the Computer?
    4. 1.4 Ethics and Responsibilities in the Computing Profession
      1. Software Piracy
      2. Privacy of Data
      3. Use of Computer Resources
      4. Software Engineering
    5. 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
      10. Problem-Solving Case Study: Leap Year Algorithm
      11. Summary
      12. Quick Check
      13. Answers
      14. Exam Preparation Exercises
      15. Programming Warm-Up Exercises
      16. Case Study Follow-Up
      17. 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
    3. 2.3 More about Output
      1. Creating Blank Lines
      2. Inserting Blanks within a Line
      3. Special Characters
    4. 2.4 Program Entry, Correction, and Execution
      1. Entering a Program
      2. Compiling and Running a Program
      3. Problem-Solving Case Study: Printing a Chessboard
      4. Testing and Debugging
      5. Summary
      6. Quick Check
      7. Answers
      8. Exam Preparation Exercises
      9. Programming Warm-Up Exercises
      10. Programming Problems
      11. 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
      3. Software Maintenance Case Study: Precedence Error
    6. 3.6 Function Calls and Library Functions
      1. Value-Returning Functions
      2. Library Functions
      3. Void Functions
    7. 3.7 Formatting Output
      1. Integers and Strings
      2. Floating-Point Numbers
    8. 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
      6. Problem-Solving Case Study: Mortgage Payment Calculator
      7. Testing and Debugging
      8. Summary
      9. Quick Check
      10. Answers
      11. Exam Preparation Exercises
      12. Programming Warm-Up Exercises
      13. Programming Problems
      14. 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
      3. Software Maintenance Case Study: Adding File Input/Output to a Program
      4. Run-Time Input of File Names
    5. 4.5 Input Failure
    6. 4.6 Software Design Methodologies
    7. 4.7 Functional Decomposition
      1. Modules
      2. Implementing the Design
      3. A Perspective on Design
      4. Problem-Solving Case Study: Displaying a Name in Multiple Formats
      5. Testing and Debugging
      6. Testing and Debugging Hints
      7. Summary
      8. Quick Check
      9. Answers
      10. Exam Preparation Exercises
      11. Programming Warm-Up Exercises
      12. Programming Problems
      13. 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
      5. Software Maintenance Case Study: Incorrect Output
    4. 5.4 Nested If Statements
      1. The Dangling else
    5. 5.5 Logical Operators
      1. Precedence of Operators
      2. Relational Operators with Floating-Point Types
    6. 5.6 Testing the State of an I/O Stream
      1. Problem-Solving Case Study: BMI Calculator
      2. Testing and Debugging
      3. Testing in the Problem-Solving Phase: The Algorithm Walk-Through
      4. Testing in the Implementation Phase
      5. The Test Plan
      6. Tests Performed Automatically During Compilation and Execution
      7. Testing and Debugging Hints
      8. Summary
      9. Quick Check
      10. Answers
      11. Exam Preparation Exercises
      12. Programming Warm-Up Exercises
      13. Programming Problems
      14. 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
    4. 6.4 How to Design Loops
      1. Designing the Flow of Control
      2. Designing the Process Within the Loop
      3. The Loop Exit
    5. 6.5 Nested Logic
      1. Designing Nested Loops
      2. Problem-Solving Case Study: Recording Studio Design
      3. Testing and Debugging
      4. Loop-Testing Strategy
      5. Test Plans Involving Loops
      6. Testing and Debugging Hints
      7. Summary
      8. Quick Check
      9. Answers
      10. Exam Preparation Exercises
      11. Programming Warm-Up Exercises
      12. Programming Problems
      13. 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
      1. Software Maintenance Case Study: Changing a Loop Implementation
    4. 7.4 The Break and Continue Statements
    5. 7.5 Guidelines for Choosing a Looping Statement
    6. 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
      9. Problem-Solving Case Study: The Rich Uncle
      10. Testing and Debugging
      11. Testing and Debugging Hints
      12. Summary
      13. Quick Check
      14. Answers
      15. Exam Preparation Exercises
      16. Programming Warm-Up Exercises
      17. Programming Problems
      18. 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
      3. Software Maintenance Case Study: Refactoring a Program
      4. Using Expressions with Parameters
      5. A Last Word of Caution About Argument and Parameter Lists
      6. Writing Assertions as Function Documentation
      7. Problem-Solving Case Study: Lawn Care Company Billing
      8. Testing and Debugging
      9. The assert Library Function
      10. Testing and Debugging Hints
      11. Summary
      12. Quick Check
      13. Answers
      14. Exam Preparation Exercises
      15. Programming Warm-Up Exercises
      16. Programming Problems
      17. 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
      2. Software Maintenance Case Study: Debug a Simple Program
    3. 9.3 Interface Design
      1. Side Effects
      2. Global Constants
    4. 9.4 Value-Returning Functions
      1. Complete Example
      2. Boolean Functions
      3. Interface Design and Side Effects
      4. When to Use Value-Returning Functions
    5. 9.5 Type Coercion in Assignments, Argument Passing, and Return of a Function Value
      1. Problem-Solving Case Study: Health Profile
      2. Testing and Debugging
      3. Stubs and Drivers
      4. Testing and Debugging Hints
      5. Summary
      6. Quick Check
      7. Answers
      8. Exam Preparation Exercises
      9. Programming Warm-Up Exercises
      10. Programming Problems
      11. 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
    5. 10.5 Hierarchical Records
    6. 10.6 Unions
      1. Problem-Solving Case Study: Stylistical Analysis of Text
      2. Testing and Debugging
      3. Coping with Input Errors
      4. Testing and Debugging Hints
      5. Summary
      6. Quick Check
      7. Answers
      8. Exam Preparation Exercises
      9. Programming Warm-Up Exercises
      10. Programming Problems
      11. 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
      9. Software Maintenance Case Study: Modularizing a Program
      10. Using Typedef with Arrays
    2. 11.2 Arrays of Records
      1. Arrays of Records
    3. 11.3 Special Kinds of Array Processing
      1. Subarray Processing
      2. Indexes with Semantic Content
    4. 11.4 Two-Dimensional Arrays
    5. 11.5 Passing Two-Dimensional Arrays as Arguments
    6. 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
    7. 11.7 Another Way of Defining Two-Dimensional Arrays
    8. 11.8 Multidimensional Arrays
    9. 11.9 Sorting and Searching in an Array
      1. Sorting
      2. Searching
      3. Problem-Solving Case Study: Calculating Exam Statistics
      4. Problem-Solving Case Study: Favorite Rock Group
      5. Testing and Debugging
      6. One-Dimensional Arrays
      7. Complex Structures
      8. Multidimensional Arrays
      9. Sorting and Searching
      10. Testing and Debugging Hints
      11. Summary
      12. Quick Check
      13. Answers
      14. Exam Preparation Exercises
      15. Programming Warm-Up Exercises
      16. Programming Problems
      17. 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
      5. Software Maintenance Case Study: Comparing Two TimeOfDay Objects
    6. 12.6 The Name ADT
      1. Specification of the ADT
      2. Implementation File
    7. 12.7 Composition
      1. Design of an Entry Class
    8. 12.8 UML Diagrams
      1. Diagramming a Class
      2. Diagramming Composition of Classes
      3. Problem-Solving Case Study: Create an Array of Name Objects
      4. Testing and Debugging
      5. Testing and Debugging Hints
      6. Summary
      7. Quick Check
      8. Answers
      9. Exam Preparation Exercises
      10. Programming Warm-Up Exercises
      11. Programming Problems
      12. Case Study Follow-Up
  18. 13 - Recursion
    1. 13.1 What Is Recursion?
    2. 13.2 Recursive Algorithms with Simple Variables
    3. 13.3 Towers of Hanoi
    4. 13.4 Recursive Algorithms with Structured Variables
    5. 13.5 Recursion or Iteration?
      1. Software Maintenance Case Study: Substituting Binary Search for Linear Search
      2. Testing and Debugging
      3. Testing and Debugging Hints
      4. Summary
      5. Quick Check
      6. Answers
      7. Exam Preparation Exercises
      8. Programming Warm-Up Exercises
      9. Programming Problems
      10. Case Study Follow-Up
  19. Appendices
  20. Index