In: Computer Science
Here is the completed code for this problem. Comments are included, go through it, learn how things work and let me know if you have any doubts or if you need anything to change. If you are satisfied with the solution, please rate the answer. Thanks
//completed program
#include<iostream>
using namespace std;
//Circle class
class Circle
{
private:
double radius;
public:
void setRadius(double);
double getRadius() const;
double getArea() const;
double getPerimeter() const;
};
//implementation of all methods in Circle class
void Circle::setRadius(double rad){
//setting radius to rad
radius=rad;
}
double Circle::getRadius() const{
//returns the radius
return radius;
}
double Circle::getArea() const{
//area=PI*r*r
double area=3.14*radius*radius;
return area;
}
double Circle::getPerimeter() const{
//perimeter=2*PI*r
double peri=2*3.14*radius;
return peri;
}
int main(){
//creating two Circle objects
Circle pizza1;
Circle pizza2;
//setting different radii to each circle
pizza1.setRadius(50);
pizza2.setRadius(20);
//displaying area of pizza1, pizza2 and pizza 1 & 2 combined
cout<<"Area of Pizza 1: "<<pizza1.getArea()<<endl;
cout<<"Area of Pizza 2: "<<pizza2.getArea()<<endl;
cout<<"Area of Pizza 1 and 2 combined: "<<(pizza1.getArea()+pizza2.getArea())<<endl;
return 0;
}
/*OUTPUT*/
Area of Pizza 1: 7850
Area of Pizza 2: 1256
Area of Pizza 1 and 2 combined: 9106