10. Review and exam 2

Review Topics

General Information


  • Make sure you follow along with this page linked in Canvas
  • Please keep your microphone off unless you are asking a question
  • Please turn on camera if you can (optional)
  • Use chat if you would like to comment or ask questions


See Announcements link in Canvas to keep up with what is going on. Here are a few for review:

Exam Help

10.1: Exam 2 Preparation

  • You must attend the exam at the scheduled time or you will receive a score of zero (0)
    • Except for unforeseeable emergency and justifiable reasons
  • Be on time as you can only work on the exam during the scheduled time
  • The exam covers material from the first 9 weeks
  • Exam question types include multiple choice, short answer, and programming problems
    • See practice exam for examples
  • We will take the test in Canvas using the LockDown Browser.
  • Make sure you have completed the Pre-Exam 2 Computer Check in Canvas

10.1.1: Administration and Exam Rules

  • Use restroom before starting the exam. Leaving exam means you are done.
  • Exam length is about 45 minutes.
  • Exam is closed books, closed homework, and closed notes except one 3" x 5" card of handwritten notes.
  • Exam work area must be clear: only a computer, 3" x 5" card, and one sheet of blank scratch paper.
  • Your exam computer must have the LockDown Browser installed for the exam
    • Verify your computer with the Pre-Exam 2 Computer Check quiz
  • We will start the exam in a Zoom room to answer questions, verify 3x5 cards and scratch paper, and position phones
  • Join the Zoom room using your cell phone--not your computer
    • Zoom tends to crash some computers during exams
    • Install the Canvas and Zoom apps on your phone
  • No computer applications open except the LockDown Browser.
  • Must NOT use the computer to:
    1. View documents on the Internet
    2. Look at pre-existing code
    3. Open documents of any kind
    4. Send messages to anyone but the instructor (instructor via Zoom chat)
  • No devices near work area including but not limited to earbuds, headphones, or cell phones, except for one cell phone positioned for Zoom call.
    • Touching a cell phone during the exam == automatic fail
    • The exam includes a built-in calculator
  • Other allowed computer uses are entering, compiling and running code using an online compiler provided in the exam.
    • Cannot use any other compiler or editor except the one provided
  • Start the exam with the LockDown Browser
  • Must NOT communicate with anyone but the instructor during the exam
    • Find a separate room or space for the exam if possible
    • Make certain other people in your home know not to disturb you during the exam
    • Students are responsible for not invading third party privacy rights with their webcam or phone
  • Send questions or other messages to the instructor during the test via Zoom chat

About Compiling

  • Code that does not compile contains an error
  • When given the tools to compile, your code must compile for a good score
  • Expect a substantial penalty if your code does not compile
  • Also expect to lose points for every error in the code
  • If you are having problems compiling, comment out the parts that do not compile
  • Partial credit is available if you comment out your problem code

3"x 5" Card Requirements

  • Put your name on your card
  • Maximum card or paper size is 3 inches by 5 inches
  • You may use both sides of the card
  • Notes must be handwritten and NOT photocopied
  • No more than three statements in a code sequence on the card — only snippets
  • Any 3" x 5" cards violating these rules will be denied use before the exam

About Audio and Video

  • In normal class meeting I do not require audio or video.
  • However, the test is not a normal class meeting
  • Audio and video are required during the test
  • Students are responsible for selecting private spaces for testing
  • Students must ensure that any recordings do not invade the privacy rights of any third party

10.1.2: Test Preparation Resources

You have many resources to help you review and prepare for the exam as shown below.

  1. Textbook
    • Table of contents: expand and review the sections for each chapter to locate information
    • Search: type in keywords to find topics, click links and search in the page
    • Participation Activities (PAs): Review the PAs as needed to refresh your memory of concepts
    • Challenge Activities (CAs): Verify you know how to write the code snippets
  2. Lesson notes
    • Instructor's notes: review and expansion of textbook topics
    • In-class exercises: review the practice problems we worked on during class
    • Your notes: written down before, during or after class
  3. Lab projects
    • Review the lab projects completed each week
    • Instructor project solutions (in Canvas)
  4. Practice exam questions in Canvas
  5. Instructor, SI and tutors: ask questions
    • Student hours: see Canvas Home page
    • SI study sessions
    • Q & A discussion
    • Email
    • CS tutoring hours: (see Homework Help above)
  6. 3x5 Reference card

