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 using namespace std;

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 = "<radius+Rec.radius; Circle s(r); return s; } ostream &operator<<(ostream &out, Circle aCircle) { out<<"This a circle "; out<<"The radius is "<

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 #include"Circle.h" using namespace std;

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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!