Question
C++ Class and Operator Overloading part 1 The source file contains a C++ program that declares and initializes an array of Circles. The program is
C++ Class and Operator Overloading
part 1
The source file contains a C++ program that declares and initializes an array of Circles. The program is using a for loop statement to find the largest circle in the array and display it on the output screen. However, the program is currently not working. The problem is the program uses logical operator ' > ' for comparison of circles and it is not working unless we overload such operator for the class Circle. Please fix the problem and make the program in the source file working correctly.
//Header File of class Circle
#ifndef _Circle #define _Circle #include
class Circle { private: double radius; public: Circle(); Circle(double r); void setRadius(double r); double getRadius(); double area(); void display(); Circle operator+(const Circle &Rec) const; }; Circle::Circle() { radius=1; } Circle::Circle(double r) { radius=r; } //Definition of Methods: void Circle::setRadius(double r) { radius = r; } double Circle::getRadius() { return radius; } double Circle::area() { return 3.1415926*radius*radius; } void Circle::display() { cout<<"This a circle "; cout<<"Radius = "< part2 In the source file, declare another array of circles with 6 elements. Using a looping statement to put the circles in the array a into the newly declared array by following rules: 1. The first circle in the array a goes to the first element of the new array. 2. If a circle in array a is greater than all the circles in the new array, then put this circle after the last circle in the new array, otherwise, insert this circle right in front of the first circle in the new array that is greater than or equal to this circle. // source file #include int main() { Circle a[6]={Circle(5),Circle(7),Circle(2),Circle(3),Circle(11),Circle(6)}; Circle t; t=a[0]; for(int i=0;i<6;i++){ if(a[i]>t) t=a[i]; } cout<<"The largest circle is "< Please upload the header file for Part I and upload source file for part II
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