Question
Using this circle class: // Circle.h #pragma once #include #include #ifndef CIRCLE_H #define CIRCLE_H using namespace std; const double PI = 3.1416; class circleType {
Using this circle class:
// Circle.h
#pragma once
#include
#include
#ifndef CIRCLE_H
#define CIRCLE_H
using namespace std;
const double PI = 3.1416;
class circleType
{
public:
void print();
// output radius, circumference, and area of the circle
void setRadius(double r);
// Function to set Radius
// Postcondition: if (r >= 0) radius = r;
// Otherwise radius = 0
double getRadius();
// Function to return the radius
// Postcondition: The value of the radius is returned
double area();
// Function to return the area of the circle
// Postcondition: area is calculated and returned
double circumference();
// Function to return the circumference of a circle
// Postcondition: Circumference is calculated and returned
circleType(double r = 0);
// Constructor with a default parameter
// Radius is set according to the parameter
// Default value of the radius is 0.0;
// Postcondition: radius = r;
private:
double radius;
};
#endif
// Circle.cpp
#include "Circle.h"
#include
using namespace std;
void circleType::print()
{
cout << "Radius = " << radius
<< ", area = " << area()
<< "circumference = " << circumference();
}
void circleType::setRadius(double r)
{
if (r >= 0)
radius = r;
else
radius = 0;
}
double circleType::getRadius()
{
return radius;
}
double circleType::area()
{
return PI * radius * radius;
}
double circleType::circumference()
{
return 2 * PI * radius;
}
circleType::circleType(double r)
{
setRadius(r);
}
Use the class to perform the following:
a)
Overload the pre and post increment operator (++) to increment the radius of
the circleType object. Note that after incrementing the radius, it must be
positive.
b)
Overload the pre and post decrement operator (--) to decrement the radius of
the circleType object. Note that after decrementing the radius, it must be
positive.
c)
Overload the binary operator to subtract radius of one circleType object
from corresponding radius of another circleType object. If the resulting
value is negative, display message that operation cant be performed.
d)
Overload == and != to compare two circleType objects. You only need to
compare the radius.
e)
Also overload > , < , >= and <=
Lastly, write test program to test the work shown above.
Edit: overloaded operator functions should be member functions
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started