Lesson 13A 2Q Lab 13.2 circles as a class Retrieve program circles.cpp from the
ID: 3778877 • Letter: L
Question
Lesson 13A 2Q Lab 13.2 circles as a class Retrieve program circles.cpp from the Lab 13 folder. The code is as follows: Sinclude kiostream» using namespace std This program declares a class for a circle that will have member functions that set the center, find the area, find the circumference and display these attributes. input data, but The program as written does not allow the user to rather has the radii and center coordinates of the circles a function. in the program) initialized at definition or set by //class declaration section (header file) class circles etcenter (int x, int y) void s double findArea double findcircumference0 u center of the circle. void print circlestats This outputs the radius and Constructor Circles (float r) Default constructor circles private radius; float int center int center ya const double PI 3.14; //client section int main() Circles sphere (B) sphere set Center (9,10) i sphere printcirclestats cout "The area of the circle is sphere.findArea endli cout "The circumference of the circle is sphere find circumference endli return 0; continuesExplanation / Answer
Here is the code after filling the undefined methods:
#include <iostream>
using namespace std;
class Circles
{
public:
void setCenter(int x, int y);
double findArea();
double findCircumference();
void printCircleStats();
Circles (float r);
Circles();
private:
float radius;
int center_x;
int center_y;
};
const double PI = 3.14;
int main()
{
Circles sphere(8);
sphere.setCenter(9, 10);
sphere.printCircleStats();
cout<<"The are of the circle is "<<sphere.findArea()<<endl;
cout<<"The circumference of the circle is "
<<sphere.findCircumference()<<endl;
return 0;
}
Circles::Circles()
{
radius = 1;
}
Circles::Circles(float r)
{
radius = r;
}
double Circles::findArea()
{
return PI * radius * radius;
}
double Circles::findCircumference()
{
return 2 * PI * radius;
}
void Circles::printCircleStats()
{
cout<<"The radius of the circle is "<<radius<<endl;
cout<<"The center of the circle is ("<<center_x
<<", "<<center_y<<")"<<endl;
}
void Circles::setCenter(int x, int y)
{
center_x = x;
center_y = y;
}
Here is the modified version for you Exercise 1:
#include <iostream>
using namespace std;
class Circles
{
public:
//void setCenter(int x, int y);
double findArea();
double findCircumference();
void printCircleStats();
Circles (float r, int x, int y);
Circles();
private:
float radius;
int center_x;
int center_y;
};
const double PI = 3.14;
int main()
{
Circles sphere(8, 9, 10);
//sphere.setCenter(9, 10);
sphere.printCircleStats();
cout<<"The are of the circle is "<<sphere.findArea()<<endl;
cout<<"The circumference of the circle is "
<<sphere.findCircumference()<<endl;
return 0;
}
Circles::Circles()
{
radius = 1;
center_x = center_y = 0;
}
Circles::Circles(float r, int x, int y)
{
radius = r;
center_x = x;
center_y = y;
}
double Circles::findArea()
{
return PI * radius * radius;
}
double Circles::findCircumference()
{
return 2 * PI * radius;
}
void Circles::printCircleStats()
{
cout<<"The radius of the circle is "<<radius<<endl;
cout<<"The center of the circle is ("<<center_x
<<", "<<center_y<<")"<<endl;
}
/*void Circles::setCenter(int x, int y)
{
center_x = x;
center_y = y;
}*/
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.