Programming Assignment #2
CS 202 Programming Systems
Winter 2006
After attending the Lumberjax’s first home game in LaCross, you have decided it would be fun to start monitoring the progress of professional teams. You have decided to compare lacross, basketball, football, and baseball. (However, if you would like to substitute another sport for one of these – that is fine)
You realize that there are some statistics that are similar between each of these types of sports: Each play with two teams (which both have names). There is a score for each team. And there is a winner. There are also differences. In lacross, we keep track of the number of attempts at each goal (whether or not it goes in). And, the number of players is different than the other sports. Baseball is different in that the statistics are kept at each inning; in addition, you might want to keep track of the number of home runs. Of course, other differences are the number of players on the field and how many points you get for scoring (football you can score a variety of ways – touchdowns, kicks, etc. which are scored differently)
Examine the four team sports of your choice – and come up with a list of similarities and differences. Look at both the data and the operations. Operations COULD include methods to play a game with two teams – defining the team names and players, set the score for that game, find out the statistics for a particular team that has played, and display all of the statistics for a given game.
As you design this software, you are not sure which data structure would be best. So, you have decided to use BOTH linear linked list of linear linked lists and arrays of linear linked lists in this assignment. You can decide where best to put these data structures in your design. Other data structures can also be used – of your choice. You have decided to use dynamic binding so that you only have to write the application once, independent of four different teams that will be monitored!
For this assignment…
Because of the self similar nature of these four team sports, you have decided to use dynamic binding with C++ to create a hierarchy that will support all four. In each derived class, you will want to look for the information (data) that is unique for that type of data arrangement.
With dynamic binding, we will build a hierarchy where the most indirect base class acts as a hub that should contain virtual functions of all of the common operations that are supported by its derived classes.
Support
dynamic binding in all operations
(except the constructors). Your goal is to create an abstraction that will look
and feel the same regardless of the underlying data structure used by the
client program.
For
program #2, we will apply inheritance and pure polymorphism to the creation of
our abstraction. In the main, use a pointer to a base class which can point to objects of any type.
Avoid using casting to solve this problem. Minimize your use of if/else (or
switch) as well. Attempt to use pure polymorphism as much as possible. And, of
course, all arrays must be dynamically allocated (no statically allocated
arrays) and no use of the string class.
1)
Your primary job is
to implement a simple application using OOP and then implement this using
dynamic binding.
2)
You will be graded
on your use of memory and the underlying efficiency of your design. Strive for
an elegant OOP solution – although don’t wait to start (at least on your
design)!
3)
Each node’s array of characters must be dynamically
allocated at run time using new (and don’t forget to deallocate it later!). Do not use statically allocated
arrays in your nodes!
4)
On the other hand,
the client program may use statically allocated arrays.
5)
Realize that you are
not allowed to use the string class
in this assignment.
6)
Use modular design,
separating the .h files from the .cpp files. Remember, .h files should contain
the class header and any necessary prototypes. The .cpp files should contain
function definitions. Never
"#include" .cpp files!
7)
Use the iostream.h
library for all I/O; do not use stdio.h.
8) Make sure to define a constructor and destructor
for your classes. Your destructor must deallocate all dynamically
allocated memory.
9) You are not
allowed to use global variables.
10) You must
have a copy constructor. You must also show that you have tested your copy
constructor
As part of your design writeup discuss how you used “is a” versus “using” versus
“has a” relationships in your design.
What to Turn in:
•
On the due date, email your shar’d program to: karlaf@cs.pdx.edu
The
subject of your email should state: 202-prog2 <your last name>
submission
•
Also, on the due date turn in a hard copy of your program's source code, a hard copy of output, a 1-page design
consideration write-up, and a 1-page debugger write-up.
INSTRUCTIONS TO EMAIL PROGRAMS: In the
subject field of your email, indicate: your last name and the assignment number
followed by the word “submission” (this way I will know that the program is
being turned in). When you mail the
program, using the following command typed at the UNIX prompt. Do Not
Use Pine to accomplish this!
Programs
must be emailed using the following syntax:
type:
/bin/sh
at
the prompt type: shar file1.cpp file2.cpp file2.h >prog2
next,
type control-d
To
email this archive, type the following. The double quotes are essential!
mailx
-s “202 prog2 My Name Submission” karlaf@cs.pdx.edu <prog2
This
represents how you might submit the first program that has the filenames:
file1.cpp and file2.cpp.
REMINDERS:
Every program must have a comment at
the beginning with your first and last
name, the class (CS202), the name of the file, and the assignment number. This is
essential!