You are on page 1of 5

_____________________________________________________________________________________

CSC134 C++ PROGRAMMING


_____________________________________________________________________________________

EXTRA CREDIT LAB:


OBJECT ORIENTED PROGRAMMING –CLASSES AND DATA ABSTRACTION

Objectives

In this lab assignment, students will learn:

- how to create a class, which unlike a struct, allows you to group data and functions.

Goals

In this lab assignment, you will demonstrate:


- how to use private, protected and public members of a class.
- how to define a constructor and destructor for a class.
- how to define mutator and accessor functions.
- how to use the static and constant data/function members

Grading

Grading rubric for each question:


- Insert comments to document your program [10pts]
- Program must be implemented and run as instructed [80 pts]
Class Implementation (40pts) and Main Driver (40pts)
- Source files (xxx.cpp/xxx.h) and executables (xxx.exe) are submitted to Blackboard in a compressed file
(i.e. .zip file). [10 pts]

Complete the following programming exercise. Electronically submit all necessary source code
files for compilation. You will not get any points if your code does not compile.

Chapter 10:
Swimming Pool Management –
In this programming exercise you will create a simple swimming management program
according to the following customer specifications:
 Write the definition of a class SwimmingPool, to implement the properties and functions
of a swimming pool. The pool must be a rectangular shaped of any dimension. (20%)
o The class should have the instant variables to store the length (in feet), width (in
feet), depth (in feet), amount (in cubic feet), of water in the pool, the rate (in
gallons / minute), at which the water is draining from the pool.
o The instant variables must all be private members of the class.
 Must add the SwimmingPool Constructor(s) and Destructor member functions. (10%)
______________________________________________________________________________________________________________________________________________________________________________________________________________________

CSC134 Lab 05 Page 2


______________________________________________________________________________________________________________________________________________________________________________________________________________________

 Add appropriate accessor and mutator member functions.(10%)

 Add member functions to do the following: (40%)


o determine the amount of water needed to fill an empty or partially filled pool,
o determine the time needed to completely or partially fill or empty the pool,
o and add or drain water for a specific amount of time.
o Allow adding or subtracting one or more pools (add by adding lengths, widths
and depths, rates and amount – subtract by subtracting lengths, widths, and
depths, rates and amount).
 Add a static property (data member) to count the number of swimming pools created and
static member function to report this count.(20%)
 NOTE: The amount of gallons in a cubic feet is 7.48

Please use the following driver program to test your class:

//Main program

#include <iostream>

#include "swimmingPool.h"

using namespace std;

int main()
{
cout << "The initial total number of pools in this program is "<<
SwimmingPool::getNumberOfPools() << endl;

const int NUM_OF_POOLS = 3;


SwimmingPool pools[NUM_OF_POOLS];

pools[0] = SwimmingPool(30, 15, 10);


pools[1] = SwimmingPool(60, 25, 16);
pools[2] = SwimmingPool(35, 20, 11);
int waterFRate;
int time;

cout << "Pool data: " << endl;


for (int i = 0; i < 3; i++)
{
cout << "\n\n";
cout << "POOL # " << i + 1 << ": " << endl;
cout << " Length: " << pools[i].getLength() << endl;
cout << " Width: " << pools[i].getWidth() << endl;
cout << " Depth: " << pools[i].getDepth() << endl;
______________________________________________________________________________________________________________________________________________________________________________________________________________________

CSC134 Lab 05 Page 3


______________________________________________________________________________________________________________________________________________________________________________________________________________________

cout << " Total water in the pool: " <<


pools[i].getTotalWaterInPool() << endl;

cout << "To completely fill the pool: " << endl;
cout << " Enter water fill in rate (Gallons Per Minute): ";
cin >> waterFRate;
cout << endl;

pools[i].setWaterFlowRateIn(waterFRate);

time = pools[i].timeToFillThePool();

cout << " Time to fill the pool is approximately: "


<< time / 60 << " hour(s) and " << time % 60
<< " minute(s)." << endl;
}
//Add 2nd Pool and 3rd Pool to create the addedPool
cout << "\n\nThe Added Pool Data: " << endl;
SwimmingPool addedPool = pools[2].add(pools[1]);
cout << " Length: " << addedPool.getLength() << endl;
cout << " Width: " << addedPool.getWidth() << endl;
cout << " Depth: " << addedPool.getDepth() << endl;

cout << " Total water in the pool: " <<


addedPool.getTotalWaterInPool() << endl;

//Subtract the 3rd Pool from the 2nd Pool to create the subPool
cout << "\n\nThe Subtracted Pool Data: " << endl;
SwimmingPool subPool = pools[1].subtract(pools[2]);
cout << " Length: " << subPool.getLength() << endl;
cout << " Width: " << subPool.getWidth() << endl;
cout << " Depth: " << subPool.getDepth() << endl;

cout << " Total water in the pool: " <<


subPool.getTotalWaterInPool() << endl;

SwimmingPool extraPool(20, 10, 5);


cout << "\n\n\nThe total number of pools created in this program is "
<< extraPool.getNumberOfPools() << endl;

system("pause");
return 0;
}

//In your SwimmingPool class, add the following Copy Constructor member function to
your class. (No modification is required to this function):
//Copy Constructor – Topic covered in chapter 11.
SwimmingPool::SwimmingPool(const SwimmingPool &copy)
{
length = copy.length;
width = copy.width;
depth = copy.depth;
waterFlowInRate = copy.waterFlowInRate;
waterFlowOutRate = copy.waterFlowOutRate;
amountOfWaterInPool = copy.amountOfWaterInPool;
numOfPools++;
}
______________________________________________________________________________________________________________________________________________________________________________________________________________________

CSC134 Lab 05 Page 4


______________________________________________________________________________________________________________________________________________________________________________________________________________________

SAMPLE OUTPUT:

The initial total number of pools in this program is 0


Pool data:

POOL # 1:
Length: 30
Width: 15
Depth: 10
Total water in the pool: 0
To completely fill the pool:
Enter water fill in rate: 10

Time to fill the pool is approximately: 56 hour(s) and 6 minute(s).

POOL # 2:
Length: 60
Width: 25
Depth: 16
Total water in the pool: 0
To completely fill the pool:
Enter water fill in rate: 10

Time to fill the pool is approximately: 299 hour(s) and 12 minute(s)

POOL # 3:
Length: 35
Width: 20
Depth: 11
Total water in the pool: 0
To completely fill the pool:
Enter water fill in rate: 10

Time to fill the pool is approximately: 96 hour(s) and 0 minute(s).

The Added Pool Data:


Length: 95
Width: 45
Depth: 27
Total water in the pool: 0
______________________________________________________________________________________________________________________________________________________________________________________________________________________

CSC134 Lab 05 Page 5


______________________________________________________________________________________________________________________________________________________________________________________________________________________

The Subtracted Pool Data:


Length: 25
Width: 5
Depth: 5
Total water in the pool: 0

The total number of pools created in this program is 6


Press any key to continue . . .

You might also like