Question
//Swimming Pool Header// #include using namespace std; #include SwimmingPool.h using namespace cs52; #ifndef SWIMMINGPOOL_H #define SWIMMINGPOOL_H #include using namespace std; namespace cs52{ class SwimmingPool {
//Swimming Pool Header//
#include
using namespace std;
#include "SwimmingPool.h"
using namespace cs52;
#ifndef SWIMMINGPOOL_H
#define SWIMMINGPOOL_H
#include
using namespace std;
namespace cs52{
class SwimmingPool {
public:
SwimmingPool( int size );
void fill( int amount );
void splash( );
void swim( );
void evaporate( int amount );
int getSize( );
int getContents( );
void setSize( int size );
SwimmingPool operator+ (SwimmingPool &);
SwimmingPool operator- (SwimmingPool &);
bool operator> (SwimmingPool &);
bool operator
bool operator!= (SwimmingPool &);
bool operator== (SwimmingPool &);
friend ostream& operator
friend istream& operator >> ( istream& ins, SwimmingPool & pool );
private:
int mySize; // how big the pool is
int myContents; // how full the pool is
};
}
#endif
**************************************************************
// Swimming pool //
#include "SwimmingPool.h"
#include
using namespace std;
namespace cs52{
SwimmingPool::SwimmingPool( int size ) {
mySize = size;
myContents = 0;
}
void SwimmingPool::fill( int amount ) {
if (amount
{ cout
system("pause");
}
if (myContents + amount > mySize)
{ cout
myContents= mySize;
}
else
myContents+=amount;
}
void SwimmingPool::splash( ) {
cout
}
void SwimmingPool::swim( ) {
cout
}
void SwimmingPool::evaporate( int amount ) {
if(amount
{ cout
system("pause");
}
if(myContents - amount
{ cout
myContents=0;
}
else
myContents -= amount;
}
int SwimmingPool::getSize( ) {
return( mySize );
}
int SwimmingPool::getContents( ) {
return( myContents );
}
void SwimmingPool::setSize( int size ) {
if(size
{ cout
system("pause");
}
mySize = size;
}
ostream& operator
{
outs
return outs;
}
istream& operator>>( std::istream& ins, SwimmingPool & pool )
{
cout
ins>>pool.mySize;
cout
ins>>pool.myContents;
return ins;
}
SwimmingPool SwimmingPool::operator+(SwimmingPool &pool)
{
int poolContents=pool.getContents();
int poolSize=pool.getSize();
int newSize=poolSize+ this->mySize;
SwimmingPool pool2(newSize);
int newContents= poolContents+this->myContents;
if( newContents > newSize)
{
cout
return 0;
}
pool2.fill(newContents);
return pool2;
}
SwimmingPool SwimmingPool::operator-(SwimmingPool &pool)
{
int poolContents=pool.getContents();
int poolSize=pool.getSize();
int newSize=this->mySize-poolSize;
SwimmingPool pool2(newSize);
int newContents= this->myContents - poolContents;
if( newContents
{
cout
return 0;
}
pool2.fill(newContents);
return pool2;
}
bool SwimmingPool::operator>(SwimmingPool &pool)
{
int poolSize=pool.getSize();
return (this->mySize > poolSize);
}
bool SwimmingPool::operator
{
int poolSize=pool.getSize();
return (this->mySize
}
bool SwimmingPool::operator!=(SwimmingPool &pool)
{
int poolSize=pool.getSize();
return (this->mySize != poolSize);
}
bool SwimmingPool::operator==(SwimmingPool &pool)
{
int poolSize=pool.getSize();
return (this->mySize == poolSize);
}
}
**************************************************************************
// Swimming pool driver code//
int main() {
SwimmingPool smallOne( 1 );
SwimmingPool bigOne( 1000 );
bigOne.fill( 100 );
SwimmingPool yours( 10 );
yours.fill( 1 );
SwimmingPool mine( 20 );
mine.fill( 19 );
cout
SwimmingPool pool1 = mine + mine;
SwimmingPool pool2 = yours - yours;
if (pool1 > pool2) {
cout is working..."
}
if (pool1 != pool2) {
cout
}
if (pool2
cout
}
if (pool1 == pool1) {
cout
}
cout
SwimmingPool badPool = smallOne - bigOne;
// this operator above should print
// out an error message...
system("pause");
}
Project 2: Inheritance n this assignment, you will explore both inheritance and exception handling. Start with your completed solution files from Project 1 (Swimming Pool.h, SwimmingPool.cpp, SwimmingPoolDriver.cpp). Please provide header and implementation files for each class and a driver file. Create two custom exception classes inheriting from std:logic error: Overflowin wimming PoolException and UnderflowingswimmingPoolException. Note that subclasses must call their parent class constructors in their initialization list. When an illegal operation is attempted, create and throw a custom exception, rather than just printing an error message. Include try...catch blocks in your driver code to catch any exceptions. Remember to add the statement #includeStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started