Problem calling functions from a class
Dec 1, 2016 at 11:08pm UTC
My goal is to create a program including a class that displays the radius, diameter, and area of 2 circles. One of the circles radius is given using a constructor and the other accepts input. I'm having an issue where its telling me "non-standard syntax; use '&' to create a pointer to member" on the lines 125, 129, and 130. I am confused because it isn't returning an error on the lines with the other modules even though most of them are exactly the same just using the variable from a different circle. Any help is greatly appreciated, thank you.
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 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134
#include <iostream>
#include <string>
using namespace std;
//Programmer: Curtis Moffitt
class Circle
{
private :
double radius1;
double radius2;
public :
const double Pi = 3.14;
Circle(); //constructor
//void setradius2(double);
/*void setRadius2(double r)
{
if (r >= 0)
radius2 = r;
else {
cout << "Invalid radius " << endl;
exit(EXIT_FAILURE);
}
return;
}*/
double getradius1()
{
return radius1;
}
double getArea1() //const
{
return Pi * radius1 * radius1;
}
double getDiameter1()// const
{
return radius1 * 2;
}
double getradius2()
{
cout << "Input a radius for your circle" << endl;
cin >> radius2;
if (radius2 >= 0)
return radius2;
else {
cout << "Invalid radius " << endl;
exit(EXIT_FAILURE);
}
}
double getArea2() //const
{
return Pi * radius2 * radius2;
}
double getDiameter2() //const
{
return radius2 * 2;
}
//void inputCircle();
void displayCircle1();
void displayCircle2();
};
Circle::Circle()
{
radius1 = 1.0;
}
/*void Circle::setRadius2(double r)
{
if (r >= 0)
radius2 = r;
else {
cout << "Invalid radius " << endl;
exit(EXIT_FAILURE);
}
} */
/*void Circle::inputCircle()
{
cout << "Enter the radius of your Circle: " << endl;
cin >> radius2;
}*/
void Circle::displayCircle1()
{
cout << endl;
cout << "Here is our circle's data: \n" ;
cout << "Radius = " << radius1 << endl;
cout << "Diameter =" << radius1 * 2 << endl;
cout << "Area = " << Pi * radius1 * radius1 << endl;
}
void Circle::displayCircle2()
{
cout << "Here is your circle's data: \n" ;
cout << "Radius = " << radius2 << endl;
cout << "Diameter = " << radius2 * 2 << endl;
cout << "Area = " << Pi * radius2 * radius2 << endl;
}
int main() {
Circle circle;
circle.getradius1();
circle.getArea1();
circle.getDiameter1();
//circle.setRadius2();
circle.getradius2;
circle.getArea2();
circle.getDiameter2();
//circle.inputcircle();
circle.displayCircle1;
circle.displayCircle2;
system("pause" );
}
Dec 1, 2016 at 11:32pm UTC
You've forgotten the parentheses.
Dec 1, 2016 at 11:35pm UTC
Wow, I need to get some sleep. Thanks so much
Topic archived. No new replies allowed.