Think Like a Programmer

Book description

In this one-of-a-kind text, author V. Anton Spraul breaks down the ways that programmers solve problems and teaches readers what other introductory books often ignore: how to Think Like a Programmer. Each chapter tackles a single programming concept and illustrates how you can apply these tools to real problems in innovative ways.

Publisher resources

View/Submit Errata

Table of contents

  1. Cover Page
  2. Title Page
  3. Copyright Page
  4. Brief Contents
  5. Contents in Detail
  6. Acknowledgments
  7. Introduction
    1. About This Book
      1. Prerequisites
      2. Chosen Topics
      3. Programming Style
      4. Exercises
      5. Why C++?
  8. Chapter 1: Strategies for Problem Solving
    1. Classic Puzzles
      1. The Fox, the Goose, and the Corn
      2. Problem: How to Cross the River?
      3. Sliding Tile Puzzles
      4. Problem: The Sliding Eight
      5. Problem: The Sliding Five
      6. Sudoku
      7. Problem: Completing a Sudoku Square
      8. The Quarrasi Lock
      9. Problem: Opening the Alien Lock
    2. General Problem-Solving Techniques
      1. Always Have a Plan
      2. Restate the Problem
      3. Divide the Problem
      4. Start with What You Know
      5. Reduce the Problem
      6. Look for Analogies
      7. Experiment
      8. Don’t Get Frustrated
    3. Exercises
  9. Chapter 2: Pure Puzzles
    1. Review of C++ Used in This Chapter
    2. Output Patterns
      1. Problem: Half of a Square
      2. Problem: A Square (Half of a Square Reduction)
      3. Problem: A Line (Half of a Square Further Reduction)
      4. Problem: Count Down by Counting Up
      5. Problem: A Sideways Triangle
    3. Input Processing
      1. Problem: Luhn Checksum Validation
      2. Breaking Down the Problem
      3. Problem: Convert Character Digit to Integer
      4. Problem: Luhn Checksum Validation, Fixed Length
      5. Problem: Simple Checksum Validation, Fixed Length
      6. Problem: Positive or Negative
      7. Putting the Pieces Together
    4. Tracking State
      1. Problem: Decode a Message
      2. Problem: Reading a Number with Three or Four Digits
      3. Problem: Reading a Number with Three or Four Digits, Further Simplified
    5. Conclusion
    6. Exercises
  10. Chapter 3: Solving Problems with Arrays
    1. Review of Array Fundamentals
      1. Store
      2. Copy
      3. Retrieval and Search
      4. Sort
      5. Compute Statistics
    2. Solving Problems with Arrays
      1. Problem: Finding the Mode
      2. Refactoring
    3. Arrays of Fixed Data
    4. Non-scalar Arrays
    5. Multidimensional Arrays
    6. Deciding When to Use Arrays
    7. Exercises
  11. Chapter 4: Solving Problems with Pointers and Dynamic Memory
    1. Review of Pointer Fundamentals
    2. Benefits of Pointers
      1. Runtime-Sized Data Structures
      2. Resizable Data Structures
      3. Memory Sharing
    3. When to Use Pointers
    4. Memory Matters
      1. The Stack and the Heap
      2. Memory Size
      3. Lifetime
    5. Solving Pointer Problems
      1. Variable-Length Strings
      2. Problem: Variable-Length String Manipulation
      3. Linked Lists
      4. Problem: Tracking an Unknown Quantity of Student Records
    6. Conclusion and Next Steps
    7. Exercises
  12. Chapter 5: Solving Problems with Classes
    1. Review of Class Fundamentals
    2. Goals of Class Use
      1. Encapsulation
      2. Code Reuse
      3. Dividing the Problem
      4. Information Hiding
      5. Readability
      6. Expressiveness
    3. Building a Simple Class
      1. Problem: Class Roster
      2. The Basic Class Framework
      3. Support Methods
    4. Classes with Dynamic Data
      1. Problem: Tracking an Unknown Quantity of Student Records
      2. Adding a Node
      3. Rearranging the List
      4. Destructor
      5. Deep Copy
      6. The Big Picture for Classes with Dynamic Memory
    5. Mistakes to Avoid
      1. The Fake Class
      2. Single-Taskers
    6. Exercises
  13. Chapter 6: Solving Problems with Recursion
    1. Review of Recursion Fundamentals
    2. Head and Tail Recursion
      1. Problem: How Many Parrots?
      2. Approach 1
      3. Approach 2
      4. Problem: Who’s Our Best Customer?
      5. Approach 1
      6. Approach 2
    3. The Big Recursive Idea
      1. Problem: Computing the Sum of an Array of Integers
    4. Common Mistakes
      1. Too Many Parameters
      2. Global Variables
    5. Applying Recursion to Dynamic Data Structures
      1. Recursion and Linked Lists
      2. Problem: Counting Negative Numbers in a Singly Linked List
      3. Recursion and Binary Trees
      4. Problem: Find the Largest Value in a Binary Tree
    6. Wrapper Functions
      1. Problem: Find the Number of Leaves in a Binary Tree
    7. When to Choose Recursion
      1. Arguments Against Recursion
      2. Problem: Display a Linked List in Order
      3. Problem: Display a Linked List in Reverse Order
    8. Exercises
  14. Chapter 7: Solving Problems with Code Reuse
    1. Good Reuse and Bad Reuse
    2. Review of Component Fundamentals
      1. Code Block
      2. Algorithms
      3. Patterns
      4. Abstract Data Types
      5. Libraries
    3. Building Component Knowledge
      1. Exploratory Learning
      2. Problem: The First Student
      3. As-Needed Learning
      4. Problem: Efficient Traversal
    4. Choosing a Component Type
      1. Component Choice in Action
      2. Problem: Sorting Some, Leaving Others Alone
      3. Comparing the Results
    5. Exercises
  15. Chapter 8: Thinking Like a Programmer
    1. Creating Your Own Master Plan
      1. Playing to Your Strengths and Weaknesses
      2. Putting the Master Plan Together
    2. Tackling Any Problem
      1. Problem: Cheating at Hangman
      2. Finding a Way to Cheat
      3. Required Operations for Cheating at Hangman
      4. Initial Design
      5. Initial Coding
      6. Analysis of Initial Results
      7. The Art of Problem Solving
    3. Learning New Programming Skills
      1. New Languages
      2. New Skills for a Language You Already Know
      3. New Libraries
      4. Take a Class
    4. Conclusion
    5. Exercises
  16. Index
  17. The Electronic Frontier Foundation (EFF)
  18. Updates

Product information

  • Title: Think Like a Programmer
  • Author(s): V. Anton Spraul
  • Release date: August 2012
  • Publisher(s): No Starch Press
  • ISBN: 9781593274245