First-time coders
C++ Basics
- 30 lessons
- About 60 minutes per lesson
Compile and run your first C++ program, then learn input and output, decisions, loops, strings and vectors. Finish by building a command-line program that reads scores and prints a report.
View the syllabus
What you’ll be able to do
- Compile and run a program, then read numbers and text in a specified format.
- Process a batch of data with decisions, loops and vectors.
- Separate reading, aggregation and output into functions and check edge cases.
Course syllabus
Open a module for the lesson breakdown, a worked example and an assignment.
Lessons 1–5 Compilation, variables and I/O
Work through the complete path from source code to program output.
- Compile a program with main and print a line with cout.
- Compare what int, double and string are used to store.
- Read integers with cin and verify input order.
- Compare integer division, remainder and floating-point division.
- Read compiler diagnostics for a missing semicolon or a type mismatch.
Lessons 6–10 Decisions, loops and state
Classify one input, then apply the rule to a whole batch.
- Use if/else to classify a score and check the equality boundary.
- Write score bands with else if and check their order.
- Use for to process a given number of scores.
- Use while to read until a -1 sentinel and exclude it from the data.
- Count passes and check all-pass, all-fail and empty batches.
Lessons 11–15 Strings and vectors
Store and scan a batch of data, with attention to indexes and bounds.
- Store a word in string and iterate through its characters.
- Compare token extraction with cin and line input with getline.
- Use vector and push_back to store an unknown number of values.
- Use indexes and range-for to compute a total and maximum.
- Check an empty vector, a single element and the last valid index.
Lessons 16–20 Functions, argument passing and debugging
Split the program into steps and verify each function’s inputs and return value.
- Write a function with parameters and a return value.
- Compare local variables with variables in the caller.
- Compare passing by value with a read-only const reference.
- Call an aggregation function directly with fixed inputs.
- Use a minimal failing test to locate an incorrect loop bound.
Lessons 21–25 Sorting and basic statistics
Order a batch and explain it with totals, maximums and means.
- Sort a vector in ascending order with std::sort.
- Locate minimum, maximum and middle positions in sorted results.
- Add large integer totals with long long.
- Convert to double and print the mean at the required precision.
- Check duplicate values, even-sized batches and empty input.
Lessons 26–30 Project: score report
Deliver a complete reporting program with tests from input to formatted output.
- Specify the batch size, pass mark and report fields.
- Read the scores and implement maximum and count functions.
- Add the mean and handle empty batches before division.
- Check the exact output format against fixtures.
- Submit source, compilation instructions and three tests.
A sample exercise
Read 17 cards and give out sets of 5. Print the number of complete sets and the remainder.
See the worked example →Common questions
What is the first lesson?
Compile a program with main and print a line with cout. · Compilation, variables and I/O
How can I check my progress?
Submit a score-report tool that reads a batch and reports the maximum, pass count and mean. Show how it handles an empty batch, the exact pass mark and integer division.