Linking Error

Hi. I'm writing code that has to do with classes. I have it almost finished, but I'm getting a linking error. Here is the prompt:

Write the definition of a class, swimmingPool, to implement the properties of a swimming pool.
Your class should have the instance variables to store the length (in feet), width (in feet), depth (in
feet), the rate (in gallons per minute) at which the water is filling the pool, and the rate (in gallons per
minute) at which the water is draining from the pool.
Add appropriate constructors to initialize the instance variables.
Also add member functions to do the following:
• determine the amount of water needed to fill an empty or partially filled pool;
• determine the time needed to completely or partially fill or empty the pool;
• add or drain water for a specific amount of time.
Note:
There are 7.48 GALLONS_IN_A_CUBIC_FEET. You’ll need this to estimate the
poolTotalWaterCapacity( ).
You should input Pool length, width, and depth (e.g., 30,15,10).
Based on these values, output “Total pool water capacity”.
Then, input …water fill in rate to completely fill the pool.
Based on all above values, output the “Time to fill the pool”.

--
Here are the three files for the code I set up:

-----
[main.cpp]



#include "swimmingPoolImp.cpp"

int main()
{
double length, width, depth, rateFill, rateDrain;

cout << "Please enter the length: " << endl;
cin >> length;
cout << "Please enter the width: " << endl;
cin >> width;
cout << "Please enter the depth: " << endl;
cin >> depth;
cout << "Please enter the rate in which water fills the pool: " << endl;
cin >> rateFill;
cout << "Please enter the rate in which water drains the pool: " << endl;
cin >> rateDrain;

swimmingPool myPool(length, width, depth, rateFill, rateDrain);
double waterCapacity = myPool.poolTotalWaterCapacity();
cout << "Total water capacity: " << waterCapacity << endl;

double timeToFillPool = myPool.timeNeededToFill();
cout << "Time to fill the pool: " << timeToFillPool;

return 0;
}

[/main.cpp]
-----


-----
[swimmingPoolImp.cpp]

#include "swimmingPool.h"
#include <iostream>
using namespace std;

swimmingPool::swimmingPool()
{
length = 0;
width = 0;
depth = 0;
rateWaterDrainsPool = 0;
rateWaterFillsPool = 0;
}
swimmingPool::swimmingPool(double l, double w, double d, double rateFill, double rateDrain)
{
length = l;
width = w;
depth = d;
rateWaterFillsPool = rateFill;
rateWaterDrainsPool = rateDrain;
}
double swimmingPool::amountWaterNeeded()
{
return (length * width * depth) * GALLONS_IN_A_CUBIC_FOOT;
}
double swimmingPool::timeNeededToFill()
{
return poolTotalWaterCapacity() / rateWaterDrainsPool;
}
double swimmingPool::addWater(double time)
{
return rateWaterDrainsPool * time;
}
double swimmingPool::drainWater(double time)
{
return rateWaterDrainsPool * time;
}
double swimmingPool::poolTotalWaterCapacity()
{
return (length*width*depth)*GALLONS_IN_A_CUBIC_FOOT;
}


[/swimmingPoolImp.cpp]
-----

-----
[swimmingPool.h]



class swimmingPool
{
public:
swimmingPool();
swimmingPool(double l, double w, double d, double rateFill, double rateDrain);
double amountWaterNeeded();
double timeNeededToFill();
double addWater(double time);
double drainWater(double time);
double poolTotalWaterCapacity();

#define GALLONS_IN_A_CUBIC_FOOT 7.48;
private:
double length;
double width;
double depth;
double rateWaterFillsPool;
double rateWaterDrainsPool;
};


[/swimmingPool.h]
-----


When the program is run, this is the error message I get:

'clang: error: linker command failed with exit code 1 (use -v to see invocation)'


---



An answer would help greatly! Thank you in advance!
multiple definition: http://www.cplusplus.com/forum/general/140198/


> this is the error message I get:
>> clang: error: linker command failed with exit code 1 (use -v to see invocation)'
you leave out all the important part of the message
This is easy to fix.
You need to include in the main "swimmingPool.h" and not cpp.
in the swimmingPool.h u only need to add the class and the functions but not initialized.
In the swimmingpoolimt.cpp etc... you need to initialize the functions of. and also include swimming...h and iostream plus using namespace std;....
Topic archived. No new replies allowed.