CPSC 421-010 Object-Oriented Programming Spring 2026

Exercise 22: For Semantics II Posted: Feb 03

If you did not take the Exercise 8: For Statement Quiz nor do Exercise 17: For Semantics I, then you cannot do this exercise, as it is based on your work on the quiz.

In your for semantics repository is a file ForSemantics.cpp. It has a set of separate test cases with some setup, the code to evaluate, and an answer checked via an assert(), e.g.,

Each test case is in its own block statement to isolate its scope. The test cases are scenarios of using the original code from the quiz, followed by a test case with your individual answers. There are multiple scenarios for each example/answer from the quiz.

One special case is for Q3, which gave you macros (e.g., INCR) instead of the actual code. For that one, we used the preprocessing #define to make them into statements.

This is a non-standard use of preprocessing statements, so don't treat it as a general solution.

A CMake configuration is provided. So use the standard procedure to configure and build. There is no target run provided in the Makefile, so you will have to run the test program on the command line.

So your job is to:

You can only change what is between the // @START and // @END comments. Changes to any other places in the code will result in a 0 on the exercise.