Question: 1 8 . 1 Fall 2 0 2 4 Circle Class with Overloads Although this class has been done, it would be good practice to

18.1 Fall 2024 Circle Class with Overloads
Although this class has been done, it would be good practice to redo it
The overloaded operators are the only member functions being added
Circle- color:String
- radius:double+Circle()
+Circle(newColor:String, newRadius:double)
+setColor(color:String):void
+setRadius(radius:double):void
+getColor():String
+getRadius():double
+getArea():double
+operator <(rhs: Circle):boolean
+operator ==(rhs: Circle):boolean
+friend operator <<(out: ostream&, circle: const Circle&):ostream&
+printCircleInfo():void
Create a class called Circle as describe below
Constructor with no arguments
Sets radius to 1 and color to black
Constructor with arguments
Sets the color and radius to the values passed in
Get functions (accessors) return the field that the get refers to
getArea uses PI in the Math class to compute the area and return it
Set methods (mutators) set the field to the new values passed in to it
printCircleInfo
prints the color and area in the following format
The red circle has area 78.54
overloaded operators compare the areas of the circle
overloaded << prints output
Circle Color: red Circle Radius: 8.50
Once you have tested the class, copy the main below. DO NOT CHANGE MAIN. If all of the methods in the class are correct, the main should give the correct answers. DO NOT CHANGE MAIN
Main
#include #include "Circle.h" using namespace std; Circle createCircle(); int main(){ Circle circle1("purple",5.2); Circle circle2; circle2= createCircle(); cout << endl; circle1.printCircleInfo(); circle2.printCircleInfo(); // Following statements use the operator overloads (< and ==)that should be // add to the Circle class cout << endl; if (circle1< circle2){ cout << "Circle1 has a smaller area than circle2"<< endl; } if (circle1== circle2){ cout << "Circle1 has the same area as circle2"<< endl; }// Following statements use the operator overloads (<<)that should be // add to the Circle class cout << "Circle1 Info" << endl; cout << circle1; cout << "Circle2 Info" << endl; cout << circle2; cout <<"Or you can print them both this way, too" << endl; cout << circle1<< circle2; return 0; }// Function: createCircle // Using the function call in main, write the function // Check output for what it looks like Circle createCircle(){ string color; double radius; cout << "Enter the color: "; cin >> color; cout << "Enter radius: "; cin >> radius; Circle circle(color, radius); return circle; }
Sample Output 1
Enter the color: red Enter radius: 7.32 The purple circle has an area of 84.95 The red circle has an area of 168.33 Circle1 has a smaller area than circle2 Circle1 Info Circle Color: purple Circle Radius: 5.20 Circle2 Info Circle Color: red Circle Radius: 7.32 Or you can print them both this way, too Circle Color: purple Circle Radius: 5.20 Circle Color: red Circle Radius: 7.32
Sample Output 2
Enter the color: yellow Enter radius: 5.2 The purple circle has an area of 84.95 The yellow circle has an area of 84.95 Circle1 has the same area as circle2 Circle1 Info Circle Color: purple Circle Radius: 5.20 Circle2 Info Circle Color: yellow Circle Radius: 5.20 Or you can print them both this way, too Circle Color: purple Circle Radius: 5.20 Circle Color: yellow Circle Radius: 5.20

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 Programming Questions!