Define a class to represent circle. Data members should include radius, circumfe
ID: 3692617 • Letter: D
Question
Define a class to represent circle. Data members should include radius, circumference, area. Member functions should allow the following: A constructor to initialize its data members i.e radius A function to calculate area of the circle A function to calculate circumference of the circle In your program radius should have public access. The value for radius should be initialized externally through a constructor. Data members, Circumference and area Should have private access. Then create an object for class circle and implement the above function members.Explanation / Answer
#include <iostream>
#include <string>
using namespace std;
class Circle {
private:
double circumference;
double area;
public:
Circle(double r) {
radius = r;
}
double radius;
double calculateArea() {
return radius*radius*3.1416;
}
double calculateCircumference() {
return radius*3.1416;
}
};
int main() {
Circle c1(1.2);
cout << " Area=" << c1.calculateArea()
<< " circumference=" << c1.calculateCircumference() << endl;
}
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.