CS 102 Laboratory Session Two
Week Three Lab session. Perform the exercises in the lab session. You may prepare in advance if you like.
Use only one preferred compiler (your choice). Show output to the TA for five points (maximum) credit
for this session.
Exercise One
Two checkoff points.
Revise (extend, modify) your program from the first lab session to operate over the input range
of minus one hundred million to five hundred million (use the American million with six zeroes).
Test the program with an appropriate dataset.
Using a class
Thanks to Claire Bono for creating the exercises below. Used with permission.
Goals
These exercises will give you practice creating objects and calling member
functions on objects. That is, acting as a "client" of a class. To
complete this lab you should not change any of the code that is part
of the class. That includes the class definition, the member
functions definitions, and the other completed functions (except main).
(Normally all the code for the class would appear in a separate file,
but for now, we'll just use one file for our whole program.)
Exercise Two
Three checkoff points.
The source code for a fraction class can be found in ~csci102b/labs/lab2/fractlab.cc
Make a copy of this file in your directory, but
call it ex1.cc.
Record the error messages that result from compiling the following
modifications to the program. To compile from inside emacs: (M-x compile; Ctrl-x ` to find
errors); use the command g++ -g -Wall ex1.cc
- Add to main the variable definition
Fraction k;
- Add to main the statement
h._num++;
- Remove the "Fraction::" from the print
member function definition.
- Remove the Fraction (int n, int d); line from the
Fraction class definition (not the function definition).
For checkoff, show the TA a table (on-line or on paper) that lists
the four error messages and their causes.
This page established September 8, 1999; last updated January 23, 2000 by Rick Wagner.