bsc

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

pgrm_004.cpp (937B)


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