bsc

Comprehensive codebase and cou...
Log | Files | Refs | Activity | README | LICENSE

root / semester_2 / eduincs / pgrm_004.cpp

pgrm_004.cpp (801B)


      1 /* Write a program to calculate area and circumference of a circle. */
      2 
      3 #include<iostream>
      4 #include<cmath>
      5 using namespace std;
      6 
      7 class circle {
      8     private: 
      9         double r, radius;
     10 
     11     public: 
     12         circle(double r) {
     13             setRadius(r);
     14         }
     15         ~circle() {};
     16 
     17         void setRadius(double r) {
     18             if(r >= 0) radius = r;
     19             else radius = 0;
     20         }
     21 
     22         double getRadius() {
     23             return radius;
     24         }
     25 
     26         double area() {
     27             return M_PI * radius * radius;
     28         }
     29 
     30         double cir() {
     31             return 2 * M_PI * radius;
     32         }
     33 };
     34 
     35 int main() {
     36     circle c(5);
     37     cout << "Radius: " << c.getRadius() << endl;
     38     cout << "Area: " << c.area() << endl;
     39     cout << "Circumference: " << c.cir() << endl;
     40     return 0;
     41 }
© notamitgamer • Site Built: 2026-09-05 01:53:16 UTC • git-mirror commit: c170d72 [view raw info]
Originally created with stagit • modified by notamitgamer
Forked from github.com/notamitgamer/git-mirror