munther_abdellatif

class exc

Jul 11th, 2021 (edited)
241
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2. #define pi 22/7
  3. using namespace std;
  4. class circle {
  5.     float diameter;
  6. public :
  7.     // constractor
  8.     circle (float d) {
  9.         diameter = d;
  10.     }
  11.     // class function
  12.     void PrintInfo (){
  13.         float ci = 2 * pi * diameter;
  14.         float area = pi * diameter * diameter;
  15.         cout << " circle diameter is : " << diameter <<" cm" << endl;
  16.         cout << " circumference of a circle is :" << ci <<" cm" << endl;
  17.         cout << " circle surface area is : " << area << " cm2" << endl;
  18.     }
  19.     // setter
  20.     void setDiameter(float d) {
  21.         diameter = d;
  22.     }
  23.     // getter
  24.     float getDiameter() {
  25.         return diameter;
  26.     }
  27.     float getCircumference() {
  28.         return 2 * pi * diameter;
  29.     }
  30.     float getarea() {
  31.         return pi * diameter * diameter;
  32.     }
  33. };
  34.  
  35. int main() {
  36.     circle myCircle(14);
  37.     myCircle.PrintInfo();
  38.     cout <<"---------------------------------------\n";
  39.     myCircle.setDiameter(16.25);
  40.     cout << " circle diameter is : " << myCircle.getDiameter()<< " cm" << endl;
  41.     cout << " circumference of a circle is :" << myCircle.getCircumference()<<" cm" << endl;
  42.     cout << " circle surface area is : " << myCircle.getarea()<<" cm2" << endl;
  43.   cin.get();
  44. }
RAW Paste Data