Grace Hopper Center

CSC 222 Weekly Assignments: Week 16

CSC 222


Overview

This week we will take a break from our projects and return to our textbook, from where we left off at Chapter 13: Objects of vectors. Our goal is to complete this chapter and the next two by the end of the course.

I'll be out Friday, so we'll talk about our plan for that day when we meet on Wednesday.

Wednesday and Friday, December 17th and 19th

Classwork

During class today we will discuss the new ideas introduced in Chapter 13: Objects of vectors. Then we will use Chapter 13 Exercise Set 0: Introducing Make to setup our testing workflow.

We'll use the remainder of class time to complete several exercises from Chapter 13 Exercise Set 1: Chapter Review together, with the goal of getting you to the point where you can continue on your own for homework.

In class on Friday you can work on finishing the War! game using Chapter 13 Exercise Set 2: It's War! to help guide you.

Homework

Complete as much of Chapter 13 Exercise Set 1: Chapter Review as time permits.

For Friday, there is no homework! Have a wonderful, relaxing winter break!

Evaluation

I will be evaluating your git repos during the break for evidence of commits made during and between the last two class sessions.

Monday, December 15th

Classwork

Only two students showed up on Saturday. You will have two other opportunies to meet to review for the CPE: Saturday, January 10th and Saturday, January 17th from 9 am to 12 noon both days.

Delanie and Jeff spent what seemed to be way more time then they should have on understanding this practice problem:

What is the output of the program below?

#include <iostream>
using namespace std;

char f(char *cp) {
    *cp = *cp + 3;
    return (*cp)++;
}
char *g(char &ch) {
    ++ch;
    return &ch;
}
char h(char ch) {
    return ch++;
}
int main() {
    char ch = 'a';
    char ch2 = h(ch);
    cout << f(g(ch2)) << endl;
    return 0;
}

Working it out by hand, they both came up with g as the expected output, and it took them quite a while to understand why it was instead e. As the person who wrote this question in the first place, Jeff should have known better, but gradually encroaching senility means he gets to experience the thrill of learning these lessons anew each year.

When they finally figured it out, what they learned, and what even senile Jeff will not soon forget, could best be stated as a rule of thumb:

Don't ++ at the end of an expression in a return statement!

Take a look at 09_returnplusplus.cpp. Run it and observe what happens.

What is the moral of this tale? Well, I am now completely convinced that Delanie groks pointers in a way she didn't the last time she sat for the CPE, and I'll go out on a limb and predict that with the approach she is taking to prep, she will nail the CPE next time. Success in earning this certification requires a deep engagement with the C++ langauge, and that requires time. There's just no getting around it, which is why I'm making myself available on Saturdays and why I strongly encourage those of you who want to earn your certification to join me in January.

You'll have most of class time today to begin working on the homework assignment. Chapter 13 introduces several new ideas and it will require time to get through it.

Homework

Read Chapter 13: Objects of vectors, taking notes and trying out the examples in your git repos. This is due by Tuesday December 16th at 11:59 pm so that I can look them over early Wednesday morning before we meet for class.