Remember, in this course, all programming will be done under the Linux operating system, using standard programming tools for that environment. Linux is a free operating system, available for all to download (RH), (Mandrake) and use with no cost. Linux itself is about a decade old, but in conjunction with a set of free utilities from the GNU project, behaves like a member of the UNIX family of operating systems.
Tutorials on Linux are available all over the Internet, Google for "Linux tutorial" and find one that suits you, or just try this one.
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.h 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 1: your class should be derived publicly from Counter, and should use exceptions to signal error. Errors occur whenever the value of Couter would be outside the bounds it was created with. Throwing the exception std::domain_error is as a good choice as any for now.
Hint 2: you know if your file is correct if testcounter.cc returns only the expected exceptions.
Save your file as simplecounter.cc.
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 Course Style Guide before starting the program.
Attendance - 2 points
Terminal session turned in - 7 points
Misc. Tasks - 1 point
Extra credit - .4 points
Total: 10.4/10
© 2003 UC Riverside Department of Computer Science & Engineering. All rights reserved.