Summer Quarter 2003 / Class webpage
In this lab, we will work with ADTs (Abstract Data Type) and debugging. The main exercise (7 points) requires you to develop a simple class using a given ADT. The other exercises require you to work with debugging and error corrections.
A file name is specified for each exercise. Save all files in the folder that you will turnin at the end of the class.
First, you have to download the files Counter and testcounter.cc.
Counter defines an abstract base class describing the interface of the abstract data type (ADT) Counter, which is (in turn) partially described in comments. The program testcounter tries to create an object of the class SimpleCounter implementing the Counter interface.
Your task is to develop a class SimpleCounter that passes the tests performed in testcounter.cc.
In other words, you have Counter as abstract class, whose implementation is done by subclasses, as for instance SimpleCounter. Also, you have a separate program (testcounter) that uses the same abstract data type by its implementation class.
Hint: your class should be derived publicly from Counter.
Hint: You will want your program to have some method to indicate when a counter has exceeded its valid range. This can range from terminating the program with an error message to printing a warning message and continuing to adding an "invalid" flag to the counter which gets set on error conditions. This implementation is left up to you.
Save your file as SimpleCounter.
1 point possible
Attendance for the full lab period is mandatory. Try working on some of the following short tasks. Each exercise is worth 0.5 points, out of 1 possible.
1. Correct errors.
Your tasks are:
a) Justify the message errors (0.2 points).
b) Correct the code (0.3 points).
Save your file as lab2_1.cc. Begin your file with part a) in comments.
2. Correct errors.
This program contains an error.
a) What output does the program produce when x =64? (0.1 point)
b) Run the program and remove the error. Describe the steps that you took to find the error (0.2 points).
c) How can you make the program more user friendly and fail-safe? (0.2 points). (A fail-safe program is one that will perform reasonably no matter how anyone uses it. See Carrano chapter 1 for details.)
Save your file as lab2_2.cc. Begin your file with part a) followed by descriptions of parts b) and c) in comments.
3. Suppose that, due to some severe error, you must abort a program from a location deep inside nested function calls, while loops, and if
statements. Write a diagnostic function that you can call from anywhere
in a program. This function should take an error code as an argument
(some mnemonic enumeration), display an appropriate error message, and
terminate program execution. (0.2 points)
Save your file as lab2_3.cc.
4. Write a simple program (main function) that calls the
previous procedure with at least 3 different error codes. List what
kind of input generates each of these errors. (0.2 points)
Save your file as lab2_4.cc.
Remember to read the Coding Standards before starting the program.
Attendance - 2 points
Counter implementation turned in - 7 points
Misc. Tasks - 1 point
Extra credit - .4 points
Total: 10.4/10