Need help with this program i have the classs header file just need the cpp file
ID: 3841689 • Letter: N
Question
Need help with this program i have the classs header file just need the cpp file for circle and what goes in the main file. This program is in c++
// Cirlce header file
#ifndef CIRCLE_H
#define CIRLCE_H
class Circle
{
public:
Circle();
Circle(double);
double getArea() const;
double getRadius() const;
void setRadius(double);
static int getNumberOfObjects();
private:
double radius;
static int numberOfObjects;
};
#endif
Explanation / Answer
Hi, Please find my implementation of all required function.
########### Circle.h #########
#ifndef CIRCLE_H
#define CIRCLE_H
class Circle
{
public:
Circle();
Circle(double);
double getArea() const;
double getRadius() const;
void setRadius(double);
static int getNumberOfObjects();
bool operator <(const Circle& other);
bool operator <=(const Circle& other);
bool operator ==(const Circle& other);
bool operator !=(const Circle& other);
bool operator >(const Circle& other);
bool operator >=(const Circle& other);
private:
double radius;
static int numberOfObjects;
};
#endif
########### Circle.cpp #########
#include "Circle.h"
Circle::Circle(){
radius = 0;
numberOfObjects++;
}
int Circle::numberOfObjects = 0;
Circle::Circle(double r){
radius = r;
numberOfObjects++;
}
double Circle::getArea() const{
return 3.14*radius*radius;
}
double Circle::getRadius() const{
return radius;
}
void Circle::setRadius(double r){
radius = r;
}
int Circle::getNumberOfObjects(){
return numberOfObjects;
}
// overloaded < operator
bool Circle::operator <(const Circle& other) {
if(radius < other.radius) {
return true;
}else
return false;
}
// overloaded <= operator
bool Circle::operator <=(const Circle& other) {
if(radius <= other.radius) {
return true;
}else
return false;
}
// overloaded == operator
bool Circle::operator ==(const Circle& other) {
if(radius == other.radius) {
return true;
}else
return false;
}
// overloaded != operator
bool Circle::operator !=(const Circle& other) {
if(radius != other.radius) {
return true;
}else
return false;
}
// overloaded > operator
bool Circle::operator >(const Circle& other) {
if(radius > other.radius) {
return true;
}else
return false;
}
// overloaded >= operator
bool Circle::operator >=(const Circle& other) {
if(radius >= other.radius) {
return true;
}else
return false;
}