Point.h
#ifndef POINT_H
#define POINT_H
#include<math.h>
class Point
{
public:
// Add getter methods of data members
// to access them in other class
Point();
Point(double, double);
void set_x(double);
void set_y(double);
double get_x() const;
double get_y() const;
double Distance(Point);
private:
double x;
double y;
};
#endif // POINT_H
Point.cpp
#include "Point.h"
// Default constructor
Point::Point(){
x = 0;
y = 0;
}
// Constructor to set x,y
Point::Point(double x, double y):x(x),y(y){}
// Setter and getter methods for data members
void Point::set_x(double x){
this->x = x;
}
void Point::set_y(double y){
this->y = y;
}
double Point::get_x() const{
return x;
}
double Point::get_y() const{
return y;
}
// Calculate distance and return
double Point::Distance(Point p){
double distance = sqrt(pow(x-p.get_x(),2) +
pow(y-p.get_y(),2));
return distance;
}
Circle.h
#ifndef CIRCLE_H
#define CIRCLE_H
#include<Point.h>
class Circle
{
public:
Circle();
Circle(double radius);
Circle(double radius, double x, double y);
void setRadius(double);
double getRadius() const;
void SetCenter(Point);
Point GetCenter() const;
double getArea() const;
double getDiameter() const;
double getCircumference() const;
bool sameArea(Circle);
private:
double radius;
Point center;
};
#endif // CIRCLE_H
Circle.cpp
#include "Circle.h"
// Default constructor
Circle::Circle():center(0,0){
radius =0 ;
}
// Constructor to set radius
Circle::Circle(double radius):radius(radius){}
// Constructor to set radius and center
Circle::Circle(double radius, double x, double y):radius(radius),
center(x,y){}
// setter and getter methods for data members
void Circle::setRadius(double radius){
this->radius = radius;
}
double Circle::getRadius() const{
return radius;
}
void Circle::SetCenter(Point p){
center = p;
}
Point Circle::GetCenter() const{
return center;
}
// Calculate area and return
double Circle::getArea() const{
return 3.14*radius*radius;
}
// Calculate diameter and return
double Circle::getDiameter() const{
return 2*radius;
}
// Calculate Circumference and return
double Circle::getCircumference() const{
return 2*3.14*radius;
}
// If area is same, return true else false
bool Circle::sameArea(Circle c){
if (getArea()==c.getArea()){
return true;
}else{
return false;
}
}
main.cpp
#include <iostream>
#include<Point.h>
#include<Circle.h>
using namespace std;
int main ()
{
Circle c1(1,1,1);
Circle c2;
c2.setRadius(2);
c2.SetCenter(Point(4,4.5));
cout<<"Circle 1"<<endl;
cout<<"Radius: "<<c1.getRadius()<<endl;
cout<<"Center: "<<c1.GetCenter().get_x()<<",
"<<c1.GetCenter().get_y()<<endl;
cout<<"Area: "<<c1.getArea()<<endl;
cout<<"Perimeter:
"<<c1.getCircumference()<<endl;
cout<<"\nCircle 2"<<endl;
cout<<"Radius: "<<c2.getRadius()<<endl;
cout<<"Center: "<<c2.GetCenter().get_x()<<",
"<<c2.GetCenter().get_y()<<endl;
cout<<"Area: "<<c2.getArea()<<endl;
cout<<"Perimeter:
"<<c2.getCircumference()<<endl;
Circle c3;
Circle c4(6, 6,7);
cout<<"\nCircle 3"<<endl;
cout<<"Area: "<<c3.getArea()<<endl;
cout<<"Perimeter:
"<<c3.getCircumference()<<endl;
cout<<"\nCircle 4"<<endl;
cout<<"Area: "<<c4.getArea()<<endl;
cout<<"Perimeter:
"<<c4.getCircumference()<<endl;
if(c3.sameArea(c4)){
cout<<"\nCircle c3 and c4 have same area"<<endl;
}else{
cout<<"\nCircle c3 and c4 does not have same
area"<<endl;
}
c3.setRadius(6);
c3.SetCenter(Point(6,7));
cout<<"\nCircle 3"<<endl;
cout<<"Radius: "<<c3.getRadius()<<endl;
cout<<"Center: "<<c3.GetCenter().get_x()<<",
"<<c3.GetCenter().get_y()<<endl;
cout<<"Area: "<<c3.getArea()<<endl;
cout<<"Perimeter:
"<<c3.getCircumference()<<endl;
cout<<"\nCircle 4"<<endl;
cout<<"Radius: "<<c4.getRadius()<<endl;
cout<<"Center: "<<c4.GetCenter().get_x()<<",
"<<c4.GetCenter().get_y()<<endl;
cout<<"Area: "<<c4.getArea()<<endl;
cout<<"Perimeter:
"<<c4.getCircumference()<<endl;
if(c3.sameArea(c4)){
cout<<"\nCircle c3 and c4 have same area"<<endl;
}else{
cout<<"\nCircle c3 and c4 does not have same
area"<<endl;
}
double distance = c3.GetCenter().Distance(c4.GetCenter());
cout<<"\nDistance between Circle 3 and Circle 4 center is
"<<distance<<endl;
return 0;
}
OUTPUT
Note: Could you plz go through this code and let me
know if u need any changes in this.Thank You
_________________
// Point.h
#ifndef POINT_H
#define POINT_H
#include<string>
#include<cmath>
using namespace std;
class Point
{
public:
Point();
Point(double ,double);
~Point();
double get_X();
double get_Y();
void set_X(double);
void set_Y(double);
double Distance(Point p);
private:
// Declaring variables
double x;
double y;
};
#endif
_____________________
// Point.cpp
#include <iostream>
#include <cmath>
using namespace std;
#include "point.h"
Point::Point()
{
this->x=0.0;
this->y=0.0;
}
Point::Point(double x,double y)
{
this->x=x;
this->y=y;
}
Point::~Point()
{
}
double Point::get_X()
{
return x;
}
double Point::get_Y()
{
return y;
}
void Point::set_X(double x)
{
this->x=x;
}
void Point::set_Y(double y)
{
this->y=y;
}
double Point::Distance(Point p)
{
return sqrt(pow((p.x - x), 2) + pow((p.y - y), 2));
}
____________________
// Circle.h
#ifndef CIRCLE_H
#define CIRCLE_H
#include "point.h"
class Circle:public Point
{
public:
double getRadius();
void setCenter(Point);
void setRadius(double);
double getArea();
double getDiameter();
double getCircumference();
bool sameArea(Circle c);
Circle(double x,double y, double r );
Circle();
~Circle();
Point getCenter();
protected:
double radius;
Point center;
};
#endif
_________________________
// Circle.cpp
#include <iostream>
using namespace std;
#include "circle.h"
#include "point.h"
double Circle::getRadius()
{
return radius;
}
void Circle::setCenter(Point p)
{
center.set_X(p.get_X());
center.set_Y(p.get_Y());
}
void Circle::setRadius(double r)
{
radius=r;
}
double Circle::getDiameter()
{
return 2*radius;
}
double Circle::getCircumference()
{
return 2*3.14159;
}
bool Circle::sameArea(Circle c)
{
if(getArea()==c.getArea())
return true;
else
return false;
}
double Circle::getArea()
{
return 3.14159*radius*radius;
}
Circle::Circle(double x,double y, double r )
{
center.set_X(x);
center.set_Y(y);
radius=r;
}
Circle::Circle()
{
center.set_X(0.0);
center.set_Y(0.0);
radius=1.0;
}
Circle::~Circle()
{
}
Point Circle::getCenter()
{
return center;
}
____________________
// main.cpp
#include <iostream>
using namespace std;
#include "circle.h"
int main()
{
Circle c1,c2;
c1.setRadius(1.0);
c1.set_X(1.0);
c1.set_Y(1.0);
cout<<"Area of
Circle#1:"<<c1.getArea()<<endl;
cout<<"Perimeter of
Circle#1:"<<c1.getCircumference()<<endl;
c2.setRadius(2.0);
c2.set_X(4.0);
c2.set_Y(4.5);
cout<<"Area of
Circle#2:"<<c2.getArea()<<endl;
cout<<"Perimeter of
Circle#2:"<<c2.getCircumference()<<endl;
Circle c3,c4;
c4.setRadius(6.0);
c4.set_X(6.0);
c4.set_Y(7.0);
cout<<"Area of
Circle#3:"<<c3.getArea()<<endl;
cout<<"Perimeter of
Circle#3:"<<c4.getCircumference()<<endl;
cout<<"Area of
Circle#4:"<<c4.getArea()<<endl;
cout<<"Perimeter of
Circle#4:"<<c4.getCircumference()<<endl;
bool b=c3.sameArea(c4);
if(b)
{
cout<<"Circle#3 and Circle#4 have the same
area"<<endl;
}
else
{
cout<<"Circle#3 and Circle#4 not have the same
area"<<endl;
}
c3.setRadius(6.0);
c3.set_X(6.0);
c3.set_Y(7.0);
cout<<"Area of
Circle#3:"<<c3.getArea()<<endl;
cout<<"Perimeter of
Circle#3:"<<c4.getCircumference()<<endl;
cout<<"Area of
Circle#4:"<<c4.getArea()<<endl;
cout<<"Perimeter of
Circle#4:"<<c4.getCircumference()<<endl;
b=c3.sameArea(c4);
if(b)
{
cout<<"Circle#3 and Circle#4 have the same
area"<<endl;
}
else
{
cout<<"Circle#3 and Circle#4 not have the same
area"<<endl;
}
Point p3=c3.getCenter();
Point p4=c4.getCenter();
double distance=p3.Distance(p4);
cout<<"The Distance between Circle#3 center and Cirle#4
center is :"<<distance<<endl;
return 0;
}
___________________________
Output:
_______________Could you plz rate me well.Thank
You
U8ing separate files, write th definition for a clas called Poit and a class called Cirele...
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)...
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....
Pure Abstract Base Class Project. Define a class called BasicShape which will be a pure abstract class. The class will have one protected data member that will be a double called area. It will provide a function called getArea which should return the value of the data member area. It will also provide a function called calcArea which must be a pure virtual function. Define a class called Circle. It should be a derived class of the BasicShape class. This...
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()...
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....
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. ...
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...
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...
java language Problem 3: Shape (10 points) (Software Design) Create an abstract class that represents a Shape and contains abstract method: area and perimeter. Create concrete classes: Circle, Rectangle, Triangle which extend the Shape class and implements the abstract methods. A circle has a radius, a rectangle has width and height, and a triangle has three sides. Software Architecture: The Shape class is the abstract super class and must be instantiated by one of its concrete subclasses: Circle, Rectangle, or...
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...