Programming in C++
Table of Contents
1. Introduction to C++
1.1 Programming (general)
1.2 Programming basics
1.3 Console input
1.4 Comments and whitespace
1.5 Errors and warnings
1.6 Computers and programs (general)
1.7 Integrated development environment
1.8 Computer tour
1.9 Language history
1.10 Problem solving
1.11 Why programming
1.12 Why whitespace and precision matter
1.13 C++ example: Salary Calculation
1.14 C++ example: Married-couple names
2. Variables / Assignments
2.1 Variables and assignments (general)
2.2 Variables (int)
2.3 Identifiers
2.4 Arithmetic expressions (general)
2.5 Arithmetic expressions (int)
2.6 Example: Health data
2.7 Floating-point numbers (double)
2.8 Scientific notation for floating-point literals
2.9 Constant variables
2.10 Using math functions
2.11 Integer division and modulo
2.12 Type conversions
2.13 Binary
2.14 Characters
2.15 Strings
2.16 Integer overflow
2.17 Numeric data types
2.18 Unsigned
2.19 Random numbers
2.20 Debugging
2.21 Auto (since C++11)
2.22 Style guidelines
2.23 C++ example: Salary calculation with variables
2.24 C++ example: Married-couple names with variables
3. Branches
3.1 If-else branches (general)
3.2 Detecting equal values with branches
3.3 Detecting ranges with branches (general)
3.4 Detecting ranges with branches
3.5 Detecting ranges using logical operators
3.6 Detecting ranges with gaps
3.7 Detecting multiple features with branches
3.8 Common branching errors
3.9 Example: Toll calculation
3.10 Order of evaluation
3.11 Switch statements
3.12 Boolean data type
3.13 String comparisons
3.14 String access operations
3.15 Character operations
3.16 Finding, inserting, and replacing text in a string
3.17 Conditional expressions
3.18 Floating-point comparison
3.19 Short circuit evaluation
3.20 C++ example: Salary calculation with branches
3.21 C++ example: Search for name using branches
4. Loops
4.1 Loops (general)
4.2 While loops
4.3 More while examples
4.4 For loops
4.5 More for loop examples
4.6 Loops and strings
4.7 Nested loops
4.8 Developing programs incrementally
4.9 Break and continue
4.10 Variable name scope
4.11 Enumerations
4.12 C++ example: Salary calculation with loops
4.13 C++ example: Domain name validation with loops
5. Arrays / Vectors
5.1 Array concept (general)
5.2 Vectors
5.3 Array iteration drill
5.4 Iterating through vectors
5.5 Multiple vectors
5.6 Vector resize
5.7 Vector push_back
5.8 Loop-modifying or copying/comparing vectors
5.9 Swapping two variables (General)
5.10 Debugging example: Reversing a vector
5.11 Arrays vs. vectors
5.12 Two-dimensional arrays
5.13 Char arrays / C strings
5.14 C-String library functions
5.15 Char library functions: cctype
5.16 C++ example: Annual salary tax rate calculation with vectors
5.17 C++ example: Domain name validation with vectors
6. User-Defined Functions
6.1 User-defined function basics
6.2 Print functions
6.3 Reasons for defining functions
6.4 Writing mathematical functions
6.5 Functions with branches
6.6 Functions with loops
6.7 Unit testing (functions)
6.8 How functions work
6.9 Functions: Common errors
6.10 Pass by reference
6.11 Using pass by reference to modify string/vector parameters
6.12 Functions with C string parameters
6.13 Scope of variable/function definitions
6.14 Default parameter values
6.15 Function name overloading
6.16 Parameter error checking
6.17 Preprocessor and include
6.18 Separate files
6.19 C++ example: Salary calculation with functions
6.20 C++ example: Domain name validation with functions
7. Objects and Classes
7.1 Objects: Introduction
7.2 Using a class
7.3 Defining a class
7.4 Inline member functions
7.5 Mutators, accessors, and private helpers
7.6 Initialization and constructors
7.7 Classes and vectors/classes
7.8 Separate files for classes
7.9 Choosing classes to create
7.10 Unit testing (classes)
7.11 Constructor overloading
7.12 Constructor initializer lists
7.13 The ‘this’ implicit parameter
7.14 Operator overloading
7.15 Overloading comparison operators
7.16 Vector ADT
7.17 Namespaces
7.18 Static data members and functions
7.19 C++ example: Salary calculation with classes
7.20 C++ example: Domain name availability with classes
8. Pointers
8.1 Pointers (General)
8.2 Pointers and dynamically allocated arrays
8.3 Changing the size of a dynamically allocated arrays
8.4 Dynamically allocating objects
8.5 Allocating arrays of objects
8.6 Classes with dynamically allocated data
8.7 String functions with pointers
8.8 Memory regions: Heap/Stack
8.9 Destructors
8.10 Memory leaks
8.11 Copy constructors
8.12 Copy assignment operator
8.13 Rule of three
8.14 Smart pointers
8.15 C++ example: Employee list using vectors
9. Streams
9.1 Output and input streams
9.2 Output formatting
9.3 Input string stream
9.4 Output string stream
9.5 File input
9.6 C++ example: Parsing and validating input files
9.7 File output
9.8 C++ example: Saving and retrieving program data
9.9 Overloading stream operators
10. Inheritance
10.1 Derived classes
10.2 Access by members of derived classes
10.3 Overriding member functions
10.4 Polymorphism and virtual member functions
10.5 Abstract classes: Introduction (generic)
10.6 Abstract classes
10.7 Is-a versus has-a relationships
10.8 UML
10.9 C++ example: Employees and overriding class functions
10.10 C++ example: Employees using an abstract class
11. Recursion
11.1 Recursion: Introduction
11.2 Recursive functions
11.3 Recursive algorithm: Search
11.4 Adding output statements for debugging
11.5 Creating a recursive function
11.6 Recursive math functions
11.7 Recursive exploration of all possibilities
11.8 Stack overflow
11.9 C++ example: Recursively output permutations
12. Exceptions
12.1 Handling exceptions
12.2 Throwing exceptions
12.3 Exceptions with files
12.4 User-defined exceptions
12.5 C++ example: Generate number format exception
13. Templates
13.1 Function templates
13.2 Class templates
13.3 C++ example: Map values using a function template
14. Containers
14.1 Range-based for loop
14.2 List
14.3 Pair
14.4 Map
14.5 Set
14.6 Queue
14.7 Deque
14.8 find() function
14.9 sort() function
15. Searching and Sorting Algorithms
15.1 Searching and algorithms
15.2 Binary search
15.3 O notation
15.4 Algorithm analysis
15.5 Sorting: Introduction
15.6 Selection sort
15.7 Insertion sort
15.8 Quicksort
15.9 Merge sort
16. Additional Material
16.1 Do-while loops
16.2 Arrays
16.3 Iterating through arrays
16.4 Multiple arrays
16.5 Loop-modifying or copying/comparing arrays
16.6 Debugging example: Reversing an array
16.7 Engineering examples
16.8 Functions with array parameters
16.9 Functions with array parameters: Common errors
16.10 Engineering examples using functions
16.11 Grouping data: struct
16.12 Structs and functions
16.13 Structs and vectors
16.14 Structs, vectors, and functions: A seat reservation example
16.15 Command-line arguments
16.16 Command-line arguments and files
16.17 The #define directive
16.18 Compiling and running a program using a command-line interface
16.19 Modular compilation
16.20 Makefiles
16.21 Additional material: Why pointers?
16.22 Additional material: A first linked list
16.23 Additional material: Destructors (Simple linked lists)
16.24 Additional practice: Output art
16.25 Additional practice: Grade calculation
16.26 Additional practice: Abbreviation decoder
16.27 Additional practice: Dice statistics
16.28 zyBooks built-in programming window
Teach C++ with this hands-on, interactive zyBook with zyLabs
Programming in C++ is a comprehensive introduction to the principles and practice of C++ programming, based on the latest standards.
- Covers foundational constructs, like branches, loops and functions, and advanced topics, like inheritance, exceptions and plotting
- Packed with over 700 interactive coding exercises and learning activities to help students master the material
- Includes emphasis on disciplined program development, incremental development, modular development, and testing/debugging.
- Completely customizable so instructors can reorganize, edit and add their own learning content
- Adopters have access to a test bank with over 650 questions
What is a zyBook?
Programming in C++is a web-native, interactive zyBook that helps students visualize concepts to learn faster and more effectively than with a traditional textbook. Check out our research.
Since 2012, over 1,800 academic institutions have adopted digital zyBooks to transform their STEM education.
zyBooks benefits both students and instructors:
- Instructor benefits
- Customize your course by reorganizing existing content, or adding your own content
- Continuous publication model updates your course with the latest content and technologies
- Robust reporting gives you insight into students’ progress, reading and participation
- Save time with auto-graded labs and challenge activities that seamlessly integrate with your LMS gradebook
- Build quizzes and exams with hundreds of included test questions
- Student benefits
- Learning questions and other content serve as an interactive form of reading
- Instant feedback on labs and homework
- Concepts come to life through extensive animations embedded into the interactive content
- Review learning content before exams with different questions and challenge activities
- Save chapters as PDFs to reference the material at any time
What is a zyLab?
See the capabilities of the zyBooks programming environment
Authors
Frank Vahid
Computer Science PhD, Univ. of California, Irvine / zyBooks Co-Founder
Roman Lysecky
Professor Emeritus of Electrical and Computer Engineering, Univ. of Arizona
Programming in Python 3
in All, Computer Science, CS1/2/3/by Harris SalatTable of Contents
1. Introduction to Python
1.1 Programming (general)
1.2 Programming using Python
1.3 Basic input and output
1.4 Errors
1.5 Integrated development environment
1.6 Computers and programs (general)
1.7 Computer tour
1.8 Language history
1.9 Why whitespace and precision matter
1.10 Python example: Salary calculation
1.11 Additional practice: Output art
2. Variables and Expressions
2.1 Variables and assignments
2.2 Identifiers
2.3 Objects
2.4 Numeric types: Floating-point
2.5 Arithmetic expressions
2.6 Python expressions
2.7 Division and modulo
2.8 Module basics
2.9 Math module
2.10 Random numbers
2.11 Representing text
2.12 Additional practice: Number games
3. Types
3.1 String basics
3.2 String formatting
3.2 List basics
3.3 Tuple basics
3.4 Set basics
3.5 Dictionary basics
3.6 Common data types summary
3.7 Additional practice: Grade calculation
3.8 Type conversions
3.9 Binary numbers
3.11 Additional practice: Health data
4. Branching
4.1 If-else branches (general)
4.2 Detecting equal values with branches
4.3 Detecting ranges with branches (general)
4.4 Detecting ranges with branches
4.5 Detecting ranges using logical operators
4.6 Detecting ranges with gaps
4.7 Detecting multiple features with branches
4.8 Comparing data types and common errors
4.9 Membership and identity operators
4.10 Order of evaluation
4.11 Code blocks and indentation
4.12 Conditional expressions
4.13 Additional practice: Tweet decoder
5. Loops
5.1 Loops (general)
5.2 While loops
5.3 More while loop examples
5.4 Counting
5.5 For loops
5.6 Counting using the range() function
5.7 While vs. for loops
5.8 Nested loops
5.9 Developing programs incrementally
5.10 Break and continue
5.11 Loop else
5.12 Getting both index and value when looping: enumerate()
5.13 Additional practice: Dice statistics
6. Functions
6.1 User-defined function basics
6.2 Print functions
6.3 Dynamic typing
6.4 Reasons for defining functions
6.5 Writing mathematical functions
6.6 Function stubs
6.7 Functions with branches/loops
6.8 Functions are objects
6.9 Functions: Common errors
6.10 Scope of variables and functions
6.11 Namespaces and scope resolution
6.12 Function arguments
6.13 Keyword arguments and default parameter values
6.14 Arbitrary argument lists
6.15 Multiple function outputs
6.16 Help! Using docstrings to document functions
6.17 Engineering examples
7. Strings
7.1 String slicing
7.2 Advanced string formatting
7.3 String methods
7.4 Splitting and joining strings
8. Lists and Dictionaries
8.1 Lists
8.2 List methods
8.3 Iterating over a list
8.4 List games
8.5 List nesting
8.6 List slicing
8.7 Loops modifying lists
8.8 List comprehensions
8.9 Sorting lists
8.10 Command-line arguments
8.11 Additional practice: Engineering examples
8.12 Dictionaries
8.13 Dictionary methods
8.14 Iterating over a dictionary
8.15 Dictionary nesting
9. Classes
9.1 Classes: Introduction
9.2 Classes: Grouping data
9.3 Instance methods
9.4 Class and instance object types
9.5 Class example: Seat reservation system
9.6 Class constructors
9.7 Class interfaces
9.8 Class customization
9.9 More operator overloading: Classes as numeric types
9.10 Memory allocation and garbage collection
10. Exceptions
10.1 Handling exceptions using try and except
10.2 Multiple exception handlers
10.3 Raising exceptions
10.4 Exceptions with functions
10.5 Using finally to clean up
10.6 Custom exception types
11. Modules
11.1 Modules
11.2 Finding modules
11.3 Importing specific names from a module
11.4 Executing modules as scripts
11.5 Reloading modules
11.6 Packages
11.7 Standard library
12. Files
12.1 Reading files
12.2 Writing files
12.3 Interacting with file systems
12.4 Binary data
12.5 Command-line arguments and files
12.6 The “with” statement
12.7 Comma separated values files
13. Inheritance
13.1 Derived classes
13.2 Accessing base class attributes
13.3 Overriding class methods
13.4 Is-a versus has-a relationships
13.5 Mixin classes and multiple inheritance
13.6 Testing your code: The unittest module
14. Recursion
14.1 Recursive functions
14.2 Recursive algorithm: Search
14.3 Adding output statements for debugging
14.4 Creating a recursive function
14.5 Recursive math functions
14.6 Recursive exploration of all possibilities
15. Python for Data Science
15.1 Introduction to data science
15.2 Data science life cycle
15.3 Introduction to Python for data science
15.4 Introduction to Jupyter Notebooks
15.5 NumPy
15.6 pandas
15.7 Matplotlib
16. Searching and Sorting Algorithms
16.1 Searching and algorithms
16.2 Binary search
16.3 O notation
16.4 Algorithm analysis
16.5 Sorting: Introduction
16.6 Selection sort
16.7 Insertion sort
16.8 Quicksort
16.9 Merge sort
17. Additional Material
17.1 String formatting using %
17.2 String formatting using format()
17.3 String formatting using dictionaries
17.4 Basic graphics
17.5 zyBooks built-in programming window
Teach Python with this hands-on, interactive zyBook with zyLabs
Programming in Python 3 is a comprehensive introduction to the principles and practice of Python programming, based on the latest standards.
What is a zyBook?
Programming with Python 3 is a web-native, interactive zyBook that helps students visualize concepts to learn faster and more effectively than with a traditional textbook. Check out our research.
Since 2012, over 1,800 academic institutions have adopted digital zyBooks to transform their STEM education.
zyBooks benefits both students and instructors:
What is a zyLab?
See the capabilities of the zyBooks programming environment
Author
Bailey Miller
Computer Science PhD, University of California, Riverside
Instructors: Interested in evaluating this zyBook for your class?
Check out these related zyBooks
Python for Everyone
in All, Computer Science, CS1/2/3/by Harris SalatTable of Contents
1. Introduction
1.1 Computer Programs
1.2 The Anatomy of a Computer
1.3 Computing and Society: Computers Are Everywhere
1.4 The Python Programming Language
1.5 Becoming Familiar with Your Programming Environment
1.6 Special Topic: The Python Interpreter
1.7 Analyzing Your First Program
1.8 Errors
1.9 Problem Solving: Algorithm Design
1.10 Computing and Society: Data Is Everywhere
1.11 How To: Describing an Algorithm with Pseudocode
1.12 Worked Example: Writing an Algorithm for Tiling a Floor
1.13 Chapter Summary
1.14 Interactive Practice: Computer Programs
1.15 Interactive Practice: The Anatomy of a Computer
1.16 Interactive Practice: The Python Programming Language
1.17 Interactive Practice: The Programming Environment
1.18 Interactive Practice: First Programs
1.19 Interactive Practice: Errors
1.20 Interactive Practice: Algorithm Design
1.21 Review Exercises
1.22 Programming Projects
2. Programming with Numbers and Strings
2.1 Variables
2.2 Arithmetic
2.3 Special Topic: Other Ways to Import Modules
2.4 Special Topic: Combining Assignment and Arithmetic
2.5 Special Topic: Line Joining
2.6 Problem Solving: First Do It By Hand
2.7 Worked Example: Computing Travel Time
2.8 Strings
2.9 Special Topic: Character Values
2.10 Special Topic: Escape Sequences
2.11 Computing and Society: International Alphabets and Unicode
2.12 Input and Output
2.13 How To: Writing Simple Programs
2.14 Worked Example: Computing the Cost of Stamps
2.15 Computing and Society: Bugs in Silicon
2.16 Graphics: Simple Drawings
2.17 How To: Graphics: Drawing Graphical Shapes
2.18 Toolbox: Symbolic Processing with SymPy
2.19 Chapter Summary
2.20 Interactive Practice: Variables
2.21 Interactive Practice: Arithmetic
2.22 Interactive Practice: First Do It By Hand
2.23 Interactive Practice: Strings
2.24 Interactive Practice: Input and Output
2.25 Interactive Practice: Simple Drawings
2.26 Review Exercises
2.27 Programming Projects
3. Decisions
3.1 The if Statement
3.2 Special Topic: Conditional Expressions
3.3 Relational Operators
3.4 Special Topic: Lexicographic Ordering of Strings
3.5 How To: Implementing an if Statement
3.6 Worked Example: Extracting the Middle
3.7 Nested Branches
3.8 Computing and Society: Dysfunctional Computerized Systems
3.9 Multiple Alternatives
3.10 Toolbox: Sending E-mail
3.11 Problem Solving: Flowcharts
3.12 Problem Solving: Test Cases
3.13 Boolean Variables and Operators
3.14 Special Topic: Chaining Relational Operators
3.15 Special Topic: Short-Circuit Evaluation of Boolean Operators
3.16 Special Topic: De Morgan’s Law
3.17 Analyzing Strings
3.18 Application: Input Validation
3.19 Special Topic: Terminating a Program
3.20 Special Topic: Interactive Graphical Programs
3.21 Computing and Society: Artificial Intelligence
3.22 Worked Example: Graphics: Intersecting Circles
3.23 Toolbox: Plotting Simple Graphs
3.24 Chapter Summary
3.25 Interactive Practice: The if Statement
3.26 Interactive Practice: Relational Operators
3.27 Interactive Practice: Nested Branches
3.28 Interactive Practice: Multiple Alternatives
3.29 Interactive Practice: Flowcharts
3.30 Interactive Practice: Test Cases
3.31 Interactive Practice: Boolean Variables and Operators
3.32 Interactive Practice: Analyzing Strings
3.33 Interactive Practice: Input Validation
3.34 Review Exercises
3.35 Programming Projects
4. Loops
4.1 The while Loop
4.2 Special Topic: Special Form of the print Function
4.3 Computing and Society: The First Bug
4.4 Problem Solving: Hand-Tracing
4.5 Application: Processing Sentinel Values
4.6 Special Topic: Processing Sentinel Values with a Boolean Variable
4.7 Special Topic: Redirection of Input and Output
4.8 Problem Solving: Storyboards
4.9 Common Loop Algorithms
4.10 The for Loop
4.11 How To: Writing a Loop
4.12 Nested Loops
4.13 Worked Example: Average Exam Grades
4.14 Worked Example: A Grade Distribution Histogram
4.15 Processing Strings
4.16 Application: Random Numbers and Simulations
4.17 Worked Example: Graphics: Bull’s Eye
4.18 Graphics: Digital Image Processing
4.19 Problem Solving: Solve a Simpler Problem First
4.20 Computing and Society: Digital Piracy
4.21 Chapter Summary
4.22 Interactive Practice: The while Loop
4.23 Interactive Practice: Hand Tracing
4.24 Interactive Practice: Processing Sentinel Values
4.25 Interactive Practice: Storyboards
4.26 Interactive Practice: Common Loop Algorithms
4.27 Interactive Practice: The for Loop
4.28 Interactive Practice: Nested Loops
4.29 Interactive Practice: Processing Strings
4.30 Interactive Practice: Random Numbers and Simulations
4.31 Interactive Practice: Digital Image Processing
4.32 Interactive Practice: Solve a Simpler Problem First
4.33 Review Exercises
4.34 Programming Projects
5. Functions
5.1 Functions as Black Boxes
5.2 Implementing and Testing Functions
5.3 Parameter Passing
5.4 Return Values
5.5 Special Topic: Using Single-Line Compound Statements
5.6 How To: Implementing a Function
5.7 Worked Example: Generating Random Passwords
5.8 Functions Without Return Values
5.9 Computing and Society: Personal Computing
5.10 Problem Solving: Reusable Functions
5.11 Problem Solving: Stepwise Refinement
5.12 Worked Example: Calculating a Course Grade
5.13 Worked Example: Using a Debugger
5.14 Variable Scope
5.15 Worked Example: Graphics: Rolling Dice
5.16 Graphics: Building an Image Processing Toolkit
5.17 Worked Example: Plotting Growth or Decay
5.18 Recursive Functions
5.19 How To: Thinking Recursively
5.20 Toolbox: Turtle Graphics
5.21 Chapter Summary
5.22 Interactive Practice: Functions as Black Boxes
5.23 Interactive Practice: Implementing and Testing Functions
5.24 Interactive Practice: Parameter Passing
5.25 Interactive Practice: Return Values
5.26 Interactive Practice: Functions Without Return Values
5.27 Interactive Practice: Reusable Functions
5.28 Interactive Practice: Stepwise Refinement
5.29 Interactive Practice: Variable Scope
5.30 Interactive Practice: Building an Image Processing Toolkit
5.31 Interactive Practice: Recursive Functions
5.32 Review Exercises
5.33 Programming Projects
6. Lists
6.1 Basic Properties of Lists
6.2 Special Topic: Negative Subscripts
6.3 Special Topic: Common Container Functions
6.4 Computing and Society: Computer Viruses
6.5 List Operations
6.6 Special Topic: Slices
6.7 Common List Algorithms
6.8 Worked Example: Plotting Trigonometric Functions
6.9 Using Lists with Functions
6.10 Special Topic: Call by Value and Call by Reference
6.11 Special Topic: Tuples
6.12 Special Topic: Functions with a Variable Number of Arguments
6.13 Special Topic: Tuple Assignment
6.14 Special Topic: Returning Multiple Values with Tuples
6.15 Toolbox: Editing Sound Files
6.16 Problem Solving: Adapting Algorithms
6.17 How To: Working with Lists
6.18 Worked Example: Rolling the Dice
6.19 Problem Solving: Discovering Algorithms by Manipulating Physical Objects
6.20 Tables
6.21 Worked Example: A World Population Table
6.22 Special Topic: Tables with Variable Row Lengths
6.23 Worked Example: Graphics: Drawing Regular Polygons
6.24 Chapter Summary
6.25 Interactive Practice: Basic Properties of Lists
6.26 Interactive Practice: List Operations
6.27 Interactive Practice: Common List Algorithms
6.28 Interactive Practice: Using Lists with Functions
6.29 Interactive Practice: Adapting Algorithms
6.30 Interactive Practice: Discovering Algorithms
6.31 Interactive Practice: Tables
6.32 Review Exercises
6.33 Programming Projects
7. Files and Exceptions
7.1 Reading and Writing Text Files
7.2 Text Input and Output
7.3 Special Topic: Reading the Entire File
7.4 Special Topic: Regular Expressions
7.5 Special Topic: Character Encodings
7.6 Toolbox: Working with CSV Files
7.7 Command Line Arguments
7.8 How To: Processing Text Files
7.9 Worked Example: Analyzing Baby Names
7.10 Toolbox: Working with Files and Directories
7.11 Computing and Society: Encryption Algorithms
7.12 Binary Files and Random Access
7.13 Worked Example: Graphics: Displaying a Scene File
7.14 Exception Handling
7.15 Special Topic: The with Statement
7.16 Toolbox: Reading Web Pages
7.17 Application: Handling Input Errors
7.18 Toolbox: Statistical Analysis
7.19 Worked Example: Creating a Bubble Chart
7.20 Computing and Society: The Ariane Rocket Incident
7.21 Chapter Summary
7.22 Interactive Practice: Text Files
7.23 Interactive Practice: Text Input and Output
7.24 Interactive Practice: Command Line Arguments
7.25 Interactive Practice: Binary Files
7.26 Interactive Practice: Exception Handling
7.27 Interactive Practice: Handling Input Errors
7.28 Review Exercises
7.29 Programming Projects
8. Sets and Dictionaries
8.1 Sets
8.2 Worked Example: Counting Unique Words
8.3 Special Topic: Hashing
8.4 Computing and Society: Standardization
8.5 Dictionaries
8.6 Special Topic: Iterating over Dictionary Items
8.7 Special Topic: Storing Data Records
8.8 Worked Example: Translating Text Messages
8.9 Complex Structures
8.10 Special Topic: User Modules
8.11 Worked Example: Graphics: Pie Charts
8.12 Toolbox: Harvesting JSON Data from the Web
8.13 Chapter Summary
8.14 Interactive Practice: Sets
8.15 Interactive Practice: Dictionaries
8.16 Interactive Practice: Complex Structures
8.17 Review Exercises
8.18 Programming Projects
9. Objects and Classes
9.1 Object-Oriented Programming
9.2 Implementing a Simple Class
9.3 Specifying the Public Interface of a Class
9.4 Designing the Data Representation
9.5 Constructors
9.6 Special Topic: Default and Named Arguments
9.7 Implementing Methods
9.8 Special Topic: Class Variables
9.9 Testing a Class
9.10 How To: Implementing a Class
9.11 Worked Example: Implementing a Bank Account Class
9.12 Problem Solving: Tracing Objects
9.13 Problem Solving: Patterns for Object Data
9.14 Object References
9.15 Computing and Society: Electronic Voting
9.16 Application: Writing a Fraction Class
9.17 Special Topic: Object Types and Instances
9.18 Worked Example: Graphics: A Die Class
9.19 Computing and Society: Open Source and Free Software
9.20 Chapter Summary
9.21 Interactive Practice: Object-Oriented Programming
9.22 Interactive Practice: Implementing a Simple Class
9.23 Interactive Practice: Specifying the Public Interface
9.24 Interactive Practice: Designing the Data Representation
9.25 Interactive Practice: Constructors
9.26 Interactive Practice: Implementing Methods
9.27 Interactive Practice: Testing a Class
9.28 Interactive Practice: Tracing Objects
9.29 Interactive Practice: Patterns for Object Data
9.30 Interactive Practice: Object References
9.31 Interactive Practice: Writing a Fraction Class
9.32 Review Exercises
9.33 Programming Projects
10. Inheritance
10.1 Inheritance Hierarchies
10.2 Special Topic: The Cosmic Superclass: object
10.3 Implementing Subclasses
10.4 Calling the Superclass Constructor
10.5 Overriding Methods
10.6 Polymorphism
10.7 Special Topic: Subclasses and Instances
10.8 Special Topic: Dynamic Method Lookup
10.9 Special Topic: Abstract Classes
10.10 How To: Developing an Inheritance Hierarchy
10.11 Worked Example: Implementing an Employee Hierarchy for Payroll Processing
10.12 Application: A Geometric Shape Class Hierarchy
10.13 Toolbox: Game Programming
10.14 Chapter Summary
10.15 Interactive Practice: Inheritance Hierarchies
10.16 Interactive Practice: Implementing Subclasses
10.17 Interactive Practice: Calling the Superclass Constructor
10.18 Interactive Practice: Overriding Methods
10.19 Interactive Practice: Polymorphism
10.20 Interactive Practice: A Geometric Shape Class Hierarchy
10.21 Review Exercises
10.22 Programming Projects
11. Recursion
11.1 Triangle Numbers Revisited
11.2 Special Topic: Recursion with Objects
11.3 Problem Solving: Thinking Recursively
11.4 Worked Example: Finding Files
11.5 Recursive Helper Functions
11.6 The Efficiency of Recursion
11.7 Permutations
11.8 Computing and Society: The Limits of Computation
11.9 Backtracking
11.10 Worked Example: Towers of Hanoi
11.11 Mutual Recursion
11.12 Toolbox: Analyzing Web Pages with Beautiful Soup
11.13 Chapter Summary
11.14 Interactive Practice: Triangle Numbers Revisited
11.15 Interactive Practice: Thinking Recursively
11.16 Interactive Practice: Recursive Helper Functions
11.17 Interactive Practice: The Efficiency of Recursion
11.18 Interactive Practice: Permutations
11.19 Interactive Practice: Backtracking
11.20 Interactive Practice: Mutual Recursion
11.21 Review Exercises
11.22 Programming Projects
12. Sorting and Searching
12.1 Selection Sort
12.2 Profiling the Selection Sort Algorithm
12.3 Analyzing the Performance of the Selection Sort Algorithm
12.4 Special Topic: Oh, Omega, and Theta
12.5 Special Topic: Insertion Sort
12.6 Merge Sort
12.7 Analyzing the Merge Sort Algorithm
12.8 Special Topic: The Quicksort Algorithm
12.9 Computing and Society: The First Programmer
12.10 Searching
12.11 Problem Solving: Estimating the Running Time of an Algorithm
12.12 Special Topic: Comparing Objects
12.13 Worked Example: Enhancing the Insertion Sort Algorithm
12.14 Chapter Summary
12.15 Interactive Practice: Selection Sort
12.16 Interactive Practice: Profiling Selection Sort
12.17 Interactive Practice: Analyzing Selection Sort
12.18 Interactive Practice: Merge Sort
12.19 Interactive Practice: Analyzing Merge Sort
12.20 Interactive Practice: SearchingNEC
12.21 Interactive Practice: Estimating Running Times
12.22 Review Exercises
12.23 Programming Projects
13. XML
13.1 XML Tags and Documents
13.2 How To: Designing an XML Document Format
13.3 Parsing XML Documents
13.4 Creating XML Documents
13.5 How To: Writing an XML Document
13.6 Special Topic: Grammars, Parsers, and Compilers
13.7 Validating XML Documents
13.8 How To: Writing a DTD
13.9 Special Topic: Schema Languages
13.10 Special Topic: Other XML Technologies
13.11 Chapter summary
13.12 Review Exercises
13.13 Practice Exercises
13.14 Programming Projects
The interactive zyBooks version of a classic introduction to programming
The Python for Everyone zyVersion offers the complete contents of the 3rd edition of this popular textbook, plus new immersive activities and integrated live coding to help beginning programmers learn faster and more effectively.
Designed to serve a wide range of student interests and abilities, the book requires no prior programming experience.
Dr. Cay Horstmann discusses the benefits of teaching with zyBooks
What is a zyVersion?
zyVersions are leading print titles converted and adapted to zyBooks’ interactive learning platform, allowing for a quick and easy transition to an engaging digital experience for instructors and students.
zyBooks’ web-native content helps students visualize concepts to learn faster and more effectively than with a traditional textbook. (Check out our research.)
This zyVersion of Python for Everyone benefits both students and instructors:
The Python for Everyone zyVersion in action
In this video, coauthor Rance Necaise demonstrates how Jupyter Notebooks and other embedded tools advance learning:
Authors
Cay Horstmann, PhD
Professor of Computer Science, San Jose State University
Rance Necaise, PhD
Associate Professor of Computer Science, Randolph-Macon College
Instructors: Interested in evaluating this zyBook for your class?
Check out these related zyBooks
Programming in C
in All, Computer Science, CS1/2/3/by Ricky PorcoTable of Contents
1. Introduction to C
1.1 Programming (general)
1.2 Programming basics
1.3 Comments and whitespace
1.4 Errors and warnings
1.5 Computers and programs (general)
1.6 Integrated development environment
1.7 Computer tour
1.8 Language history
1.9 Problem solving
1.10 Why programming
1.11 Why whitespace and precision matter
1.12 C example: Salary calculation
1.13 C example: Married-couple names
2. Variables / Assignments
2.1 Variables and assignments (general)
2.2 Variables (int)
2.3 Identifiers
2.4 Arithmetic expressions (general)
2.5 Arithmetic expressions (int)
2.6 Example: Health data
2.7 Floating-point numbers (double)
2.8 Scientific notation for floating-point literals
2.9 Constant variables
2.10 Using math functions
2.11 Integer division and modulo
2.12 Type conversions
2.13 Binary
2.14 Characters
2.15 Strings
2.16 Integer overflow
2.17 Numeric data types
2.18 Unsigned
2.19 Random numbers
2.20 The printf and scanf functions
2.21 Debugging
2.22 Style guidelines
2.23 C example: Salary calculation with variables
2.24 C example: Married-couple names with variables
3. Branches
3.1 If-else branches (general)
3.2 Detecting equal values with branches
3.3 Detecting ranges with branches (general)
3.4 Detecting ranges with branches
3.5 Detecting ranges using logical operators
3.6 Detecting ranges with gaps
3.7 Detecting multiple features with branches
3.8 Common branching errors
3.9 Example: Toll calculation
3.10 Oder of evaluation
3.11 Switch statements
3.12 Boolean data type
3.13 String comparisons
3.14 String access operations
3.15 Character operations
3.16 Conditional expressions
3.17 Floating-point comparison
3.18 Short circuit evaluation
3.19 C example: Salary calculation with branches
3.20 C example: Search for name using branches
4. Loops
4.1 Loops (general)
4.2 While loops
4.3 More while examples
4.4 For loops
4.5 More for loop examples
4.6 Loops and strings
4.7 Nested loops
4.8 Developing programs incrementally
4.9 Break and continue
4.10 Variable name scope
4.11 Enumerations
4.12 C example: Salary calculation with loops
4.13 C example: Domain name validation with loops
5. Arrays / Vectors
5.1 Array/vector concept (general)
5.2 Vectors
5.3 Array iteration drill
5.4 Iterating through vectors
5.5 Multiple arrays
5.6 Swapping two variables (general)
5.7 Loop-modifying or copying/comparing arrays
5.8 Debugging example: Reversing an array
5.9 Two-dimensional arrays
5.10 Char arrays / C strings
5.11 String library functions
5.12 Char library functions: ctype
5.13 Arrays and strings
5.14 C example: Annual salary tax rate calculation with arrays
5.15 C example: Domain name validation with arrays
6. User-Defined Functions
6.1 User-defined function basics
6.2 Print functions
6.3 Reasons for defining functions
6.4 Writing mathematical functions
6.5 Functions with branches
6.6 Functions with loops
6.7 Unit testing (functions)
6.8 How functions work
6.9 Functions: Common errors
6.10 Pass by pointer
6.11 Functions with array parameters
6.12 Functions with C string parameters
6.13 Functions with array parameters: Common errors
6.14 Scope of variable/function definitions
6.15 Parameter error checking
6.16 Preprocessor and include
6.17 Separate files
6.18 C example: Salary calculation with functions
6.19 C example: Domain name validation with functions
7. Structs
7.1 Grouping data: struct
7.2 Structs and functions
7.3 Structs and arrays
7.4 Structs, arrays, and functions: A seat reservation example
7.5 Separate files for structs
8. Pointers
8.1 Why pointers: Pass by pointer example
8.2 Pointer basics
8.3 The malloc and free functions
8.4 Pointers with structs
8.5 String functions with pointers
8.6 The malloc function for arrays and strings
8.7 The realloc function
8.8 Vector ADT
8.9 Why pointers: A list example
8.10 A first linked list
8.11 Memory regions: Heap/Stack
8.12 Memory leaks
8.13 C example: Employee list using vector ADT
9. Input / Output
9.1 The stdout and stdin file pointers
9.2 Output formatting
9.3 Input parsing
9.4 File input and output
10. Recursion
10.1 Recursion: Introduction
10.2 Recursive functions
10.3 Recursive algorithm: Search
10.4 Adding output statements for debugging
10.5 Creating a recursive function
10.6 Recursive math functions
10.7 Recursive exploration of all possibilities
10.8 Stack overflow
10.9 C example: Recursively output permutations
11. Searching and Sorting Algorithms
11.1 Searching and algorithms
11.2 Binary search
11.3 O notation
11.4 Algorithm analysis
11.5 Sorting: Introduction
11.6 Selection sort
11.7 Insertion sort
11.8 Quicksort
11.9 Merge sort
12. Additional Material
12.1 Do-while loops
12.2 Engineering examples
12.3 Command-line arguments
12.4 The #define directive
12.5 Compiling and running a program using a command-line interface
12.6 Modular compilation
12.7 Makefiles
12.8 Binary file I/O
12.9 Engineering examples using functions
12.10 Command-line arguments and files
12.11 Additional practice: Output art
12.12 Additional practice: Grade calculation
12.13 Additional practice: Abbreviation decoder
12.14 Additional practice: Dice statistics
12.15 zyBooks built-in programming window
Teach C with this hands-on, interactive zyBook with zyLabs
Programming in C is a comprehensive introduction to the foundational principles and practice of C programming, based on the latest standards.
What is a zyBook?
Programming in C is a web-native, interactive zyBook that helps students visualize concepts to learn faster and more effectively than with a traditional textbook. Check out our research.
Since 2012, over 1,800 academic institutions have adopted digital zyBooks to transform their STEM education.
zyBooks benefits both students and instructors:
What is a zyLab?
See the capabilities of the zyBooks programming environment
Authors
Frank Vahid
Computer Science PhD, Univ. of California, Irvine / zyBooks Co-Founder
Roman Lysecky
Professor Emeritus of Electrical and Computer Engineering, Univ. of Arizona
Instructors: Interested in evaluating this zyBook for your class?