Skip to main content

Posts

Showing posts from 2023

C++ program to define a class circle to represent circles. Add a data member radius to store the radius of a circle. Write member functions area() and perimeter() to compute the area and perimeter of a circle.

  C++ program to define a class circle to represent circles. Add a data member radius to store the radius of a   circle. Write member functions area() and perimeter() to compute the area and perimeter of a circle.     To define a Circle class in C++, we start by declaring the class with the class keyword, followed by the name of the class. In this case, we'll call it Circle . We'll then define a private data member to store the radius of the circle. Here's the code to do that:    class Circle {      private:      double radius;    };          Next, we need to define public member functions that can set and get the value of the radius, as well as calculate the area and perimeter of the circle. Here's the full code for the Circle class: class Circle { private: double radius; public: void setRadius(double r) { radius = r; } double getRadius() { return radius; } double area() { return 3.14159 * r