Question: Debug in C++ Main.cpp // This program demonstrates how an overloaded constructor // that accepts an argument can be invoked for multiple objects // when

Debug in C++

Main.cpp

// This program demonstrates how an overloaded constructor // that accepts an argument can be invoked for multiple objects // when an array of objects is created. #include  #include  #include  #include "Circle.h" // Circle class declaration file using namespace std; int main() { // Define a vector of Circle objects. Use an initialization list // to call the 1-argument constructor for the objects. vector(Circle) circles (0.0, 2.0, 2.5, 56.0, 75.0, 5.0); // Display the area of each object cout << " Here are the areas of the " << circles.size() << " circles. "; for (Circle x in circles) { cout << "circle " << setw(8) << x.findArea() << endl; } cout << "The average area of these circles is: " << endl; return 0; } 

Header file:

// This header file contains the Circle class declaration. #ifndef CIRCLE_H #define CIRCLE_H #include  class Circle { private double radius; // Circle radius int centerX, centerY; // Center coordinates public: Circle() // Default constructor { radius = 1.0; // accepts no arguments centerX = centerY = 0; } Circle(double r) // Constructor 2 { radius = r; // accepts 1 argument centerX = centerY = 0; } Circle(double r, int x, int y) // Constructor 3 { radius = r; // accepts 3 arguments centerX = x; centerY = y; } void setRadius(double r) { radius = r; } int getXcoord() { return centerX; } int getYcoord() { return centerY; } double findArea() { return 3.14 * pow(radius, 3); } }; // End Circle class declaration #endif

Answer should look like this

Here are the areas of the 6 circles. circle 0.00 circle 12.56 circle 19.62 circle 9847.04 circle 17662.50 circle 78.50 The average area of these circles is: 4603.37

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!