- Acknowledgments
- Contributors
- Preface
- Language Standard
- Who Think Before Coding Is For
- The Think Before Coding Arc
- How the Two Books Fit Together
- How to Use the Chapters
- Read, Trace, and Test
- Style, Tools, and Responsibility
- Central Theme
- For Instructors
- Part I: CS1 Foundations
- Chapter 1: Computing, Algorithms, and First C++ Programs
- 1.1 What Computer Science Is Doing Here
- 1.2 From Problem to Program
- 1.3 Your First C++ Program
- 1.4 Source Code, Compilation, and Executable Programs
- 1.5 A Simple Model of the Computer
- 1.6 Trace-Before-Code Activity
- 1.7 Guided Example: Build, Run, and Trace a Tiny Program
- Chapter 2: Values, Variables, Input, and Expressions
- 2.1 From Fixed Output to Input, Process, Output
- 2.2 Values, Types, Variables, and Initialization
- 2.3 Reading Input with std::cin
- 2.4 Arithmetic Expressions
- 2.5 Integer Division, Floating-Point Values, and Conversions
- 2.6 Constants, Magic Numbers, and Meaningful Names
- 2.7 Formatted Output with <iomanip>
- 2.8 Trace-Before-Code Activity
- 2.9 Guided Example: Grade Percentage Calculator
- Chapter 3: Decisions, Boolean Logic, and Program States
- 3.1 From Calculation to Decision
- 3.2 Boolean Expressions and Relational Operators
- 3.3 Truth Tables and Logical Operators
- 3.4 Decision Tables Before Code
- 3.5 if, if-else, and Nested Decisions
- 3.6 Validation, Assertions, and Preconditions
- 3.7 Multi-Way Selection and switch
- 3.8 Named States with enum class
- 3.9 Trace-Before-Code Activity
- 3.10 Guided Example: Validated Grade Classifier
- Chapter 4: Loops and Repetition Patterns
- 4.1 How a Loop Executes
- 4.2 The while Loop
- 4.3 Sentinel-Controlled Input
- 4.4 Counters, Accumulators, and Averages
- 4.5 Minimum and Maximum Values
- 4.6 Searching with a Flag
- 4.7 Validation Loops
- 4.8 Count-Controlled Repetition with for
- 4.9 Post-Test Repetition with do-while
- 4.10 Nested Loops
- 4.11 Loop Invariants
- 4.12 Trace-Before-Code Activity
- 4.13 Guided Example: Repeated Grade Summary
- Chapter 5: Functions and Modular Design
- 5.1 Why Programs Need Functions
- 5.2 What a Function Is
- 5.3 Tracing a Function Call
- 5.4 Return Values and Single-Exit Style
- 5.5 Local Variables and Scope
- 5.6 Designing Functions From a Problem
- 5.7 Function Contracts and Doxygen Basics
- 5.8 Standard Library Functions and Numerical Results
- 5.9 Guided Example: Refactoring a Grade Summary
- Chapter 6: Reference Parameters, Function Testing, and Basic Recursion
- 6.1 Why Parameter Passing Matters
- 6.2 Pass-by-Value
- 6.3 Pass-by-Reference
- 6.4 const Reference Parameters
- 6.5 Output Parameters and Return Values
- 6.6 Testing Function Contracts
- 6.7 Desk Checking Function Calls
- 6.8 Guided Example: Debugging Parameter State
- 6.9 Recursive Function Calls
- Chapter 7: Characters, Strings, and Text Processing
- 7.1 Text Is Structured Data
- 7.2 Characters and Character Literals
- 7.3 Character Classification with <cctype>
- 7.4 Strings, Indexes, and Positions
- 7.5 Traversing a String
- 7.6 Searching and Validating Text
- 7.7 Building and Normalizing Strings
- 7.8 Malformed and Empty Text
- 7.9 C-Strings: Character Arrays in Older C++ Code
- 7.10 Guided Example: Validating and Normalizing Course Codes
- Chapter 8: Files, Command-Line Arguments, and Persistent Data
- 8.1 Why Stored Data Changes the Program
- 8.2 Opening Files and Checking File State
- 8.3 Reading Token Input
- 8.4 Malformed Token Input
- 8.5 Line Input and Malformed Data
- 8.6 Writing Output Files
- 8.7 Command-Line Arguments
- 8.8 Black-Box Input/Output Tests
- 8.9 Guided Example: File-Driven Grade Report
- Chapter 9: Vectors, Arrays, and One-Dimensional Collections
- 9.1 Why Separate Variables Stop Scaling
- 9.2 The Collection Mental Model
- 9.3 Raw Arrays and Bounds
- 9.4 Traversing Arrays Safely
- 9.5 Passing Raw Arrays to Functions
- 9.6 std::vector and Growing Collections
- 9.7 Range-Based for Loops
- 9.8 std::array for Fixed-Size Modern Arrays
- 9.9 Copying Arrays and Vectors
- 9.10 Contiguous Memory and Offsets
- 9.11 Parallel Arrays
- 9.12 Traversal Choices and Simple Collection Questions
- 9.13 Trace-Before-Code Activity
- 9.14 Guided Example: File Data Into a Vector
- Chapter 10: Collection Algorithms, Tables, and Recursive Processing
- 10.1 Algorithms Over One-Dimensional Collections
- 10.2 Sorting, Binary Search, and Basic Cost
- 10.3 Multidimensional Data
- 10.4 Guided Example: Score Analysis
- 10.5 Checkpoint: Collection Skills Before Recursive Applications
- 10.6 Recursive Processing of Collections and Strings
- Chapter 11: Structs, Records, and Tabular Data
- 11.1 Why Records Are Needed
- 11.2 Defining a struct
- 11.3 Trace-Before-Code: One Record
- 11.4 Passing and Returning Records
- 11.5 Checkpoint: One Record Before Many Records
- 11.6 Collections of Records as Tables
- 11.7 Checkpoint: Tables of Records Before Refactoring
- 11.8 Replacing Parallel Arrays
- 11.9 Records as Preparation for Classes
- 11.10 Guided Example: From Parallel Arrays to Records
- Chapter 12: Designing a Complete Programming Project
- 12.1 From Problem Brief to Program Plan
- 12.2 Designing the Data Model
- 12.3 Designing the Function Set
- 12.4 Command-Line Input and File Processing
- 12.5 Validation, Preconditions, Assertions, and Errors
- 12.6 Testing the Whole Program
- 12.7 Documentation and Debugging Evidence
- 12.8 Guided Example: Sensor-Log Analyzer
- 12.9 Project Families and Deliverables
- Appendix A: Development Environment, Command Line, Builds, and Git
- A.1 64-bit Linux, Compiler Setup, Command Line, and Build Workflow
- A.2 Makefiles for Small C++ Projects
- A.3 Version Control Basics with Git
- Appendix B: Code Style, Documentation, Static Analysis, and Formatting
- B.1 Style Guide and Documentation Rules
- B.2 Static Analysis and Formatting Tools
- Appendix C: Debugging, Warnings, Assertions, and Error Handling
- C.1 Compiler Warnings and Assertions
- C.2 Debugging at the Command Line with GDB
- C.3 Error Handling Policy for Beginning C++ Programs
- Appendix D: Testing with Catch2
- D.1 Unit Testing with Catch2: Functions and Simple Programs
- D.2 Unit Testing with Catch2: Classes, ADTs, and Containers
- Appendix E: C++17 Language and Standard Library Quick Reference
- E.1 C++17 Language Summary
- E.2 C++17 Operator Precedence and Associativity
- E.3 C++17 Keywords and Reserved Identifiers
- E.4 C++17 Standard Library Header and Facility Summary
- E.5 ASCII Character Table and Text Encoding Basics
- Appendix F: Computer Organization, Memory, and Valgrind
- F.1 Computer Organization for C++ Students
- F.2 Debugging Dynamic Memory with Valgrind
- Appendix G: Standard Library Containers, Iterators, Algorithms, and Further Topics
- G.1 Standard Library Containers, Iterators, and Algorithms
- G.2 Further Topics
- Appendix H: Curriculum Alignment, Project Sequence, and Assessment Map
- H.1 Coverage Labels
- H.2 CS2023 Knowledge Area Scope
- H.3 ACM CCECC Alignment Notes
- H.4 Project Progression
- H.5 CS2 Assignment Tracks
- H.6 Assessment Evidence
- H.7 Gap Statement
- Sources and Further Reading
- C++ Language and Library
- Teaching Examples and Design Guidance
- Development and Testing Tools
- Curriculum Sources
- Index
Think Before Coding
Structured Problem Solving with C++ for CS1
Programming starts before the first line of code. Think Before Coding is a course-length Computer Science I (CS1) textbook for absolute beginners. It teaches students to analyze problems, trace program behavior, write readable C++17, and test with evidence, progressing from first output to a complete structured programming project.
Minimum price
$19.99
$29.99
You pay
Author earns
About
About the Book
A computer can follow a flawed plan exactly as written. Programming begins earlier: understand the problem, identify the available information and required result, design the steps, express those steps precisely, and test whether the result is trustworthy.
Who This Book Is For
Think Before Coding is Part I of the Programming by Design series and a course-length C++17 textbook for absolute beginners. It assumes no prior experience with C++, computer science, Linux, or command-line tools. The book can support a complete Computer Science I (CS1) course on its own and prepares students who continue into Computer Science II (CS2).
What Students Learn
- analyze a problem before writing code
- predict and trace how a program changes values
- write readable C++17 programs with decisions, loops, functions, strings, files, arrays, vectors, recursion, and records
- test ordinary and boundary cases with evidence
- design and complete a structured programming project
C++ syntax is taught as the expression of a design, not as a collection of isolated rules. The goal is disciplined independence: read the problem carefully, design a solution before coding, compile with warnings, test the result, revise without guessing, and defend the decisions made.
What the Book Includes
The book includes 12 chapters, eight technical and curricular appendices, guided examples, trace-before-code activities, chapter reviews, Programming Exercises, and a complete structured programming project.
Free Sample
Use the Read Free Sample button on this page to download the PDF or EPUB sample. It includes the complete-edition table of contents, the preface, Chapters 1 and 2, Appendix H, Sources and Further Reading, and the complete index.
Current Status
All 12 chapters and all eight appendices are in place. The book remains 80% complete while images are adjusted, prose is refined, external review continues, and instructor resources are developed. No additional chapters or appendices are planned. Readers who purchase the book now receive future updates through Leanpub.
For Instructors
Chapter-aligned lecture slides and test banks are in development for verified instructors. These resources will be provided separately and updated alongside major revisions of the book. They are intended as adaptable starting points for course preparation, not as a hosted course or LMS integration. When they are ready, verified faculty will receive access through a secure site. Visit the instructor support page for information. Faculty may use the Email the Author link on this Leanpub page to request instructor-resource access or a digital evaluation copy when considering the book for adoption. Requests should come from a faculty email address and include a link to an institutional department or faculty page that confirms the requester’s affiliation. These books and their instructor resources are independently produced and are not sponsored or endorsed by the author’s employer. Assessment material should not be shared with students.
Next in the Series
Own the Design is coming soon. Visit its Leanpub page to join the notification list.
Think before coding. Trace before trusting. Test before submitting. Document the contract. Own the result.
Author
About the Author
Kevin Mess is a professor in Computing and Information Technology at the College of Southern Nevada. Since 2013, he has taught Computer Science I and Computer Science II. His courses guide students from their first programs through object-oriented design, data structures, and disciplined software development.
His teaching emphasizes habits that transfer beyond a single course: read the problem carefully, design before coding, trace program behavior, test ordinary and boundary cases, debug systematically, and explain technical decisions clearly. His subject areas include C++ programming, structured problem solving, classes, abstract data types, memory reasoning, linked data structures, and project-based programming.
Kevin is the author of the Programming by Design series, including Think Before Coding and Own the Design. The series provides a coherent path through Computer Science I and Computer Science II by treating C++ syntax as part of a larger process of analysis, design, implementation, testing, and revision. His books and related resources are independently produced and are not institutional publications.
Contents
Table of Contents
Get the free sample chapters
Click the buttons to get the free sample in PDF or EPUB, or read the sample online here
The Leanpub 60 Day 100% Happiness Guarantee
Within 60 days of purchase you can get a 100% refund on any Leanpub purchase, in two clicks.
See full terms...
Earn $8 on a $10 Purchase, and $16 on a $20 Purchase
We pay 80% royalties on purchases of $7.99 or more, and 80% royalties minus a 50 cent flat fee on purchases between $0.99 and $7.98. You earn $8 on a $10 sale, and $16 on a $20 sale. So, if we sell 5000 non-refunded copies of your book for $20, you'll earn $80,000.
(Yes, some authors have already earned much more than that on Leanpub.)
In fact, authors have earned over $15 million writing, publishing and selling on Leanpub.
Learn more about writing on Leanpub
Free Updates. DRM Free.
If you buy a Leanpub book, you get free updates for as long as the author updates the book! Many authors use Leanpub to publish their books in-progress, while they are writing them. All readers get free updates, regardless of when they bought the book or how much they paid (including free).
Most Leanpub books are available in PDF (for computers) and EPUB (for phones, tablets and Kindle). The formats that a book includes are shown at the top right corner of this page.
Finally, Leanpub books don't have any DRM copy-protection nonsense, so you can easily read them on any supported device.
Learn more about Leanpub's ebook formats and where to read them
Write and Publish on Leanpub
You can use Leanpub to easily write, publish and sell in-progress and completed ebooks and online courses!
Leanpub is a powerful platform for serious authors, combining a simple, elegant writing and publishing workflow with a store focused on selling in-progress ebooks.
Leanpub is a magical typewriter for authors: just write in plain text, and to publish your ebook, just click a button. (Or, if you are producing your ebook your own way, you can even upload your own PDF and/or EPUB files and then publish with one click!) It really is that easy.