Assignment 3 - CS 1711 - Fall 1999

Due: 1999 November 5, 4:30 pm
(This is a hard dead-line for both hard copy and drop-box submission. Do not leave it to the last minute. `I couldn't get my printer to work' or `The network was down at 4:00' are not acceptable excuses for lateness.)

The detailed instructions on handing in assignments are located on the course Web page.  Make sure to read the programming standards and course ethics material before attempting the assignment

Question 1

(Based on 5.13 of text.) Modify the Accumulator class (accum.h in the supplemental software) so that it can compute and return the average of numbers in the total: add a new data member count that is initialized to 1 by the constructor. Each time addValue() is executed, count is increased by one. The new member function average() returns the average of numbers entered into the class. The new class will be called AccumAv

Your tasks in modifying AccumAv are as follows:
- re-implement the constructor and addValue()
- implement average()

Warning: What is the average if no numbers have been entered? Since count is initialized at 1, the average is not usually total/count.

Use the AccumAv class in a program which prompts the user for a sequence of integers, sums the positive integers before the first zero in the sequence and reports their average (to 1 decimal place). You can include the declaration and implementation of AccumAv in the program file, so you will submit only the single file specified below.

Sample run

Program to sum and average positive integers.
Enter integers on a single line, separated by spaces, and terminated with a zero
Integers>23 -4 4 6 -2 0
The sum of the positive integers is 33.
The average is 11.0.

File names:


Question 2

Write the declaration and implementation of a class Room. The class has four data members, all double:
length, width, height, door
which give the room dimensions and the area of the door. Your class must have suitable constructors and access functions, plus a member function which computes the wall area (the room perimeter times the height minus the door area).

Write a program which calculates the cost to paint the walls the Room class by prompting the user for room dimensions(meters), door area(sq. meters) and paint cost (per sq. meter) and then reports the cost of painting the room.

The program should operate for several rooms by prompting the user for a repetition. Here you will submit two files, one containing the program, and a second file with the Room class.

Sample run

Enter the room dimensions (L, W, H; in meters) and door area (sq. meters)>
3.0 4.0 2.0 2.0

Enter the paint cost ($ per sq. meter)>

The room costs $65.00 to paint.

Do you want to price another room? (Type Y to continue)>

Goodbye. Thanks for using the paint cost calculator. 

File names:

paint.cpp, room.h