help with output and functions

Pages: 12
i need help with the output because im getting most of the information but some of it doesnt make sense?i think two of my function are wrong addwater which is when i call it i get and error and the other one is drain water i dont think the formatting is right so anyone could help me please and thank you
test driver
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
#include <iostream>
#include "poool.h"
using namespace std;

int main()
{
    double l;
    double w;
    double d;
    double fi;
    double fo;
    double wInPool;
    poool pool;

    cout << "enter length "<< endl;
    cin >> l;
    cout << "enter width" << endl;
    cin >> w;
    cout << "enter depth "<< endl;
    cin >> d;
    cout << "enter the flow rate in " << endl;
    cin >> fi;
    cout << "enter the flow rate out "<< endl;
    cin >> fo;
    cout << "enter the water in the pool (in gallons)" << endl;
    cin >> wInPool;

    pool.setData(l,w,d,fi,fo,wInPool);

    cout << "pool data "<< endl;
    cout << "length: " << pool.getLenght() << "feet" << endl;//get the length
    cout << "width: "<< pool.getWidth() << " feet" << endl;//get the width
    cout << "depth: "<< pool.getDepth() << " feet" << endl;//get the depth
    cout << "amount of water in pool : " << pool.getTotalWaterInPool() << " gallons" << endl;//get total water
    cout << "fill rate : "<< pool.getWaterFlowRateIn() << "gal/hr" << endl;//get water flow rate in
    cout << "drain rate: " << pool.getWaterFlowRateOut() << "gal/hr" << endl;//get water flow rate out
    cout << "water needed to fill the pool: " << pool.poolTotalWaterCapacity() << " gallons" << endl;
    cout <<"time needed to fill the pool: " << pool.timeToFillPool()/60 << " hours " << endl;
    cout << "after filling pool to it capacity amount of water in pool: " << pool.getTotalWaterInPool() << endl;
    cout << "time needed to drain the pool completely:  " << pool.timeToDrainThePool()/60 << "hours"<< endl;
    cout << "amount of water left after draining half the pool: " << pool.getTotalWaterInPool()/2 << "gallons" << endl;
    cout << "time need to fill the pool if it half full: " << pool.getTotalWaterInPool() << " hours " << endl;
    cout << "amount of water after adding water for additional 3 hours " << pool.getTotalWaterInPool() << "gallons" << endl;
    return 0; 

header file
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
  #ifndef POOOL_H
#define POOOL_H

const double gallonsInCubicFoot=7.48;
class poool
{
    public:
        void setData(double l, double w, double d, double fi, double fo, double wInPool);
        void setLength(double l);
        void setWidth(double w);
        void setDepth(double d);
        void setWaterFlowRateIn(double fi);
        void setWaterFlowRateOut(double fo);
        void addWater(double time, double rate);
        void drainWater(double time, double rate);
        double poolTotalWaterCapacity();
        double getLenght();
        double getWidth();
        double getDepth();
        double getWaterFlowRateIn();
        double getWaterFlowRateOut();
        double getTotalWaterInPool();
        int timeToFillPool();
        int timeToDrainThePool();
        double waterNeedToFillPool();
        poool();
        private:

        double length;
        double width;
        double depth;
        double waterFlowInRate;
        double waterFlowOutRate;
        double amountOfWaterInPool;

};

functions
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
#include <iostream>
#include "poool.h"

poool::poool()
{
    double l = 0;
    double w = 0;
    double d = 0;
    double fi = 0;
    double fo = 0;
    double wInPool = 0;

}
void poool::setData(double l, double w, double d, double fi, double fo, double wInPool)
{
    length=l;
    width=w;
    depth=d;
    waterFlowInRate=fi;
    waterFlowOutRate=fo;
    amountOfWaterInPool=wInPool;
}
void poool::addWater(double time, double rate)//here
{
    double amount_added = rate*time ;

    amountOfWaterInPool += amount_added ;

    if (amountOfWaterInPool > poolTotalWaterCapacity())
        amountOfWaterInPool = poolTotalWaterCapacity();

}
void poool::drainWater(double time, double rate)//here
{
    double amountDrain = rate*time;
    amountOfWaterInPool -= amountDrain;
    if(amountOfWaterInPool < poolTotalWaterCapacity())
        amountOfWaterInPool = poolTotalWaterCapacity();

}
double poool::poolTotalWaterCapacity()
{
   return amountOfWaterInPool=(length * width * depth) *gallonsInCubicFoot;
}
int poool::timeToFillPool()
{
    double waterDifference;
    waterDifference =poolTotalWaterCapacity() - getTotalWaterInPool();

    return waterDifference/waterFlowInRate;
}
int poool::timeToDrainThePool()
{
    return amountOfWaterInPool / waterFlowOutRate;
}
double poool::waterNeedToFillPool()
{
    double waterNeedToFillPool;
    waterNeedToFillPool  = poolTotalWaterCapacity() - amountOfWaterInPool;

    return waterNeedToFillPool;
}
double poool::getLenght()
{
    return length;
}
double poool::getWidth()
{
    return width;
}
double poool::getDepth()
{
    return depth;
}
double poool::getWaterFlowRateIn()
{
    return waterFlowInRate;
}
double poool::getWaterFlowRateOut()
{
    return waterFlowOutRate;
}
double poool::getTotalWaterInPool()
{
    return amountOfWaterInPool;

}
void poool::setLength(double l)
{
     l = length;
}
void poool::setWidth(double w)
{
    w=width;
}
void poool::setDepth(double d)
{
    d =depth;
}
void poool::setWaterFlowRateIn(double fi)
{
    fi = waterFlowInRate;
}
void poool::setWaterFlowRateOut(double fo)
{
    fo = waterFlowOutRate;
}

thank you
pool.cpp @5..10
these are new local vars, and do not initialise your members.
replace them with a call to setData(0.0, 0.0, 0.0, 0.0, 0.0, 0.0)

drainWater 37..38
the water is going down, did you mean
1
2
 if (amountOfWaterInPool <0.0)
    amountOfWaterInPool = 0.0;


addWater()
You make a call to poolTotalWaterCapacity()
@43 did you mean return (length * width * depth) *gallonsInCubicFoot;


@88..107
All of these setters have their assignments the wrong way round.
eg; d = depth; should be depth = d;
Last edited on
im little confused with setdata where it should go

the drain water and add water im not following what u are saying

im sorry

in your poool ctor.
1
2
3
4
5
6
7
8
9
10
poool::poool()
{
    double l = 0;
    double w = 0;
    double d = 0;
    double fi = 0;
    double fo = 0;
    double wInPool = 0;

}

all of these doubles are local variables that will go away when the function returns. they dont initialise your class member variables.

you could replace them with
1
2
3
4
5
6
7
8
poool::poool()
{
    width = 0;
    depth = 0;
    lebgth = 0;
    
   etc...
}

or just
1
2
3
4
poool::poool()
{
   setData(0.0, 0.0, 0.0, 0.0, 0.0, 0.0);
}



drainPool()
1
2
3
   if(amountOfWaterInPool < poolTotalWaterCapacity())
        amountOfWaterInPool = poolTotalWaterCapacity();

your check in here says "if the pool isnt full, make it full".
it should be checking the pool isnt less than empty.
1
2
 if (amountOfWaterInPool <0.0)
    amountOfWaterInPool = 0.0;


addWater() is fine, "if the pool has more than maximum, set it to maximum"
1
2
3
    if (amountOfWaterInPool > poolTotalWaterCapacity())
        amountOfWaterInPool = poolTotalWaterCapacity();

It calls out to poolTotalWaterCapacity() which contains amountOfWaterInPool=(length * width * depth) *gallonsInCubicFoot; which is an assignment statement. whenever you call it it will set amountOfWaterInPool to be the maximum, even while you are still filling it.

the true maximum capacity is (length * width * depth) *gallonsInCubicFoot so just return that.

thanx for the help

question:

but when i output the data i get time needed to fill the pool 0
time need to fill the pool if it half full it should be 14 hours
amount of the water after an additional 3 hours is 33660 gallons

those three are the output im having trouble with
it should be
Time needed to fill the pool: 28 hours
Time needed to fill the pool if it is half full: 14 hours
Amount of water after adding water an additional 3 hours: 20431.5
You will need to make the changes before seeing better results.
but in short addWater() calls poolTotalWaterCapacity() which sets amountOfWaterInPool to be the pools max capacity (w*l*h*gallonsInCubicFoot)

so the very first call to addWater() will set amountOfWaterInPool to be the maximum. so fills the pool instantly.
but when i call addwater i get an error saying

error: no matching function for call to 'poool::addWater()'
candidate is:
void poool::addWater(double, double)
candidate expects 2 arguments, 0 provided
yes, because addWater needs 2 parameters.
void poool::addWater(double time, double rate)

you will need to include the time and rate.

eg;
addWater(some_amount_of_time,some_fill_rate);
also i get the same thing with drainWater
same with apply for drain in my pool that mean i would have to make a cout statement in my main and ask for the time and rate?
Last edited on
yes, you need to ask for fill rate and time and drain rate and time.

without those you cant calculate how long it will take.

you already have fi and fo, you just need to know how long for.
Last edited on
im sorry i keep asking question but now im getting an error again =[
""no match for 'operator<<' (operand types are 'std::basic_ostream<char>' and 'void')|"" here the error
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
46
47
48
49
50
51
52
53
54
    double l;
    double w;
    double d;
    double fi;
    double fo;
    double wInPool;
    double time;
    double rate;
    double rate2;
    double time2;
    poool pool;

    cout << "enter length "<< endl;
    cin >> l;
    cout << "enter width" << endl;
    cin >> w;
    cout << "enter depth "<< endl;
    cin >> d;
    cout << "enter the flow rate in " << endl;
    cin >> fi;
    cout << "enter the flow rate out "<< endl;
    cin >> fo;
    cout << "enter the water in the pool (in gallons)" << endl;
    cin >> wInPool;
    cout << "enter the time of add water "<< endl;
    cin >> time;
    cout << "enter the rate of add water" << endl;
    cin >> rate;
     cout << "enter the time of drain water "<< endl;
    cin >> time2;
    cout << "enter the rate of drain water" << endl;
    cin >> rate2;

    pool.addWater(time, rate);
    pool.drainWater(time2,rate2);

    pool.setData(l,w,d,fi,fo,wInPool);

    cout << "pool data "<< endl;
    cout << "length: " << pool.getLenght() << "feet" << endl;//get the length
    cout << "width: "<< pool.getWidth() << " feet" << endl;//get the width
    cout << "depth: "<< pool.getDepth() << " feet" << endl;//get the depth
    cout << "amount of water in pool : " << pool.addWater(time, rate) << " gallons" << endl;//get total water
    cout << "fill rate : "<< pool.getWaterFlowRateIn() << "gal/hr" << endl;//get water flow rate in
    cout << "drain rate: " << pool.getWaterFlowRateOut() << "gal/hr" << endl;//get water flow rate out
    cout << "water needed to fill the pool: " << pool.poolTotalWaterCapacity() << " gallons" << endl;
    cout <<"time needed to fill the pool: " << pool.timeToFillPool()/60 << " hours " << endl;
    cout << "after filling pool to it capacity amount of water in pool: " << pool.getTotalWaterInPool() << endl;
    cout << "time needed to drain the pool completely:  " << pool.timeToDrainThePool()/60 << "hours"<< endl;
    cout << "amount of water left after draining half the pool: " << pool.getTotalWaterInPool()/2 << "gallons" << endl;
    cout << "time need to fill the pool if it half full: " << pool.drainWater(time2 ,rate2) << " hours " << endl;
    cout << "amount of water after adding water for additional 3 hours " << pool.getTotalWaterInPool() << "gallons" << endl;


and thanx again
Last edited on
you already had flow rate in and flow rate out, you didn't need to add them again.

you dont need to add or drain water to perform the calculations.

also, I was incorrect in asking the user for times, you only need the 3 hours for your output.

try this.

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
{
	double l;
	double w;
	double d;
	double fi;
	double fo;
	double wInPool;
	poool pool;

	cout << "enter length " << endl;
	cin >> l;
	cout << "enter width" << endl;
	cin >> w;
	cout << "enter depth " << endl;
	cin >> d;
	cout << "enter the flow rate in " << endl;
	cin >> fi;
	cout << "enter the flow rate out " << endl;
	cin >> fo;
	cout << "enter the water in the pool (in gallons)" << endl;
	cin >> wInPool;

	pool.setData(l, w, d, fi, fo, wInPool);

	cout << "pool data " << endl;
	cout << "length: " << pool.getLenght() << "feet" << endl;//get the length
	cout << "width: " << pool.getWidth() << " feet" << endl;//get the width
	cout << "depth: " << pool.getDepth() << " feet" << endl;//get the depth
	cout << "amount of water in pool : " << pool.getTotalWaterInPool() << " gallons" << endl;//get total water
	cout << "fill rate : " << pool.getWaterFlowRateIn() << "gal/hr" << endl;//get water flow rate in
	cout << "drain rate: " << pool.getWaterFlowRateOut() << "gal/hr" << endl;//get water flow rate out
	cout << "water needed to fill the pool: " << pool.waterNeedToFillPool() << " gallons" << endl;
	cout << "time needed to fill the pool: " << pool.timeToFillPool() << " hours " << endl;
	cout << "after filling pool to it capacity amount of water in pool: " << pool.poolTotalWaterCapacity() << endl;
	cout << "time needed to drain the pool completely:  " << pool.timeToDrainThePool() << "hours" << endl;
	cout << "amount of water left after draining half the pool: " << pool.getTotalWaterInPool() / 2 << "gallons" << endl;
	cout << "time need to fill the pool if it half full: " << pool.timeToFillPool()/2.0 << " hours " << endl;

	pool.addWater(3, fi);
	cout << "amount of water after adding water for additional 3 hours " << pool.getTotalWaterInPool() << "gallons" << endl;
	return 0;
}


my output
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
enter width
10
enter depth
10
enter the flow rate in
1
enter the flow rate out
1
enter the water in the pool (in gallons)
10
pool data
length: 10feet
width: 10 feet
depth: 10 feet
amount of water in pool : 10 gallons
fill rate : 1gal/hr
drain rate: 1gal/hr
water needed to fill the pool: 7470 gallons
time needed to fill the pool: 7470 hours
after filling pool to it capacity amount of water in pool: 7480
time needed to drain the pool completely:  10hours
amount of water left after draining half the pool: 5gallons
time need to fill the pool if it half full: 3735 hours
amount of water after adding water for additional 3 hours 13gallons


there is one mistake in there
time need to fill the pool if it half full: 3735 hours
you will need to add a method to pool. timeToFillPoolFromEmpty()

i keep getting 0 for water and time needed and i would have to make another function
If you made the changes I suggested your pool class should look like this.

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
const double gallonsInCubicFoot = 7.48;
class poool
{
public:
	void setData(double l, double w, double d, double fi, double fo, double wInPool);
	void setLength(double l);
	void setWidth(double w);
	void setDepth(double d);
	void setWaterFlowRateIn(double fi);
	void setWaterFlowRateOut(double fo);
	void addWater(double time, double rate);
	void drainWater(double time, double rate);
	double poolTotalWaterCapacity();
	double getLenght();
	double getWidth();
	double getDepth();
	double getWaterFlowRateIn();
	double getWaterFlowRateOut();
	double getTotalWaterInPool();
	double  timeToFillPool();
	double  timeToDrainThePool();
	double waterNeedToFillPool();
	poool();
private:

	double length;
	double width;
	double depth;
	double waterFlowInRate;
	double waterFlowOutRate;
	double amountOfWaterInPool;

};




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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
#include <iostream>
#include "pool.h"

poool::poool()
{
	setData(0.0, 0.0, 0.0, 0.0, 0.0, 0.0);
}
void poool::setData(double l, double w, double d, double fi, double fo, double wInPool)
{
	length = l;
	width = w;
	depth = d;
	waterFlowInRate = fi;
	waterFlowOutRate = fo;
	amountOfWaterInPool = wInPool;
}
void poool::addWater(double time, double rate)//here
{
	double amount_added = rate*time;

	amountOfWaterInPool += amount_added;

	if (amountOfWaterInPool > poolTotalWaterCapacity())
		amountOfWaterInPool = poolTotalWaterCapacity();

}
void poool::drainWater(double time, double rate)//here
{
	double amountDrain = rate*time;
	amountOfWaterInPool -= amountDrain;
	if (amountOfWaterInPool <0.0)
		amountOfWaterInPool = 0.0;

}
double poool::poolTotalWaterCapacity()
{
	return (length * width * depth) *gallonsInCubicFoot;
}
double  poool::timeToFillPool()
{
	double waterDifference;
	waterDifference = poolTotalWaterCapacity() - getTotalWaterInPool();

	return waterDifference / waterFlowInRate;
}
double poool::timeToDrainThePool()
{
	return amountOfWaterInPool / waterFlowOutRate;
}
double poool::waterNeedToFillPool()
{
	double waterNeedToFillPool;
	waterNeedToFillPool = poolTotalWaterCapacity() - amountOfWaterInPool;

	return waterNeedToFillPool;
}
double poool::getLenght()
{
	return length;
}
double poool::getWidth()
{
	return width;
}
double poool::getDepth()
{
	return depth;
}
double poool::getWaterFlowRateIn()
{
	return waterFlowInRate;
}
double poool::getWaterFlowRateOut()
{
	return waterFlowOutRate;
}
double poool::getTotalWaterInPool()
{
	return amountOfWaterInPool;

}
void poool::setLength(double l)
{
	l = length;
}
void poool::setWidth(double w)
{
	w = width;
}
void poool::setDepth(double d)
{
	d = depth;
}
void poool::setWaterFlowRateIn(double fi)
{
	fi = waterFlowInRate;
}
void poool::setWaterFlowRateOut(double fo)
{
	fo = waterFlowOutRate;
}


EDIT: I removed #include "stdafx.h" you dont need that.
Last edited on
i got it but im stuck i dont know what to do i dont know why it keeps giving me wrong data

the last 3 chunks of code that i posted are the complete program that i ran on my pc.

setWidth() setLength() setDepth() setWaterFlowRateIn() and setWaterFlowRateOut() are still incorrect but they aren't used so make no difference.

as an experiment create a new project and add the code i posted and you should get the same results i did.

then you can compare to see where you went wrong.
now im getting 0 for time needed to drain compeletly and amount of water left after draining and time needed to full the pool if half full..smh
post your output so we can see it.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
Pool data:
Length: 30 feet
Width: 15 feet
Depth: 10 feet
Amount of water in pool: 0 gallons
Fill Rate: 20 gal/min
Drain Rate: 19.5 gal/min
Water needed to fill the pool: 33660 gallons
Time needed to fill the pool: 28 .05 hours
After filling pool to capacity, amount of water in pool is: 33660 gallons
Time needed to drain the pool completely: 0hours
Amount of water left after draining half the pool: 0gallons
Time needed to fill the pool if it is half full: 0hours
Amount of water after adding water an additional 3 hours: 60 gallons

output
Last edited on
Pages: 12