(C++): Use the code provided below to create a new C++ header file called Circle
ID: 3814722 • Letter: #
Question
(C++): Use the code provided below to create a new C++ header file called Circle.h. #ifndef CIRCLE_H #define CIRCLE_H #include > using namespace std; class Circle { friend bool operator == (Circle C1, Circle C2); //return true if area of C1 equals area of C2, otherwise it returns false friend bool inside(Circle C1, Circle C2); // return true if C1 is inside C2, otherwise it returns false public: Circle (); Circle (float R, int X, int Y); Circle& operator = (Circle C); // assign the C (Circle Object) to the object members void WriteArea () const; private: float radius; int x, y; }; #endif Create a new C++ implementation file called Circle.cpp. This file should contain the implementations of the functions in the Circle class. Also, create an application program to test your Circle class.Please show output.
Explanation / Answer
//============ Circle.h ========================
#include <iostream>
using namespace std;
class Circle {
friend bool operator==(Circle &C1, Circle &C2); //return true if area of C1 equals area of C2, otherwise it returns false
friend bool inside(Circle &C1, Circle &C2); // return true if C1 is inside C2, otherwise it returns false
public: Circle ();
Circle (float R, int X, int Y);
Circle& operator = (Circle &C); // assign the C (Circle Object) to the object members
void WriteArea () const;
private: float radius;
int x, y;
};
//=============== Circle.cpp ==========================
#include <iostream>
#include <cmath>
#include "Circle.h"
using namespace std;
bool operator==(Circle &C1, Circle &C2){
if(C1.x==C2.x && C1.y==C2.y && C1.radius==C2.radius)
return true;
return false;
}
bool inside(Circle &C1, Circle &C2){
float d = sqrt(( C1.x - C2.x )*(C1.x-C2.x) + (C1.y-C2.y)*(C1.y-C2.y));
if((d <= (float)abs(C1.radius - C2.radius)))
return true;
return false;
}
Circle::Circle(){
x =0;
y =0;
radius =0;
}
Circle::Circle(float R, int X, int Y){
x =X;
y =Y;
radius =R;
}
Circle& Circle::operator=(Circle &C){
x= C.x;
y= C.y;
radius = C.radius;
return *this;
}
void Circle::WriteArea () const{
cout << "Area : "<<(22/7)*radius*radius<< ""<<endl;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.