3"x 5" Card Requirements

  • Maximum card (or paper) size is 3 inches by 5 inches
  • You may use both sides of the card
  • Notes must be handwritten and NOT printed or photocopied
  • No more than three statements in a code sequence on the card — only snippets
  • Any 3" x 5" cards violating these rules will be denied use before the exam
  • If uncertain, email me a question about or photo of the card before the exam

Exam Stress

Do you:

  • Feel stressed about exams
  • Feel your heart pounding or breath quickening
  • Feel doubt you will do well on the exam
  • Avoid studying for the exam
  • Delay taking practice exams

Stress Benefits

  • Research shows stress can be good for you
  • Heart pounding and breath quickening means your body is giving you more energy
  • Tension means your body is giving you more strength
  • Stress can improve your performance on exams
  • The key to making stress work for you is your mindset towards stress

Harnessing Stress

  • Worry less about making feelings of stress go away
  • Tell yourself you are feeling excited or invigorated instead of anxious
  • Focus on what you are going to do with your increased energy, strength and drive
  • Put the energy to use to better prepare for the exam
  • Review notes and questions, prepare your own questions and take the practice exam--multiple times
  • Prepare that 3x5 card

Exercise 10.1: Reviewing Exam Questions

The lab for today was to Take the practice exam multiple times and attempt to complete it perfectly (100% correct including code).

Arranging the Reviews

  • For the review, the instructor will create a breakout room.
  • If you would like to be among the first called, put your name in Chat when prompted
  • You will be in a waiting room and invited in for instructor review one project at a time.
  • Continue to work on your practice exam, Lab 10.2XC project, or other projects, while waiting
  • If you miss your turn, rejoin the meeting to get added back to the queue

During the Review

  • The instructor will review each student's practice exam for 3-4 minutes each with the student
  • When finished with the review, you are free to leave the meeting

10.2: Unit testing functions

Testing is the process of checking whether a program behaves correctly. Now that our code is organized into functions, we can test the code one function at a time.

10.2.1: Reviewing unit testing

  • Unit testing is the process of individually testing a small part or unit of a program
  • Typically we test the code one function at a time
  • Consider the following function:
    int add(int a, int b) {
        int sum = a + b;
        return sum;
  • The function adds two numbers together and returns their sum
  • What code do we need to test this function?

Starting our test harness

  • Before we can test our function, our program must first compile
  • To make a program with this function compile we must add a main() function
  • We start Replit and notice we already have a main() function
  • All we need to add to the code is our function and then we can compile
  • If we do not want to write std:: in front of every cout then we add to the top:
    using namespace std;

Testing a function

  • To test the function, we must call the function
  • For example, we may call our function with:
    add(2, 3);
  • However, calling the function does not assure us that the function performs as intended
  • For that we need to see if the function returns the intended value
  • What value should the above call return?

Checking the returned value

  • One way to test the returned value is to print it to the terminal window
  • Then we can visually verify the returned value is correct
    cout << add(2, 3) << endl;
  • We see that the function returns 5 and now it has passed our first test
  • We finish the testing process by adding additional tests

Exercise 10.2: Unit testing a function (10m)

In this exercise we explore unit testing a function.

For this exercise we break into teams. Within the team, work with each other to develop a solution. When the team has finished, choose one member to show your solution to the class by sharing your screen. The instructor will ask one team to share their solution.


  1. Start Replit and copy the following code into the code editor.
    int add(int a, int b) {
        int sum = a + b;
        return sum;
  2. Compile your code to make sure you added the code correctly.
  3. Now add four different test cases by calling the function from main. For example, here is main() after adding one test:
    int main() {
        cout << add(2, 3) << endl;
        return 0;
  4. Verify the output after each test.

When finished developing your code click hereClick to show answer to verify. Code need not look exactly the same. After you have completed your own program, reviewing another is often helpful in learning how to improve your programming skills.


Last Updated: April 06 2021 @18:22:09