O'Reilly logo

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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

Book Description

A Concise Edition of the Definitive C++ Text Suitable for One-Term Courses This concise and consolidated edition of the bestselling Programming and Problem Solving with C++ was developed in response to the need for a text that covered only what students and instructors are able to move through in a single semester. Sacrificing none of the breadth and detail of the comprehensive edition, the Brief Edition retains Dale and Weems’s trademark accessible and hands-on style. Highly relevant real-world examples and strong pedagogical features will engage students as they build key skills and absorb critical concepts. The text’s student-focused approach makes even the most difficult concepts in computer science programming accessible to all students. Expanded and reorganized, Programming and Problem Solving with C++: Brief, Sixth Edition presents advanced topics at the introductory level and is the ideal text for one-term introductory computer science programming courses. New and Key Features: - Includes new programming exercises and new, more student-friendly organization of material - Provides new discussion of Pointers and expanded discussion of C-Strings - Features strong pedagogical elements, including real-world case studies and highly relevant exercises that reinforce key concepts and build crucial skills - Introduces C++ language constructs in parallel with appropriate theory so that students immediately realize practical applications - Every new printed copy of the text is packaged with full student access to Turing's Craft Custom CodeLab. Customized to match the organization of the text, CodeLab offers students hands-on C++ programming experience. The system immediately judges the correctness of code typed in by students, and offers hints for building and improving coding skills - Ideally suited for bundling with A Laboratory Course in C++ (978-1-284-02590-3), a digital resource prepared by Nell Dale - Includes a full suite of ancillary resources including a source code for students and instructors, and Power Point Lecture Outlines and a Test Bank for instructors

Table of Contents

  1. Cover
  2. Title Page
  3. Contents
  4. Preface
  5. 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 Answers
      13. Exam Preparation Exercises
      14. Programming Warm-Up Exercises
      15. Case Study Follow-Up
      16. Line Number
  6. 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 Answers
      7. Exam Preparation Exercises
      8. Programming Warm-Up Exercises
      9. Programming Problems
      10. Case Study Follow-Up
  7. 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
      3. 3.5 Compound Arithmetic Expressions
      4. Precedence Rules
      5. Type Coercion and Type Casting
      6. Software Maintenance Case Study: Precedence Error
    5. 3.6 Function Calls and Library Functions
      1. Value-Returning Functions
      2. Library Functions
      3. Void Functions
    6. 3.7 Formatting Output
      1. Integers and Strings
      2. Floating-Point Numbers
    7. 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 Answers
      10. Exam Preparation Exercises
      11. Programming Warm-Up Exercises
      12. Programming Problems
      13. Case Study Follow-Up
  8. 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. Summary
      7. Quick Check Answers
      8. Exam Preparation Exercises
      9. Programming Warm-Up Exercises
      10. Programming Problems
      11. Case Study Follow-Up
  9. 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. Summary
      8. Quick Check Answers
      9. Exam Preparation Exercises
      10. Programming Warm-Up Exercises
      11. Programming Problems
      12. Case Study Follow-Up
  10. 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. Summary
      7. Quick Check Answers
      8. Exam Preparation Exercises
      9. Programming Warm-Up Exercises
      10. Programming Problems
      11. Case Study Follow-Up
  11. 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. Summary
      12. Quick Check Answers
      13. Exam Preparation Exercises
      14. Programming Warm-Up Exercises
      15. Programming Problems
      16. Case Study Follow-Up
  12. 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
      4. Function Call (Invocation)
      5. Function Declarations and Definitions
      6. Local Variables
      7. The Return Statement
    3. 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. Summary
      11. Quick Check Answers
      12. Exam Preparation Exercises
      13. Programming Warm-Up Exercises
      14. Programming Problems
      15. Case Study Follow-Up
  13. 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. Summary
      5. Quick Check Answers
      6. Exam Preparation Exercises
      7. Programming Warm-Up Exercises
      8. Programming Problems
      9. Case Study Follow-Up
  14. 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
    7. 10.7 Pointers
      1. Pointer Variables
      2. Pointers Expressions
    8. 10.8 Reference Types
      1. Problem-Solving Case Study: Stylistical Analysis of Text
      2. Testing and Debugging
      3. Coping with Input Errors
      4. Debugging with Pointers
      5. Summary
      6. Quick Check Answers
      7. Exam Preparation Exercises
      8. Programming Warm-Up Exercises
      9. Programming Problems
      10. Case Study Follow-Up
  15. 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
      11. Pointer Expressions and 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
    10. 11.10 Dynamic Data
      1. Allocating Dynamic Data
      2. Deleting Dynamic Data
      3. Constants and Dynamic Data
    11. 11.11 C-Style Strings
      1. Strings as Arrays
      2. C String Operations
      3. Converting C Strings to C++ Strings
      4. Which String Representation to Use
      5. Problem-Solving Case Study: Calculating Exam Statistics
      6. Problem-Solving Case Study: Favorite Rock Group
      7. Testing and Debugging
      8. One-Dimensional Arrays
      9. Complex Structures
      10. Multidimensional Arrays
      11. Sorting and Searching
      12. Summary
      13. Quick Check Answers
      14. Exam Preparation Exercises
      15. Programming Warm-Up Exercises
      16. Programming Problems
      17. Case Study Follow-Up
  16. 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. Summary
      6. Quick Check Answers
      7. Exam Preparation Exercises
      8. Programming Warm-Up Exercises
      9. Programming Problems
      10. Case Study Follow-Up
  17. 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. Summary
      4. Quick Check Answers
      5. Exam Preparation Exercises
      6. Programming Warm-Up Exercises
      7. Programming Problems
  18. 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
  19. Index