Introduction to C++

Module 0



All Checkpoints in this section are on GitHub Classroom. A GitHub Classroom tutorial is available here.

If your instructor has given you an assignment link for the practice code, use that to access the practice activities.

Topic Checkpoints
Hello World! (compiling, executing, printing) [Lecture Video, Slides] Hello World
Operators and Variables [Lecture Video, Slides] Mathler
Practice (optional) [GitHub link]
Functions [Lecture Video, Slides] Practice (optional) [GitHub link]
Branching and Iterators [Lecture Video, Slides] Calculator Operation
Practice (optional) [GitHub link]
Vectors and Structs [Lecture Video, Slides] Practice (optional) [GitHub link]

Programming in C++

The recommended workflow is to set up your computer to compile C++ code. Here is a guide to set up your machine:

Follow the appropriate guide for your computer.

Guides & Tutorials

The following guides and tutorials will be helpful for completing the checkpoints for this module and Project 0.

  1. GitHub Tutorial: We will use GitHub to manage all the code you will be submitting for this course.
  2. GitHub Classroom Tutorial: We use GitHub Classroom to manage code templates and autograder tests.


[Module 0 Checkpoint Templates]

Note: If you are registered in an offering of HelloRob, do not use this template directly! Your course staff will give you a GitHub Classroom assignment link to accept the assignment. Otherwise, you will not get credit for the checkpoints.


Before your begin, follow the instructions in the computer setup guide.

For all these checkpoints, you will need to clone your repository for the Module 0 Checkpoints that was created when you accepted your class assignment. On your computer, open VSCode in a folder that you created to store all your HelloRob code. Then do:

git clone <ADDRESS>

Substitute <ADDRESS> with the address for your repo, found on GitHub. The instructions for getting the address are at the end of the GitHub Classroom tutorial on accepting assignments.

Hello, World!

Our first C++ program! Watch the first lecture to learn how to do this. Your code must compile and output the phrase “Hello, World!”

  • Compiling your code: To compile the Hello, World! code, first make sure you are inside the M0 Checkpoint repo you cloned. Then do:
    g++ hello_world.cpp -o hello_world
    To run it, do:
  • Write code in the file hello_world.cpp so that when you run it, it prints out "Hello, World!"


Remember Wordle? Mathler is one of its many cousins where the goal is to come up with an equation with a fixed number of charaters that is equal to a given number. Try it out!

In this checkpoint, we will practice using Variables and Operators by solving a Mathler! Your Mathler equation must be 8 characters including integers and operators, and equal to 46. Save the result of the equation to a variable. Print out the equation (no spaces!) an equal sign, and then the variable with the result.

For example, if the desired number was 13, a valid solution would print out:


Note that the string "1+4/2+10" is exactly 8 characters. "12+1" would not be a correct answer!

  • Write code in the file mathler.cpp which prints an equation as a string with 8 charaters then the result of that equation as an integer. The result must be 46.

No cheating! We will check that your equation actually gives the right result. Just printing out the number 46 will not pass the tests!

Calculator Operation

In this checkpoint, we will practice using branching to write a claculator that performs one single operation, and then exits.

The program should accept a number, then an operator (one of +, -, *, /), then another number. Then, it should print out the equation and the result. For example, if the user enters 100, then +, then 2, the program should print:

100 + 2 = 102
  • Write code in the file calc_op.cpp which accepts two numbers and an operator (one of `+`, `-`, `*`, `/`) from the user, then prints out the equation and the result.