Prerequisites

Examples

for loop

Create a for loop that counts from 0 to 10 by an increment of 1

for (int i = 0; int <= 10; int++) {
	cout << i << ", ";
	i++;
}

indefinite loop

What happens to this while loop code?

int i;
while (true) {
	cout << i << endl;
	i++;
}

Answer: The loop runs infinitely (indefinite)


multiple if statements inside an if

If I run this code, what happens?

// Checking divisibility by 2, 3, 5;
int y = 12;
 
if (y % 2 == 0) {
	cout << y << " is divisible by 2" << endl;
	if (y % 3 == 0) {
		cout << y << " is divisible by 3" << endl;
	}
}

Answer:

  • It passes through the first if statement if (y % 2 == 0) because 2 % 2 == 0, which makes the condition true
  • After the first if statement, it runs the code inside that if statement (lines 5-8).
    • Line 5: It prints 12 is divisible by 2
    • Line 6: it goes to the second if statement if (y % 3 == 0)
      • Since 12 % 2 == 0 is true, line 7 prints 12 is divisible by 3

Git sample problems

Commits alternative name

Professor Angelo refer commits as milestones (friendly version of calling them records for every change).

What are commits?

Commits are basically records about your changes that you made to the source file, which often includes a short commentary.

  • Initial commit is a commit message btw

Explain the diff (difference) changes in this file

Keynote

Explain the differences that are highlighted in bold

Example 1

Answer: Line 8 was modified when i = i + 2 is changed to i += 2 . A commentary was added after the first brace in {, which defined the similarity between i += 1 and i = i + 2

Example 2

Note: Even though the code is not in C++, you should be able to explain the code difference Answer:

  • In line 67 and 78, the description changed Presents a message to to Removes and with supplied message to disguises
  • In Line 70 and 81, target was replaced as otherPlayer.
  • In Line 71 and 82, target:SetAttribute("DisplayName", args[2]) was changed to otherPlayer:disguiseAsPlayer(0)

Understanding Interactive Code Rewind

preview

Commit

  • |< - Goes to the first commit of the current branch from the repository
  • < - Goes to the previous commit
  • > - Goes to the next commit
  • >| - Goes to the latest commit of the current branch

Git Checkout (if you see detached HEAD)

If you reached the latest commit (notice that >| is greyed out), you must checkout the git repository (simply means that you go back to the main branch, not commit_hash branch)

You will notice that commit_hash branch is just a branch with that only commit, not the main branch that has the latest commits of all source codes. It’s obvious when you see this on the bottom left of your Theia IDE:

How to time travel between commits (milestones)

Answer: Using the left/right arrow buttons to navigate between commits.


Freeform problem

Student Grades Logger

Write a C++ program that keeps track of current grade for a class:

  1. For each assignment, print out the grade received based on the number of points received and total points then store it.
    1. Make sure to ask the user for these values!!
    2. After knowing the number of points received and total points, print out the class grade
  2. If the user wants to finish logging, have them input -1 to end the logger loop
  3. Once the loop is ended, print out a message that says that the logger is done