I need some help on calling functions. I have worked on this for three weeks. Time is up. Here is the errors I am receiving. Can someone tell me why is it throwing these errors?
||=== Build: Debug in Area (compiler: GNU GCC Compiler) ===|
|In function 'int main()':|
main.cpp|35|error: request for member 'getArea' in 'circle', which is of non-class type 'Circle()'|
|42|error: request for member 'getArea' in 'square', which is of non-class type 'Square()'|
||=== Build failed: 2 error(s), 0 warning(s) (0 minute(s), 1 second(s)) ===|
If you ever get stuck for more than an hour or so, seek help. It isn't worth banging your head against the problem.
Lines 14 & 15 declare two functions named square and circle. You want to declare variables. Do it like this:
1 2
Square square;
Circle circle;
Line 151: setLength() is misspelled. Also, the function needs to be defined in square.cpp
Lines 75 & 98: Because the area of a circle with an integer radius can be a real number, getArea() should return a double, not an int. You don't need to make the same change to class Square because if the length is an integer, then the area is an integer also.
Line 76. PI is not 3.14. Use more digits, like 3.141592653589793
Try removing the () from lines 14 and 15, the compiler probably thinks that those lines are function prototypes not creating instances of your classes.
That's only part of the error message. It means that something was not found during the linking stage. The rest of the message will state what that "something" was.
At a guess, you didn't include all of the .cpp files in the build.
you don't do anything further with that value. You need to use it to either modify the existing object, or construct a new one, using the supplied value.
1 2
cin >> radius;
circle.setRadius(radius);
1 2
cin >> radius;
Circle circle(radius);
The first of these makes sense, since you have an existing circle object. However, you should probably at least test the other approach to verify that the constructor is working correctly.
By the way, since the value of pi is a floating-point value, and consequently the area will be too, you might make all of the variables length, radius and function parameters and return types double rather than int.