main.cpp
#include
#include
#include \"SwimmingPool.h\"
using namespace std;
void printMainMenu();
void printPoolVolume();
void printGetPoolDimensions(bool);
void printHasDimensions();
void checkDimensions();
void printError();
void printPoolDimensions();
double editValue(double);
void printGetFillRate();
void printGetDrainRate();
void printAddWater();
void printDrainRate();
void printFillRate();
char printWantwer();
SwimmingPool pool;
int _response;
int _numResponses;
double _length;
double _width;
double _depth;
//double _currentwerVolume;
double _drainRate;
double _fillRate;
bool _end;
char _newValue[5];
int main()
{
int fillTime;
int drainTime;
double drained;
// Set output style and precision
cout << fixed << showpoint << setprecision(2);
// Main program loop
// ends when _end==true
while (!_end)
{
// Prints main option list
printMainMenu();
// Switch based on response
switch (_response)
{
// Sets pool dimensions
case 1:
if (pool.hasDimensions())
printHasDimensions();
else
{
printPoolDimensions();
printPoolVolume();
}
break;
// Prints pool dimensions
case 2:
printGetPoolDimensions(false);
system(\"pause\");
break;
// Prints fill rate
case 3:
printGetFillRate();
break;
// Prints drain rate
case 4:
printGetDrainRate();
break;
// Determine water need to fill pool to capacity
case 5:
checkDimensions();
if (!pool.hasWater())
cout << \"\ The pool is currently empty\";
else
{
cout << \" The pool currently has \"
<< pool.getwerVolume()
<< \" units\"
<< endl;
}
cout << \"\ \ Water needed: \"
<< pool.getFillAmount(pool.getwerVolume())
<< \" units of water\ \ \";
system(\"pause\");
break;
// Determine time required to fill pool at rate
case 6:
if (!pool.hasDimensions())
{
cout << \" Pool dimensions not yet entered.\ \";
printGetPoolDimensions(false);
}
if (pool.getFillRate() <= 0)
printGetFillRate();
cout << \"\ Time to fill pool: \"
<< pool.getFillTime()
<< endl
<< endl;
system(\"pause\");
break;
// Determine time required to drain pool at rate
case 7:
checkDimensions();
if (_drainRate <= 0)
printGetDrainRate();
if (!pool.hasWater())
{
char response = printWantwer();
while (response != \'y\' && response != \'n\')
{
printError();
response = printWantwer();
}
if (response == \'y\')
printAddWater();
else
break;;
}
cout << \"\ Time to drain pool: \"
<< pool.getDrainTime()
<< endl
<< endl;
system(\"pause\");
break;
case 8:
checkDimensions();
if (pool.getFillRate() <= 0)
printGetFillRate();
else
printFillRate();
cout << \"\ Enter fill time: \";
cin >> fillTime;
pool.setFillTime(fillTime);
pool.setwerVolume(pool.getwerVolume() + pool.fill());
cout << endl
<< pool.fill()
<< \" units of water were added to the pool\ \ \"
<< \" The pool now contains \"
<< pool.getwerVolume()
<< \" units of water\ \ \";
system(\"pause\");
break;
case 9:
checkDimensions();
if (pool.getDrainRate() <= 0)
printGetDrainRate();
else
printDrainRate();
cout << \"\ Enter drain time: \";
cin >> drainTime;
pool.setDrainTime(drainTime);
if (!pool.hasWater())
{
char response = printWantwe.
2. int drainTime;
double drained;
// Set output style and precision
cout << fixed << showpoint << setprecision(2);
// Main program loop
// ends when _end==true
while (!_end)
{
// Prints main option list
printMainMenu();
// Switch based on response
switch (_response)
{
// Sets pool dimensions
case 1:
if (pool.hasDimensions())
printHasDimensions();
else
{
printPoolDimensions();
printPoolVolume();
}
break;
// Prints pool dimensions
case 2:
printGetPoolDimensions(false);
system("pause");
break;
// Prints fill rate
case 3:
printGetFillRate();
break;
// Prints drain rate
case 4:
printGetDrainRate();
break;
3. // Determine water need to fill pool to capacity
case 5:
checkDimensions();
if (!pool.hasWater())
cout << " The pool is currently empty";
else
{
cout << " The pool currently has "
<< pool.getwerVolume()
<< " units"
<< endl;
}
cout << " Water needed: "
<< pool.getFillAmount(pool.getwerVolume())
<< " units of water ";
system("pause");
break;
// Determine time required to fill pool at rate
case 6:
if (!pool.hasDimensions())
{
cout << " Pool dimensions not yet entered. ";
printGetPoolDimensions(false);
}
if (pool.getFillRate() <= 0)
printGetFillRate();
cout << " Time to fill pool: "
<< pool.getFillTime()
<< endl
<< endl;
system("pause");
break;
// Determine time required to drain pool at rate
case 7:
4. checkDimensions();
if (_drainRate <= 0)
printGetDrainRate();
if (!pool.hasWater())
{
char response = printWantwer();
while (response != 'y' && response != 'n')
{
printError();
response = printWantwer();
}
if (response == 'y')
printAddWater();
else
break;;
}
cout << " Time to drain pool: "
<< pool.getDrainTime()
<< endl
<< endl;
system("pause");
break;
case 8:
checkDimensions();
if (pool.getFillRate() <= 0)
printGetFillRate();
else
printFillRate();
cout << " Enter fill time: ";
cin >> fillTime;
pool.setFillTime(fillTime);
pool.setwerVolume(pool.getwerVolume() + pool.fill());
cout << endl
5. << pool.fill()
<< " units of water were added to the pool "
<< " The pool now contains "
<< pool.getwerVolume()
<< " units of water ";
system("pause");
break;
case 9:
checkDimensions();
if (pool.getDrainRate() <= 0)
printGetDrainRate();
else
printDrainRate();
cout << " Enter drain time: ";
cin >> drainTime;
pool.setDrainTime(drainTime);
if (!pool.hasWater())
{
char response = printWantwer();
while (response != 'y' && response != 'n')
{
printError();
response = printWantwer();
cout << " Response is "
<< response;
}
if (response == 'y')
printAddWater();
else
break;
}
drained = pool.drain();
cout << endl
<< " "
<< drained
<< " units of water were removed from the pool "
6. << " The pool now contains "
<< pool.getwerVolume()
<< " units of water ";
system("pause");
break;
case 10:
_end = true;
break;
default:
printError();
break;
}
}
return EXIT_SUCCESS;
}
void printMainMenu()
{
_numResponses = 6;
cout << " Type the number cooresponding to the task you would like to complete: "
<< " 1) Set pool dimensions "
<< " 2) Print pool dimensions "
<< " 3) Set fill rate "
<< " 4) Set drain rate "
<< " Print fill and drain rates "
<< " Add water to pool "
<< " Remove water from pool "
<< " 5) Determine water needed to fill pool to capacity "
<< " Determine time required to: "
<< " 6) fill pool "
<< " 7) drain pool "
<< " For a specific amount of time: "
<< " 8) fill pool "
<< " 9) drain pool "
<< " 10) Exit Program "
<< " Choice: ";
cin >> _response;
8. void printHasDimensions()
{
_numResponses = 2;
cout << " The pool already has dimensions"
<< endl
<< endl
<< "1) Create new dimensions"
//<< endl
//<< "2) Edit current dimensions"
<< endl
<< "2) Return to main menu"
<< endl
<< "Response: ";
cin >> _response;
switch (_response)
{
case 1:
printGetPoolDimensions(false);
break;
//case 2:
// // Print pool dimensions prompt with existing values
// printGetPoolDimensions(true);
// break;
case 2:
printMainMenu();
break;
default:
printError();
printHasDimensions();
break;
}
}
// Function that prints an error when invalid option entered at menu
void printError()
{
cout << "a" // make an error sound
10. cout << " Enter the drain rate: ";
cin >> _drainRate;
pool.setDrainRate(_drainRate);
}
void printAddWater()
{
double currentwerVolume;
cout << " How much water would you like to add? "
<< " Response: ";
cin >> currentwerVolume;
if (currentwerVolume > pool.getVolume())
{
currentwerVolume = pool.getVolume();
cout << " You entered more than the pool could hold ("
<< pool.getVolume()
<< ") but I fixed that for you. ";
}
pool.setwerVolume(currentwerVolume);
}
void printDrainRate()
{
cout << " Drain rate is currently: "
<< pool.getDrainRate()
<< endl
<< endl;
}
void printFillRate()
{
cout << " Fill rate is currently: "
<< pool.getFillRate()
<< endl
<< endl;
}
char printWantwer()
{
char response;
11. cout << " The pool has no water to drain! "
<< " Would you like to add water?"
<< endl
<< endl
<< " Response: ";
cin >> response;
return response;
}
SwimmingPool.h
#pragma once
class SwimmingPool
{
public:
SwimmingPool();
SwimmingPool(double, double, double);
SwimmingPool(double, double, double, double, double);
void setLength(double);
void setWidth(double);
void setDepth(double);
void setDrainRate(double);
double getDrainRate();
void setFillRate(double);
double getFillRate();
void setFillTime(int);
void setDrainTime(int);
void setwerVolume(double);
double getVolume();
double getwerVolume();
double getFillAmount(double);
int getDrainTime();
int getFillTime();
double drain();
double fill();
double fill(int);
bool hasDimensions();
12. bool hasWater();
private:
double _length;
double _width;
double _depth;
double _fillRate;
double _drainRate;
int _fillTime;
int _drainTime;
double _volume;
double _waterVolume;
};
SwimmingPool.cpp
#include "SwimmingPool.h"
using namespace std;
// Default constructor
SwimmingPool::SwimmingPool()
{
_length = 0;
_width = 0;
_depth = 0;
}
// Basic constructor defined with member initialization
SwimmingPool::SwimmingPool (double l, double w, double d) :_length(l), _width(w),
_depth(d)
{
// Assign to the instance variables the arguments passed to constructo
_volume = _length * _width * _depth;
}
// Full Constructor
SwimmingPool::SwimmingPool(double length, double width, double depth, double fillRate,
double drainRate)
{
// Assign to the instance variables the arguments passed to constructor
14. void SwimmingPool::setFillTime(int t)
{
_fillTime = t;
}
void SwimmingPool::setDrainTime(int t)
{
_drainTime = t;
}
// Member function to calculate volume
double SwimmingPool::getVolume()
{
// No need to check values of instance variables
// Return the volume
return _length * _width * _depth;
}
void SwimmingPool::setwerVolume(double v)
{
_waterVolume = v;
}
double SwimmingPool::getwerVolume()
{
return _waterVolume;
}
// Returns amount of water needed to fill an empty or partially filled pool
double SwimmingPool::getFillAmount(double currentwerVolume)
{
return getVolume() - currentwerVolume;
}
// Returns time needed to completely or partially drain the pool
int SwimmingPool::getDrainTime()
{
return (int)(_waterVolume/_drainRate);
}
// Returns the time need to completely or partially drain the pool
int SwimmingPool::getFillTime()
{
15. return (int)(getVolume()/_fillRate);
}
// Drain the pool for a specified time period
// Returns adjusted water volume
double SwimmingPool::drain()
{
double waterDrained = _drainRate * _drainTime;
_waterVolume -= waterDrained;
if (_waterVolume < 0)
_waterVolume = 0;
return waterDrained;
}
double SwimmingPool::fill()
{
_waterVolume += _fillRate * _fillTime;
return _waterVolume;
}
// Fill the pool for a specified time period
// Returns adjusted water volume
double SwimmingPool::fill(int time)
{
return 0;
}
bool SwimmingPool::hasDimensions()
{
if (_length > 0 && _width > 0 && _depth > 0)
return true;
else
return false;
}
bool SwimmingPool::hasWater()
{
if (_waterVolume > 0)
return true;
else
17. int main()
{
int fillTime;
int drainTime;
double drained;
// Set output style and precision
cout << fixed << showpoint << setprecision(2);
// Main program loop
// ends when _end==true
while (!_end)
{
// Prints main option list
printMainMenu();
// Switch based on response
switch (_response)
{
// Sets pool dimensions
case 1:
if (pool.hasDimensions())
printHasDimensions();
else
{
printPoolDimensions();
printPoolVolume();
}
break;
// Prints pool dimensions
case 2:
printGetPoolDimensions(false);
system("pause");
break;
// Prints fill rate
case 3:
printGetFillRate();
break;
18. // Prints drain rate
case 4:
printGetDrainRate();
break;
// Determine water need to fill pool to capacity
case 5:
checkDimensions();
if (!pool.hasWater())
cout << " The pool is currently empty";
else
{
cout << " The pool currently has "
<< pool.getwerVolume()
<< " units"
<< endl;
}
cout << " Water needed: "
<< pool.getFillAmount(pool.getwerVolume())
<< " units of water ";
system("pause");
break;
// Determine time required to fill pool at rate
case 6:
if (!pool.hasDimensions())
{
cout << " Pool dimensions not yet entered. ";
printGetPoolDimensions(false);
}
if (pool.getFillRate() <= 0)
printGetFillRate();
cout << " Time to fill pool: "
<< pool.getFillTime()
<< endl
<< endl;
19. system("pause");
break;
// Determine time required to drain pool at rate
case 7:
checkDimensions();
if (_drainRate <= 0)
printGetDrainRate();
if (!pool.hasWater())
{
char response = printWantwer();
while (response != 'y' && response != 'n')
{
printError();
response = printWantwer();
}
if (response == 'y')
printAddWater();
else
break;;
}
cout << " Time to drain pool: "
<< pool.getDrainTime()
<< endl
<< endl;
system("pause");
break;
case 8:
checkDimensions();
if (pool.getFillRate() <= 0)
printGetFillRate();
else
printFillRate();
cout << " Enter fill time: ";
20. cin >> fillTime;
pool.setFillTime(fillTime);
pool.setwerVolume(pool.getwerVolume() + pool.fill());
cout << endl
<< pool.fill()
<< " units of water were added to the pool "
<< " The pool now contains "
<< pool.getwerVolume()
<< " units of water ";
system("pause");
break;
case 9:
checkDimensions();
if (pool.getDrainRate() <= 0)
printGetDrainRate();
else
printDrainRate();
cout << " Enter drain time: ";
cin >> drainTime;
pool.setDrainTime(drainTime);
if (!pool.hasWater())
{
char response = printWantwer();
while (response != 'y' && response != 'n')
{
printError();
response = printWantwer();
cout << " Response is "
<< response;
}
if (response == 'y')
printAddWater();
else
break;
}
drained = pool.drain();
21. cout << endl
<< " "
<< drained
<< " units of water were removed from the pool "
<< " The pool now contains "
<< pool.getwerVolume()
<< " units of water ";
system("pause");
break;
case 10:
_end = true;
break;
default:
printError();
break;
}
}
return EXIT_SUCCESS;
}
void printMainMenu()
{
_numResponses = 6;
cout << " Type the number cooresponding to the task you would like to complete: "
<< " 1) Set pool dimensions "
<< " 2) Print pool dimensions "
<< " 3) Set fill rate "
<< " 4) Set drain rate "
<< " Print fill and drain rates "
<< " Add water to pool "
<< " Remove water from pool "
<< " 5) Determine water needed to fill pool to capacity "
<< " Determine time required to: "
<< " 6) fill pool "
<< " 7) drain pool "
<< " For a specific amount of time: "
<< " 8) fill pool "
23. cin.seekg(0, cin.beg);
cin.getline(_newValue, 5);
return atof(_newValue);
}
void printHasDimensions()
{
_numResponses = 2;
cout << " The pool already has dimensions"
<< endl
<< endl
<< "1) Create new dimensions"
//<< endl
//<< "2) Edit current dimensions"
<< endl
<< "2) Return to main menu"
<< endl
<< "Response: ";
cin >> _response;
switch (_response)
{
case 1:
printGetPoolDimensions(false);
break;
//case 2:
// // Print pool dimensions prompt with existing values
// printGetPoolDimensions(true);
// break;
case 2:
printMainMenu();
break;
default:
printError();
printHasDimensions();
break;
}
}
24. // Function that prints an error when invalid option entered at menu
void printError()
{
cout << "a" // make an error sound
// print error
<< " You entered an invalid response, please try again"
<< endl
<< endl;
}
void printPoolDimensions()
{
cout << " Pool Dimensions "
<< " Length: "
<< _length
<< endl
<< " Width: "
<< _width
<< endl
<< " Depth: "
<< _depth
<< endl
<< endl;
printPoolVolume();
}
void checkDimensions()
{
if (!pool.hasDimensions())
{
cout << " Pool dimensions not yet entered. ";
printGetPoolDimensions(false);
}
}
void printGetFillRate()
{
cout << " Enter the fill rate: ";
cin >> _fillRate;
25. pool.setFillRate(_fillRate);
}
void printGetDrainRate()
{
cout << " Enter the drain rate: ";
cin >> _drainRate;
pool.setDrainRate(_drainRate);
}
void printAddWater()
{
double currentwerVolume;
cout << " How much water would you like to add? "
<< " Response: ";
cin >> currentwerVolume;
if (currentwerVolume > pool.getVolume())
{
currentwerVolume = pool.getVolume();
cout << " You entered more than the pool could hold ("
<< pool.getVolume()
<< ") but I fixed that for you. ";
}
pool.setwerVolume(currentwerVolume);
}
void printDrainRate()
{
cout << " Drain rate is currently: "
<< pool.getDrainRate()
<< endl
<< endl;
}
void printFillRate()
{
cout << " Fill rate is currently: "
<< pool.getFillRate()
<< endl
<< endl;
26. }
char printWantwer()
{
char response;
cout << " The pool has no water to drain! "
<< " Would you like to add water?"
<< endl
<< endl
<< " Response: ";
cin >> response;
return response;
}
SwimmingPool.h
#pragma once
class SwimmingPool
{
public:
SwimmingPool();
SwimmingPool(double, double, double);
SwimmingPool(double, double, double, double, double);
void setLength(double);
void setWidth(double);
void setDepth(double);
void setDrainRate(double);
double getDrainRate();
void setFillRate(double);
double getFillRate();
void setFillTime(int);
void setDrainTime(int);
void setwerVolume(double);
double getVolume();
double getwerVolume();
double getFillAmount(double);
int getDrainTime();
int getFillTime();
27. double drain();
double fill();
double fill(int);
bool hasDimensions();
bool hasWater();
private:
double _length;
double _width;
double _depth;
double _fillRate;
double _drainRate;
int _fillTime;
int _drainTime;
double _volume;
double _waterVolume;
};
SwimmingPool.cpp
#include "SwimmingPool.h"
using namespace std;
// Default constructor
SwimmingPool::SwimmingPool()
{
_length = 0;
_width = 0;
_depth = 0;
}
// Basic constructor defined with member initialization
SwimmingPool::SwimmingPool (double l, double w, double d) :_length(l), _width(w),
_depth(d)
{
// Assign to the instance variables the arguments passed to constructo
_volume = _length * _width * _depth;
}
// Full Constructor
29. double SwimmingPool::getFillRate()
{
return _fillRate;
}
void SwimmingPool::setFillTime(int t)
{
_fillTime = t;
}
void SwimmingPool::setDrainTime(int t)
{
_drainTime = t;
}
// Member function to calculate volume
double SwimmingPool::getVolume()
{
// No need to check values of instance variables
// Return the volume
return _length * _width * _depth;
}
void SwimmingPool::setwerVolume(double v)
{
_waterVolume = v;
}
double SwimmingPool::getwerVolume()
{
return _waterVolume;
}
// Returns amount of water needed to fill an empty or partially filled pool
double SwimmingPool::getFillAmount(double currentwerVolume)
{
return getVolume() - currentwerVolume;
}
// Returns time needed to completely or partially drain the pool
int SwimmingPool::getDrainTime()
{
return (int)(_waterVolume/_drainRate);
30. }
// Returns the time need to completely or partially drain the pool
int SwimmingPool::getFillTime()
{
return (int)(getVolume()/_fillRate);
}
// Drain the pool for a specified time period
// Returns adjusted water volume
double SwimmingPool::drain()
{
double waterDrained = _drainRate * _drainTime;
_waterVolume -= waterDrained;
if (_waterVolume < 0)
_waterVolume = 0;
return waterDrained;
}
double SwimmingPool::fill()
{
_waterVolume += _fillRate * _fillTime;
return _waterVolume;
}
// Fill the pool for a specified time period
// Returns adjusted water volume
double SwimmingPool::fill(int time)
{
return 0;
}
bool SwimmingPool::hasDimensions()
{
if (_length > 0 && _width > 0 && _depth > 0)
return true;
else
return false;
}
bool SwimmingPool::hasWater()