CSE 143

Spring 1999

Homework #2

"Give It Some Class!"

After many hours of hard work, you have reconstructed what you can of the soccer league program.   You place the program printouts on your boss's desk, hoping for a reaction.  And there is a reaction, practically a nuclear one.  "What kind of programmer are you, anyway?  Your resume said C++.  This is just barely cleaned-up C!  Where are the objects?  Where are the classes?  You give it some class pronto, or your stock options are history!" Trembling, you turn to retreat to your cubicle.  "One more thing, kiddo," he growls.  "Class without style ain't nothin' around here.  Now get busy."


Hoping against hope, you search the hard drive on your predecessor's computer.   Lo and behold, there are some later versions of the program you had overlooked before.  You find three useful-looking files, a newmain.cpp, a socuser.h, and a socuser.cpp (and an executable).  After studying these you deduce that there were to be three classes in the program.  This makes good sense to you; it's just what you were about to do anyway.  The three classes are:

Following your company's typical practice, you decide to create six files to realize these three classes: socplayer.h/socplayer.cpp, socteam.h/socteam.cpp, and socleague.h/socleague.cpp.  You find that there are blank or almost blank files for all of these already; fat lot of good that does you.

What you need to do

By Thursday, April 8 (electronic deadline 8:00 pm): 

Write specification (header) files for player, team, and league (i.e., socplayer.h, socteam.h, socleague.h).  They do not have to be complete, but, using them you should be able to compile newmain.cpp and socuser.cpp without errors or warnings.  You do not have to have written the implementation files (.cpp files) for the classes.  You do not have to be able to link or run the program -- only compile.  You may not change newmain or user at this stage.

You can think of player, team, and league as ADT's.  At this point, when you declare them as classes, you don't need to worry about what variables are inside. In fact, you don't need to declare any member variables now!  Focus on the member functions, which are the ADT's interface to the outside world.  How do you know what member functions are needed?  Answer: by very carefully studying newmain.cpp and user.cpp, to see how they use the classes.

Amazingly, late on Thursday evening you will discover complete official versions of the three specification files, and you should use them to complete the program so it works like the demo (or better in some ways to be described below).

By Wednesday, April 14 (electronic turn-in by 5:00)

The completed program.  This time, you will turn in the implementation files, but will not be able to turn in the specification files.  Base your implementation on the official header files.  You will not be able to turn in newmain.cpp, either. You should turn in user.cpp for the additional features described below.  Bring the receipt and any other required material the quiz section on Thursday, April 15.

Other code changes. 

  1. Implement the "show team roster" option.  The official specification files will contain the needed method interfaces; they don't have to be part of the first turn-in.  You do not have to change main.
  2. Use the assert macro in some appropriate places in your class implementations.   Checking simple pre- and post- conditions would be good candidates.  It maybe helpful to add comments to label your assertions by the type of invariant they represent (e.g., "precondition," postcondition", "class invariant," "loop bounds," "loop invariant," etc..  Make sure that at least some of your invariants  are easily visible in the code so the TA can spot that you've done it.  Maybe a yellow highlighter pen?

Other paperwork

As you did last time, turn in a separate sheet of paper stapled to the turn-in receipt and properly identified, the following three items:

  1. Statement of what works and what doesn't
  2. Design/programming critique
  3. Statement concerning sources of code and help received.

Time to get started!