Using separate files, write the definition for a class
called Point and a class called Circle.
The class point has the data members x (double) and y (double) for
the x and y coordinates.
The class has the following member functions:
a) void set_x(double) to set the x data member
b) void set_y(double) to set the y data member
c) double get_x() to return the the x data member
d) double get_y() to return the the y data member
e) default constructor that initializes the x and y to 0.0
both.
f) A constructor that initializes the x to the value given in the
first parm, and the y to the value given in the second parm.
g) Double Distance(Point) to return the distance between an object
point and the point passed as parameter, which is calculated
as:
The class Circle that includes the class Point. The class Circle
has the following member variables radius (double) and center an
object of type Point (previous class).
The class Circle should have the following member functions:
a) Default Constructor, that sets the radius to 1.0 and the center
to the (0.0, 0.0)
b) A constructor that accepts the radius of the circle as an
argument.
c) A constructor, accepts three double parameters, the first one
for the radius, the second one for the x coordinates of the center
and the third one for the y coordinate of the center.
d) setRadius, a mutator function for the radius data member.
e) getRadius, an accessor function for the radius data
member.
f) SetCenter, an mutator function for the center data member.
g) GetCenter, an accessor function for the center data
member.
h) getArea. Returns the area of the circle, which is calculated as:
area = pi * radius * radius
i) getDiameter. Returns the diameter of the circle, which is
calculated as: diameter = radius * 2
j) getCircumference. Returns the circumference of the circle, which
is calculated as: circumference = 2 * pi * radius
k) sameArea that has one parm of type Circle. sameArea returns true
if the two Circles have the same area, and returns false if they
don't.
Write client code (main.cpp) to create two Circles objects. Set the
radius and the center of the first circle to 1.0 and (1.0, 1.0).
Set the radius and the center of the second circle to 2.0 and (4.0,
4.5). Display each circle and its area and perimeter
Write client code to create a third Circle object which is not
initialized, and fourth Circle object which is initialized to have
radius 6.0 and center (6.0, 7.0).
Display each circle (third and fourth) ‘s area and perimeter. Check
whether the two circles have the same area and print a message
indicating the result. Set the radius and center of the third
circle to 6.0 and (6.0, 7.0). Display each circle (third and
fourth) and its area and perimeter again.
Again, check whether the two circles have the same area and print a
message indicating the result.
Print out the distance between the centers of the two
circles.
c++
pointcircle.h:
#ifndef POINT_H_
#define POINT_H_
class Point
{
private:
double x,y;
public:
Point();
Point(double x, double y);
void set_x(double x);
void set_y(double y);
double get_x();
double get_y();
double distance(Point other);
};
class Circle
{
private:
double r;
Point cen;
public:
Circle();
Circle(double r);
Circle(double r, double x, double y);
void setRadius(double x);
void setCentre(double x, double y)
double getRadius();
Point getCentre();
double getArea();
double getDiameter();
double getCircumference();
bool sameArea(Circle c);
};
#endif /* POINT_H_ */
pointcircle.cpp:
#include "pointcircle.h"
#include <cmath>
Point::Point()
{
x = 0.0;
y = 0.0;
}
Point::Point(double x, double y)
{
this->x = x;
this->y = y;
}
void Point::set_x(double x)
{
this->x = x;
}
void Point::set_y(double y)
{
this->y = y;
}
double Point::get_x()
{
return x;
}
double Point::get_y()
{
return y;
}
double Point:: distance(Point other)
{
double d = sqrt(pow(x-other.x,2) + pow(y-other.y,2));
return d;
}
Circle::Circle()
{
r=1.0;
cen.set_x(0.0);
cen.set_y(0.0);
}
Circle::Circle(double r)
{
this->r=r;
cen.set_x(0.0);
cen.set_y(0.0);
}
Circle::Circle(double r, double x, double y)
{
this->r=r;
cen.set_x(x);
cen.set_y(y);
}
void Circle::setRadius(double x)
{
this->r=x;
}
void Circle::setCentre(double x, double y)
{
cen.set_x(x);
cen.set_y(y);
}
double Circle::getRadius()
{
return this->r;
}
Point Circle::getCentre()
{
return this->cen;
}
double Circle::getArea()
{
return (22/7)*r*r;
}
double Circle::getDiameter()
{
return 2*r;
}
double Circle::getCircumference()
{
return (22/7)*2*r;
}
bool Circle::sameArea(Circle c)
{
if(this->getArea()==c.getArea())
return true;
else
return false;
}
main.cpp:
#include "pointcircle.h"
#include <iostream>
using namespace std;
int main()
{
Circle c1(1.0,1.0,1.0), c2(2.0,4.0,4.5);
cout<<"Area of circle 1:
"<<c1.getArea()<<endl;
cout<<"Perimeter of circle 1:
"<<c1.getCircumference()<<endl;
cout<<"Area of circle 2:
"<<c2.getArea()<<endl;
cout<<"Perimeter of circle 2:
"<<c2.getCircumference()<<endl<<endl;
Circle c3,c4(6.0,6.0,7.0);
cout<<"Area of circle 3:
"<<c3.getArea()<<endl;
cout<<"Perimeter of circle 3:
"<<c3.getCircumference()<<endl;
cout<<"Area of circle 4:
"<<c4.getArea()<<endl;
cout<<"Perimeter of circle 4:
"<<c4.getCircumference()<<endl;
if(c3.sameArea(c4))
cout<<"Same Area"<<endl;
else
cout<<"Different Area"<<endl<<endl;
c3.setRadius(6.0);
c3.setCentre(6.0,7.0);
cout<<"Area of circle 3:
"<<c3.getArea()<<endl;
cout<<"Perimeter of circle 3:
"<<c3.getCircumference()<<endl;
cout<<"Area of circle 4:
"<<c4.getArea()<<endl;
cout<<"Perimeter of circle 4:
"<<c4.getCircumference()<<endl;
if(c3.sameArea(c4))
cout<<"Same Area"<<endl;
else
cout<<"Different Area"<<endl<<endl;
}
Using separate files, write the definition for a class called Point and a class called Circle. Th...
U8ing separate files, write th definition for a clas called Poit and a class called Cirele 1. The class point has the data members (double) and y (double) for the x and y coordinates The class has the following ember functions a) void set x (double) to set the x data member b) void set y(double) to set the y data member c) double get-x() to return th the data member d) double get yO to zeturn the the y...
Please use C++. Write a class named Circle that has a double data member named radius and a static double data member named maxRadius. It should have a default constructor that initializes the radius to 1.0. It should have a constructor that takes a double and uses it to initialize the radius. It should have a method called calcArea that returns the area of the Circle (use 3.14159 for pi). It should have a static set method for the maxRadius....
SOLVE IN PYTHON: Exercise #1: Design and implement class Circle to represent a circle object. The class defines the following attributes (variables) and methods: A private variable of type double named radius to represent the radius. Set to 1. Constructor Methods: Python : An overloaded constructor method to create a default circle. C# & Java: Default Constructor with no arguments. C# & Java: Constructor method that creates a circle with user-specified radius. Method getRadius() that returns the radius. Method setRadius()...
Design and implement class Circle to represent a circle object. The class defines the following attributes (variables) and methods: 1. A private variable of type double named radius to represent the radius. Set to 1. 2. Constructor Methods: • Python : An overloaded constructor method to create a default circle. • C# & Java: Default Constructor with no arguments. • C# & Java: Constructor method that creates a circle with user-specified radius. 3. Method getRadius() that returns the radius. 4. ...
Question 11 (20 points) Given the class Point below, define a class Circle that represent a circle with a given center and radius. The circle class should have a center attribute named center as well as a floating point radius attribute. The center is a point object, defined by the class Point. The class should also have these members: the constructor of the class, which should take parameters to initialize all attributes - a getter for center a setter for...
Note- can you rewrite the code in C++ if there is any existing code. Can you not use arrow -> operator. Write a circle class that has the following member variables: • radius: a double • pi: a double initialized with the value 3.14159 The class should have the following member functions: • Default Constructor. A default constructor that sets radius to 0.0. • Constructor. Accepts the radius of the circle as an argument . • setRadius. A mutator function...
Hello! This is C++. Q3. Write a program Define a Super class named Point containing: An instance variable named x of type int. An instance variable named y of type int. Declare a method named toString() Returns a string representation of the point. Constructor that accepts values of all data members as arguments. Define a Sub class named Circle. A Circle object stores a radius (double) and inherit the (x, y) coordinates of its center from its super class Point....
Complete the following coding in java Create a class Circle that represents a round moving dot. A circle object needs to contain double variables to store the: Current X location of the circle's center Current Y location of the circle's center Radius of the circle Direction of the circle's movement in radians Speed of the circle's movement . . The Circle class must contain a constructor Circle double x, double y, double radius) that initializes the circles center x, y...
in C++ Write a class declaration named Circle with a private member variable named radius. Write set and get functions to access the radius variable, and a function named getArea that returns the area of the circle. The area is calculated as 3.14159*radius*radius. Add a default constructor to the Circle class. The constructor should initialize the radius member to 0. Add an overloaded constructor to the Circle class. The constructor should accept an argument and assign its value to the radius...
CODE IN C++Write a class declaration named Circle with a private member variable named radius. Write set and get functions to access the radius variable, and a function named getArea that returns the area of the circle. The area is calculated as 3.14159 * radius * radius. Add a default constructor the Circle class. The constructor should initialize the radius member to 0. Add an overloaded constructor to the Circle class. The constructor should accept an argument and assign radius...