CPSC 225: Intermediate Programming
Spring 2007

Instructor

Stina Bridgeman
bridgeman@hws.edu
Lansing 312, x3614

Course Description

This course continues the study of programming begun in CPSC 124. We switch to C++, a language widely used by professional programmers. C++ is similar to Java in many ways, but is a more complex language and offers many low-level features (such as direct manipulation of the computer's memory) that Java does not. C++ also removes some of the automatic checks and "safety belts" that Java provides.

The goal of this course is to build on your skills as a programmer, by reviewing and extending object-oriented programming concepts from CPSC 124 (including classes, inheritance, and polymorphism) and by adding new language features (including pointers, reference parameters, operator overloading, and templates), new algorithmic techniques (recursion), and new data structures (including linked lists, stacks, queues, trees, and, time permitting, the Standard Template Library). Continued attention will also be given to "how to think like a programmer" - that is, the fundamental logical thinking and problem-solving skills which are independent of the particular language being used.

Office Hours

M 12:30-1:30pm, W 3-4:30pm, R 10:30am-noon, F 10:30-11:30am
or by appointment (schedule)

TA Hours

Sun, Mon, Wed, Thu 7-9pm, Lansing 310
Wednesday is likely to be crowded with 124 students - please try to avoid using the TAs on Wednesdays.

Class Hours and Meeting Place

Lecture MWF 9:05-10am, Stern Hall 204
Lab R 8:45-10:10am, Gulick 208


Course Links

Unix Links


Announcements

[4/17] Q: What's the threshold for figuring out if something is spam?

A: There is no threshold, exactly. From the handout:

The idea is that if there's a 50% chance of something being spam, you could flip a coin to figure out if that message is spam - heads = spam, tails = not spam. But, certain properties increase or decrease the chance of something being spam, so that the probability of any given message being spam is not 50%. For example, maybe a given message has a 75% chance of being spam. So, you flip a coin which has a 75% chance of coming up heads, and declare the message to be spam if you get heads.

The formula for the likelihood is the calculation of what probability of heads your coin should have. The formula for taking an action with a certain probability (the one involving rand()) tells you how to use rand() to simulate flipping a coin with a given probability of heads.

[4/16] Q: "Continue reading emails until you get to the end of the file" pertains to the main program, and not necessarily having each e-mail received by an instructor read by the instructor?

A: Yes - "Continue reading emails" refers just to reading each message in from the file; it should then be received by the instructor. Whether or not it is ever actually read by the instructor is not something the main program worries about.

[4/15] Q: When do the instructors read their email?

A: They don't, at least not in this program.
You should support the ability of all instructors to read email, but the only time mail-reading will actually occur in this particular program is when a graduate student is coping.

[4/2] The original version of the WorldGUI class treats NORTH as being down; this is consistent with viewing north as increasing the row. If you done this, you're fine. If, instead, you have treated north as being up (and decreasing the row), you should copy the new version of worldgui.cc from /classes/s07/cs225/hw4/ to your directory so that north-facing creatures will point in the correct direction. This has the added advantage that the dirLeft and dirRight routines in geometry.h return directions which actually appear to be left and right turns.

Either interpretation of north (up or down) is acceptable, but you should make sure that you use the proper version of WorldGUI so that the creatures appear to move forward instead of backward.

[3/28] An issue that has come up a couple of times in Darwin's World:

Q: It keeps telling me that Species or World does not define a data type, even though I have included a header file that clearly indicates that Species and World DO define a data type.

A: You have circular #includes - world.h #includes species.h, and species.h #includes world.h. The error is because Species needs World and World needs Species - but which class declaration goes first?

The solution is to use a forward declaration of the class in one place. For example, remove #include "species.h" from World and replace it with

 class Species;

This forward declaration is like a forward declaration for a function - it announces to the compiler that "Species" is a class and should be treated as such. Then you don't need to #include "species.h" to get that information, and the cycle of #includes is broken.

Forward declarations won't solve every problem, however. Knowing that Species is a class is enough for the compiler to compile certain kinds of things (like Species parameters or variable declarations involving Species *) but isn't enough for other things (such as variable declarations involving Species objects or method calls) - for those you need to #include "species.h". This means that you'll likely need to #include "species.h" in world.cc (as the forward declaration of Species was only enough to compile the header file), and that it doesn't work to instead do a forward declaration of World in species.h (because Species has an instance variable of type World).

[3/22] Two corrections for the maze solver: when adding the adjacent rooms to the stack/queue of discovered rooms, only add rooms if they haven't been marked (the mark is NONE) and once added, mark them as discovered (not visited). The correct pseudocode:

    // ** while ( there are more discovered rooms ) {
    // **  choose a discovered room and remove it from the collection of
    // **   discovered rooms 
    // **  if it has been visited, continue with the next discovered room
    // **  otherwise {
    // **    mark it as visited in the GUI
    // **    if it is the exit, you're free (break out of the loop)
    // **    otherwise {
    // **      add the rooms adjacent to this room to the collection of
    // **       discovered rooms if not already visited or discovered
    // **      mark each as discovered in the GUI
    // **    }
    // **  }

    // pause briefly before repeating the loop, to slow down solving
    usleep(10000);                 

    // ** }

Also note that the usleep should go inside the while loop, as the last thing. This slows down the solving process a bit so you can watch it.

[3/2] A configuration file (unsurprisingly named config.txt) has been added to /classes/s07/cs225/hw4. If you've already copied the files to your directory, also copy the configuration file; if you haven't copied them yet, you'll get the configuration file along with everything else. This will let you run the Darwin's World demo.

[2/22] Two updates:

[2/20, 2/21] A few clarifications on the take-home exam:

  1. Don't name your executable "set". There's a builtin shell command named set, and your shell will try to run this one instead of your program. Choose a different (but still reasonable) name for your executable.

  2. The input file containing the cards contains the full words ("PURPLE", "HASHED", etc); the short 4-letter card description is what is displayed on the screen to allow the user to play the game.

  3. The example of the user entering 0 3 2 2 2 3 to specify a set is meant to be six separate numbers - a 0, a 3, a 2, a 2, etc. You do not have to somehow read everything as one unit and then try to split it up.

  4. If there's something you don't know how to do, you can still test your program by substituting the part you don't know how to do with something else similar that you do know how to do. (Of course, you won't get credit for the thing you didn't do, but you can get credit for everything else.) The exam handout mentions doing this if you don't know how to read from a file as specified - prompt the user to enter the information from the keyboard instead. You can also do this for other aspects of the program e.g. if you don't know how to compute the short 4-letter card description, print out the full words instead (but still arrange them in the 3x4 grid).
    If there's something you can't quite get right, you can put the part that isn't quite right in comments to show how close you got and then implement an alternative so you can test the rest of your program. Just include a note about what you did so I can figure it out...

  5. There will not be as significant a penalty for a non-compiling program as on the programming assignments. There will be deductions for syntax errors, but not an automatic 10% deduction (unless you have a *lot* of syntax errors). Thus, it is worth attempting to write something even if you aren't 100% on it.

  6. You do not need to prevent a player from choosing the same set of cards more than once to score extra points. However, if you have done this, you don't need to remove it from your program.

[2/14] Q:

scrblgui.h:63: error: expected ',' or '...' before '&' token
scrblgui.h:63: error: ISO C++ forbids declaration of 'string' with no type

A: It doesn't know what string is. Where is string defined? Add the appropriate #include to scrblgui.h. It got left out and I got away with it in my version because of the order in which I did #includes elsewhere in the program.

[2/12] If you copied the scrbl files (scrblgui and the others for the bonus) from /classes/f06/cs225/hw3 as the handout said instead of noticing that the term should actually be s07, you should recopy them from /classes/s07/cs225/hw3 or else you will get compiler errors. The handout has been corrected.

[2/9] Make the following changes to landergame.cc:

Make the following changes to landergui.cc:

[1/23] Lab #2 and programming assignment #2 have been posted. Read the lab handout before coming to lab.

[1/23] Some general comments on lab #1 have been posted (see the syllabus page). The labs will be handed back in class on Wednesday.

[1/16] The course wiki is live! You can browse the content now. Thursday's lab will include some exercises to get you a little more familiar with the wiki. We'll also create accounts in lab on Thursday (please don't try to create one before then!) so you can view/edit your journal page and post comments.

[1/15] Welcome to CPSC 225! This web page is your source for a great deal of important and useful material, so you should take a few minutes to familiarize yourself with the website. Check back often for announcements and new information.


Valid HTML 4.01!