Question
help fixing my code. I have provided the instructions below as well as my code. I can't seem to run my code so I would
help fixing my code. I have provided the instructions below as well as my code. I can't seem to run my code so I would appreciate it if you can run it and check if everything is fine or fix any errors. I would appreciate it if you include a picture of how the code output looks when its run successfully. PLEASE INCLUDE COMMENTS!! PLEASE ALSO THE Circle.h, Circle.cpp AND THE TEST PROGRAM!!!!
INSTRUCTIONS:
Implement (add) the relational operators (<, <=, ==, !=, >, >=) in the Circle class in Listing 10.9, provided below for your convenience, to order the Circle objects according to their radii.
#ifndef CIRCLE_H
#define CIRCLE_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
IMPORTANT:
Students regularly submit the Circle.h without implementing the relational operators. Which is basically the listing 10.10. Please understand, you should use listing 10.10, as the base and add the additional methods. The final submission includes the Circle.h, Circle.cpp, and the test program.
#include "Circle.h" int Circle::numberOfObjects = 0; // Construct a circle object Circle::Circle() { radius = 1; numberOfObjects++; } // Construct a circle object Circle::Circle(double newRadius) { radius = newRadius; numberOfObjects++; } // Return the area of this circle double Circle::getArea() const { return radius * radius * 3.14159; } // Return the radius of this circle double Circle::getRadius() const { return radius; } // Set a new radius void Circle::setRadius(double newRadius) { radius = (newRadius >= 0) ? newRadius : 0; } // Return the number of circle objects int Circle::getNumberOfObjects() { return numberOfObjects; }
MY CODE!!!!!
Circle.h
#ifndef CIRCLE_H
#define CIRCLE_H
class Circle
{
public:
Circle(); // Default constructor
Circle(double); // Overloaded constructor
double getArea() const; // Calculate and return the area of the circle
double getRadius() const; // Return the radius of the circle
void setRadius(double); // Set a new radius for the circle
static int getNumberOfObjects(); // Return the number of circle objects
// Relational operators to compare Circle objects based on their radii
bool operator<(const Circle& other) const;
bool operator<=(const Circle& other) const;
bool operator==(const Circle& other) const;
bool operator!=(const Circle& other) const;
bool operator>(const Circle& other) const;
bool operator>=(const Circle& other) const;
private:
double radius; // Radius of the circle
static int numberOfObjects; // Number of circle objects
};
#endif
Circle.cpp
#include "Circle.h"
int Circle::numberOfObjects = 0;
// ... (Previous code remains unchanged)
// Implement relational operators to compare Circle objects based on their radii
// Less than operator
bool Circle::operator<(const Circle& other) const
{
return radius < other.radius;
}
// Less than or equal to operator
bool Circle::operator<=(const Circle& other) const
{
return radius <= other.radius;
}
// Equal to operator
bool Circle::operator==(const Circle& other) const
{
return radius == other.radius;
}
// Not equal to operator
bool Circle::operator!=(const Circle& other) const
{
return radius != other.radius;
}
// Greater than operator
bool Circle::operator>(const Circle& other) const
{
return radius > other.radius;
}
// Greater than or equal to operator
bool Circle::operator>=(const Circle& other) const
{
return radius >= other.radius;
}
testprogram.cpp
#include
#include "Circle.h"
int main()
{
Circle circle1(5.0);
Circle circle2(3.5);
if (circle1 > circle2)
std::cout << "Circle 1 is larger than Circle 2 ";
else
std::cout << "Circle 1 is not larger than Circle 2 ";
return 0;
}
THIS IS THE ERROR I GET WHEN I RUN IT. IM NOT SURE IF ITS ON MY END SO I WOULD APPRECIATE IT IF YOU CAN TEST IT OUT AND SEE HOW IT LOOKS ON YOUR OWN END. IF ITS FINE THEN LET ME KNOW AND SEE HOW THE OUTPUT LOOKS. IF NOT PLEASE FIX ANY ERRORS AND SHOW ME HOW ITS SUPPOSE TO LOOK LIKE. THANK YOU SO MUCH!!!
Undefined symbols for architecture arm64: "Circle::Circle(double)", referenced from: _main in TestProgram-efaa64.o "Circle::operator>(Circle const&) const", referenced from: _main in Test Program-efaa64.o ld: symbol(s) not found for architecture arm64 clang: error: linker command failed with exit code 1 (use -v to see invocation)
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