PLEASE HELP - NOT WORKING - URGENT

Task
Implement a Circle class. Each object of this class will represent a circle, storing its radius and the x and y coordinates of its center as floats. Include a default constructor, access functions, an area() function, and a circumference() function.
So far this is what I have done, I would greatly appreciate any help, Thank you



#include <iostream>
#include <conio.h>
#include <stdlib.h>
#include <stdlib.h>
#include <cmath>
#define PI 3.142

using namespace std;


class Circle
{


private:int r; //Data Members, declare r as an integer

float area, cir, x, y; //declare area, cir, x and y as floats

public:
Circle(); // Constructor
void getdata (void); // Methods
void putdata (void);
void calarea (void);
void calcir (void);
};
// Function Definitions
Circle :: Circle() // Constructor function

{
r = 0;
area = 0.0;


cir = 0.0;
x = 0.0;
y = 0.0;
}




void Circle :: getdata(void)
{
cout << "Please enter the radius of the circle ";
cin >> r;
cout << "Please enter the x co-ordinate of the center ";
cin >> x;
cout << "Please enter the y co-ordinate of the center ";
cin >> y;

}
void Circle :: putdata(void)
{
cout << endl;
cout << "Radius of the circle is : " << r << endl; //print with users input for r
cout << "The x-cordinate of the circle is : " << x << endl; //print with user input for x
cout << "The y-cordinate of the circle is : " << y << endl; //print with user input for y
cout << "Area of the circle is : " << PI * r * r << endl; //print with calculation answer for area
cout << "Circumference of the circle is : " << 2 * PI * r << endl; //print with calculation answer for circumference
}

main()


{
Circle c; // c is an object of class Circle

/* Here is where we clear the screen */
/*clrscr();*/
("cls");


/*system ("cls");*/


cout << " \t\t * TO IMPLEMENT A CLASS CIRCLE * \t\t " << endl;
c.getdata();
c.calarea();
c.calcir();
c.putdata();

return 0;
_getch();
}
// End of the Program
Hi, this is an example. Please read it carefully.

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
#include <iostream>
#include <iostream>
#include <cmath>
#define PI 3.142

using namespace std;


class Circle
{
	private:
	int r; //Data Members, declare r as an integer
	float area, cir, x, y; //declare area, cir, x and y as floats

	public:
		Circle(); // Constructor
		Circle(float, float, int);
		float getCirc();
		float getArea();
};
// Function Definitions
Circle :: Circle() // Constructor function
{
	r = 0;
	area = 0.0;


	cir = 0.0;
	x = 0.0;
	y = 0.0;
}


Circle::Circle(float x_, float y_, int r_) {
	x=x_;
	y=y_;
	r=r_;
}


float Circle::getArea() {
	return (float)M_PI*r*r;
}


float Circle::getCirc() {
	return (float)(2*M_PI*r);
}

int main()
{
	Circle c(1, 2, 3); // c is an object of class Circle

	cout << "The area is " << c.getArea() << endl;
	cout << "The circumference is " << c.getCirc() << endl;
	

	return 0;
}
// End of the Program 
Thank you so much minomic but some errors are showing up when I debug it.

error C2065: 'M_PI' : undeclared identifier
IntelliSense: identifier "M_PI" is undefined

I appreciate any help

Thank you
and there are no x or y co ordinates
Yes, M_PI is a known problem: some IDEs don't recognize it. You can substitute M_PI with a constant value 3.14...
For the x and y I don't understand the problem. I showed you a very simple example where I was passing 1, 2, 3 as parameters to the constructor: if you want to change them, you can ask the user to insert x, y and radius, then pass these values to the constructor.

Let me know if you need further help.
Ok, so here is a revised version of the code:

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
#include <iostream>
#include <cmath>

using namespace std;


class Circle
{
private:
  int r; //Data Members, declare r as an integer
  float x, y; //declare area, cir, x and y as floats

public:
  Circle(); // Constructor
  Circle(float, float, int);
  float getCirc();
  float getArea();
};

// Function Definitions
Circle :: Circle() // Constructor function
{
  r = 0;
  x = 0.0;
  y = 0.0;
}


Circle::Circle(float x_, float y_, int r_) {
  x=x_;
  y=y_;
  r=r_;
}


float Circle::getArea() {
  return (float)M_PI*r*r;
}


float Circle::getCirc() {
  return (float)(2*M_PI*r);
}


int main()
{
  float x, y;
  int radius;
  cout << "Insert centre x: ";
  cin >> x;
  cout << "Insert centre y: ";
  cin >> y;
  cout << "Insert radius: ";
  cin >> radius;
  Circle c(x, y, radius); // c is an object of class Circle

  cout << "The area is " << c.getArea() << endl;
  cout << "The circumference is " << c.getCirc() << endl;

  return 0;
}
// End of the Program 
Topic archived. No new replies allowed.