Fair Warning, this question is a beginner crap fest.
My code is completely nonfunctional due to my general lack of knowledge.
Please just skip if this seems too tedious.
So I am in a second semester c++ class, but I don't know c++, like any of it, at all... The reason for this is that my school apparently doesn't have second semester classes for other languages, but requires a second semester to be take regardless of what language you took the first semester.
So with that in mind, and the fact that i'm already bad at OOP:
I am trying to make a program with an object of a swimming pool, with basic dimensions for the pool as well as some basic function, like figure out how much time it would take to fill the pool.
I had it all running in one file, but I have to separate into multiple, and when I tried to do that, well... it stopped working.
If someone could just point out the biggest mistakes I'm making I would appreciate it.
main.cpp
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
|
#include <iostream>
#include "swimmingPoolImp.cpp"
// driver function
int main()
{
swimmingPool sp(40, 30, 5, 1000, 20, 40);
std::cout << "Total Volume of the pool: " << sp.getLength() * sp.getWidth() * sp.getDepth() << "\n\n";
std::cout << "Current Volume of water in pool: " << sp.getVolume() << " cubic feet\n\n";
std::cout << "Volume needed to fill the pool: " << sp.waterNeeded() << " cubic feet\n\n";
double timeToFill = sp.timeToFill();
std::cout << "Time needed to fill the pool: " << timeToFill << " minutes\n\n";
std::cout << "Filling the pool for " << timeToFill << " minutes...\n\n";
sp.addWater(timeToFill);
double timeToDrain = sp.timeToEmpty();
std::cout << "Time needed to drain the pool: " << timeToDrain << " minutes\n\n";
std::cout << "Draining the pool for " << timeToDrain << " minutes...\n\n";
sp.drainWater(timeToDrain);
std::cout << "Current Volume of water in pool: " << sp.getVolume() << " cubic feet\n\n";
return 0;
}
|
swimmingPool.h
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
|
// SwimmingPool class
class swimmingPool
{
private:
double length;
double width;
double depth;
double currVolume;
double inFlowRate;
double outFlowRate;
public:
// parameterized constructor with default values
swimmingPool(double _length = 1, double _width = 1, double _depth = 1, double _volume = 1, double _inFlowRate = 1, double _outFlowRate = 1)
{
length = (_length > 0) ? _length : 1;
width = (_width > 0) ? _width : 1;
depth = (_depth > 0) ? _depth : 1;
currVolume = (_volume > 0) ? _volume : 1;
inFlowRate = (_inFlowRate > 0) ? _inFlowRate : 1;
outFlowRate = (_outFlowRate > 0) ? _outFlowRate : 1;
}
// accessors
void setLength(double _length) { length = _length; }
void setWidth(double _width) { width = _width; }
void setDepth(double _depth) { depth = _depth; }
void setVolume(double _volume) { currVolume = _volume; }
void setInFlowRate(double _inFlowRate) { inFlowRate = _inFlowRate; }
void setOutFlowRate(double _outFlowRate) { outFlowRate = _outFlowRate; }
// mutators
double getLength() { return length; }
double getWidth() { return width; }
double getDepth() { return depth; }
double getVolume() { return currVolume; }
double getInFlowRate() { return inFlowRate; }
double getOutFlowRate() { return outFlowRate; }
double waterNeeded();
double timeToFill();
double timeToEmpty();
void addWater(){ ;}
double drainWater;
};
|
swimmingPoolImp.cpp
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
|
#include <iostream>
#include "swimmingPool.h"
using namespace std;
// swimmingPool::swimmingPool(double l,double w,double d,double cV,double iFR,double oFR);
// function to determine the amount of water needed to fill a pool
double swimmingPool::waterNeeded()
{
// find the volume of water that is unfilled in the swimming pool
// this will be the amount of water needed to fill the pool
double unfilledVolume = (length * width * depth) - currVolume;
return unfilledVolume;
}
// function to determine the time needed to fill the pool
double swimmingPool::timeToFill()
{
double hoursToFill = waterNeeded() / inFlowRate;
return hoursToFill;
}
// function to determine the time needed to empty the pool
double swimmingPool::timeToEmpty()
{
double hoursToEmpty = currVolume / outFlowRate;
return hoursToEmpty;
}
// function to add water for a specific time
void swimmingPool::addWater(double timeInMin)
{
double amountToAdd = timeInMin * inFlowRate;
currVolume += amountToAdd;
}
// function to drain water for a specific time
void swimmingPool::drainWater(double timeInMin)
{
double amountToDrain = timeInMin * outFlowRate;
currVolume -= amountToDrain;
}
|