You are on page 1of 3

LABORATORY 3 SOLUTIONS

AIM:
To write a complete c++ class to represent a circle in 2D space.

CODE:
“Circle.h”
#pragma once
#include<iostream>

using namespace std;


class circle
{
int x, y;
int h, k;
double r;
public:
circle()
{
x = 0;
y = 0;
r = 10;

cout << "radius " << r << " at a point x = " << x << " y = " << y << endl;
}
circle(int, int, double);
void move(int, int);
int setRadius(double);
int getX();
int getY();
double getRadius();
double getArea();
void displayCircle();

};

“Source.cpp”
#include<iostream>
#include<math.h>
using namespace std;

int main()
{
circle u;
circle(12, 17, 10);
u.move(-5,-4);
u.setRadius(5);
u.getX();
u.getY();
u.getRadius();
u.getArea();
u.displayCircle();
return 0;
}

circle::circle(int a, int b, double c)


{
x = a;
y = b;
r = c;
int z = x * x + y * y;

r = sqrt(z);

cout << "radius " << r << " at a point x = " << x << " y = " << y << endl;

int area = 3.14 * r * r;


cout << "area : " << area <<endl;
}

void circle::move(int f, int v)


{
x = f;
y = v;
cout << "the coordinates are updated " << endl;

int circle::setRadius(double c)
{
r = c;
int z = x * x + y * y;

r = sqrt(z);
if (r > 0.0)
{
return r;
}

else
r = 10;
return r;
}

int circle::getX()
{

return x;
}
int circle::getY()
{
return y;
}

double circle::getRadius()
{
return r;
}

double circle::getArea()
{
return (3.14 * r * r);

void circle::displayCircle()
{
int a;
cout << "radius " << r << " at a point x = " << x << " y = " << y << endl;
a = (3.14 * r * r);
cout <<"area :" << a <<endl;
}

TESTING RESULTS:

You might also like