I'm in my 201 programming class and we have an assignment dealing with a class. I have a decent handle on everything so far, but right now I'm stuck with my code and I'm hung up on my class member functions, namely the accessor and mutator.
I get these 2 errors when I compile...Code:#include <iostream> #include <math.h> using namespace std; class circle { private: int radius; int circumference; int area; public: void caclulateArea(); void calculateCircumference(); void displayOutput(); void setRadius(); //mutator int getRadius(int userRadius); //accessor }; int main () { int userRadius = 0; const double PI = 3.141592; circle test; circle::getRadius(userRadius); circle::setRadius(); test.getRadius(userRadius); test.setRadius(); test.caclulateArea(); test.calculateCircumference(); } /****************************** calculateArea Description : Takes radius and squares it and multiplies it by pi Parameters input : radius, PI output : Returns : Preconditions: must be a positive number ------------------------------------------------------------------------------*/ void calculateArea(int radius,const double PI) { double area = pow (radius * PI, 2); } /************************** calculateCircumference Description : Takes radius and squares it and multiplies it by pi Parameters input : radius, PI output : none Returns : none Preconditions: none ------------------------------------------------------------------------------*/ void calculateCircumference(int radius, const double PI) { double Circumference = (radius * PI * 2); } /****************************** displayOutput Description : displays the answers on the console Parameters input : none output : radius, area, circumference Returns : none Preconditions: none ------------------------------------------------------------------------------*/ void displayOutput(int radius, int area, int circumference) { cout << "Using " << radius << " as the radius" << endl; cout << "The area would be " << area << endl; cout << "The circumference would be " << circumference << endl; } /****************************** getRadius Description : gets the radius from the user Parameters input : userRadius output : none Returns : userRadius Preconditions: none ------------------------------------------------------------------------------*/ int circle::getRadius(int userRadius) { cout << "This program will calculate the area and circumference of " << endl; cout << "a circle based off of the radius using a class." << endl; cout << "Enter the radius --> " << endl; cin >> radius; return userRadius; } /****************************** setRadius Description : sets the radius into the class by way of userRadius Parameters input : none output : none Returns : none Preconditions: none ------------------------------------------------------------------------------*/ void circle::setRadius() { int radius = 0; int userRadius = radius; }
1>c:\school\c201\c201 homework3\hw3.cpp(33) : error C2352: 'circle::getRadius' : illegal call of non-static member function
1> c:\school\c201\c201 homework3\hw3.cpp(24) : see declaration of 'circle::getRadius'
1>c:\school\c201\c201 homework3\hw3.cpp(34) : error C2352: 'circle::setRadius' : illegal call of non-static member function
1> c:\school\c201\c201 homework3\hw3.cpp(23) : see declaration of 'circle::setRadius'
I don't know if its something with my scope resolution or if I'm supposed to be using a dot operator instead. In the error messages it mentions static member functions but we haven't covered that and the professor said not to use any static functions or variables. Thanks in advance for any help.



LinkBack URL
About LinkBacks



I used to be an adventurer like you... then I took an arrow to the knee.