0% found this document useful (0 votes)
48 views3 pages

Laboratory 3 Solutions: To Write A Complete C++ Class To Represent A Circle in 2D Space

The document describes a C++ program that defines a Circle class with methods to initialize, move, set radius, get coordinates and radius, calculate area, and display circle details. The Circle class contains data members for x and y coordinates and radius. Methods are written to initialize, manipulate, and retrieve circle attribute values. The code is tested by creating circle objects and calling class methods.

Uploaded by

vigneshwar R
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
48 views3 pages

Laboratory 3 Solutions: To Write A Complete C++ Class To Represent A Circle in 2D Space

The document describes a C++ program that defines a Circle class with methods to initialize, move, set radius, get coordinates and radius, calculate area, and display circle details. The Circle class contains data members for x and y coordinates and radius. Methods are written to initialize, manipulate, and retrieve circle attribute values. The code is tested by creating circle objects and calling class methods.

Uploaded by

vigneshwar R
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 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