QUESTION: Use the code provided below to create a new C++ header file called Cir
ID: 3813064 • Letter: Q
Question
QUESTION:
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.
Explanation / Answer
#ifndef CIRCLE_H
#define CIRCLE_H
#include<iostream>
#include<string>
const float pi = 3.14;
using namespace std;
class Circle
{
private:
float radius;
public:
Circle(float rad = 5.0)
{
radius = rad;
}
float getradius()
{
return radius;
}
double getarea()
{
return pi * radius * radius;
}
};
int main()
{
Circle c1(2.4);
cout<<" Radius of Circle is: "<<c1.getradius();
cout<<" Area of Circle is: "<<c1.getarea();
Circle c2(5.6);
cout<<" Radius of Circle is: "<<c2.getradius();
cout<<" Area of Circle is: "<<c2.getarea();
Circle c3;
cout<<" Radius of Circle is: "<<c3.getradius();
cout<<" Area of Circle is: "<<c3.getarea();
return 0;
}
#endif