munther_abdellatif

struct exc

Jul 11th, 2021 (edited)
222
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. struct circle {
  5. private :
  6. float diameter;
  7. public :
  8.     // constractor
  9.     circle (float d) {
  10.         diameter = d;
  11.     }
  12.     // class function
  13.     void PrintInfo (){
  14.         float ci = 2 * pi * diameter;
  15.         float area = pi * diameter * diameter;
  16.         cout << " circle diameter is : " << diameter <<" cm" << endl;
  17.         cout << " circumference of a circle is :" << ci <<" cm" << endl;
  18.         cout << " circle surface area is : " << area << " cm2" << endl;
  19.     }
  20.     // setter
  21.     void setDiameter(float d) {
  22.         diameter = d;
  23.     }
  24.     // getter
  25.     float getDiameter() {
  26.         return diameter;
  27.     }
  28.     float getCircumference() {
  29.         return 2 * pi * diameter;
  30.     }
  31.     float getarea() {
  32.         return pi * diameter * diameter;
  33.     }
  34. };
  35.  
  36. int main() {
  37.     circle myCircle(14);
  38.     myCircle.PrintInfo();
  39.     cout <<"---------------------------------------\n";
  40.     myCircle.setDiameter(16.25);
  41.     cout << " circle diameter is : " << myCircle.getDiameter()<< " cm" << endl;
  42.     cout << " circumference of a circle is :" << myCircle.getCircumference()<<" cm" << endl;
  43.     cout << " circle surface area is : " << myCircle.getarea()<<" cm2" << endl;
  44.     cin.get();
  45. }
RAW Paste Data