CSCI-203 Lab 6 Fall 2002
- Selection, Repetition, and Class Implementation -


Purpose

One Way Selection

Copy the file salary.cc from the ~cs203/Labs/Lab6 to your own Lab6 directory.

Using the salary.cc file, complete problem 7B on page 262 of the Mercer text.

Be sure to hand-check your results so that you know you have done the implementation correctly.

Hand in the program code, and an execution of the program.

Repetition

Copy the file rep.cc from the ~cs203/Labs/Lab6 to your own Lab6 directory. The program is supposed to read a sequence of positive values and then display their average.

You are to fill in the main function so that it reads (using the function getValue()) a sequence of values and sums them up -- the end of the sequence will be marked by the value -1. After all the values have been read, you display the average of the values.

Important: If no values are read (i. e., if the first value read is -1) then a message indicating no data was read should be printed.

Hand in the complete program code, and several executions of the program showing that all the features work.

Implementing a Class

Scenario:

A gate attendant at a concert makes use of a ``click-counter'' which, when clicked, adds one to the current value of the counter. In this way, when everyone has entered the concert, the number of people admitted can be determined.

The click-counter has two buttons: the counter button, which when pressed increments the counter, and the reset button which sets the counter value to zero. The click-counter also has a window containing a sequence (probably 4) rotating wheels with the digits from 0 through 9. These rotate appropriately to represent the number counted so far. The important thing about the window is that it sets a maximum on the number of things which can be counted -- it will automatically roll back to 0 when the maximum number is incremented.

We want to develop a similar kind of counting device which can be used in a program to, for example, count the number of times an object is accessed or the number of times a loop repeats.

Here is a class definition for a software click-counter.

#ifndef CLICKER_H
#define CLICKER_H

class Clicker {
public:
    Clicker();
    Clicker(int inMaxCount);
    void click();
    void reset();
    void setMaxCount(int inMaxCount);
    void display() const;
    int getCount() const;
    int getMaxCount() const;
private:
    int mCount;
    int mMaxCount;
};

#endif
Carry out the following activities.

Turn in all the code for this part: Clicker.h, Clicker.cc, and your final version of testClicker.cc along with the execution of testClicker.cc.

When you are finished, be sure to clean up your directory. Type make clean at the Unix prompt. This will remove all of your .o files and your .exe file. You should clean up your files after each lab.



send comments to cs203@Bucknell.edu
2002-10-13