prometheus800

Круг C++

Mar 23rd, 2020
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.21 KB | None | 0 0
  1. /*
  2. Круг Problem 2 (0 / 0)
  3. Да се дефинира класа Krug, во која се чуваат информации за:
  4.  
  5. радиус float
  6. бројот π const float.
  7. Во класата да се реализираат:
  8.  
  9. default конструктор и конструктор со аргументи
  10. метод за пресметување плоштина
  11. метод за пресметување периметар
  12. метод кој кажува дали плоштината и периметарот на даден круг се еднакви
  13. */
  14.  
  15.  
  16. #include <iostream>
  17. using namespace std;
  18.  
  19. class Krug {
  20.     private:
  21.         float radius;
  22.         float pi = 3.14;
  23.     public:
  24.         Krug(){}
  25.         Krug(float x, float y){
  26.             radius = x;
  27.             pi = y;
  28.         }
  29.         //Set Metodi
  30.         void set_Radius(float r){
  31.             radius = r;
  32.         }
  33.         void set_Pi(const float paj){
  34.             pi = paj;
  35.         }
  36.         //Get Metodi
  37.         float getRadius(){
  38.             return radius;
  39.         }
  40.         const float getPi(){
  41.             return pi;
  42.         }
  43.         //Presmetuvanje plostina
  44.         float plostina(Krug a){
  45.             a.pi = a.getPi();
  46.             a.radius = a.getRadius();
  47.             float area = a.pi * (a.radius * a.radius);
  48.             return area;
  49.         }
  50.         //Presmetuvanje perimetar
  51.         float perimetar(Krug a){
  52.             a.pi = a.getPi();
  53.             a.radius = a.getRadius();
  54.             float circumference = 2* a.pi * a.radius;
  55.             return circumference;
  56.         }
  57.         //Proverka dali se ednakvi plostinata i perimetarot
  58.         int ednakvi(Krug x){
  59.             float a,b;
  60.             a = x.plostina(x);
  61.             b = x.perimetar(x);
  62.             if(a == b)
  63.                 return 1;
  64.             else
  65.                 return 0;
  66.         }
  67. };
  68.  
  69. int main() {
  70.     float r;
  71.     const float pi = 3.14;
  72.     cin >> r;
  73.     //instanciraj objekt od klasata Krug cij radius e vrednosta procitana od tastatura
  74.     Krug k(r,pi);
  75.     cout << k.perimetar(k) << endl;
  76.     cout << k.plostina(k) << endl;
  77.     cout << k.ednakvi(k) <<endl;
  78.     //instanciraj objekt od klasata Krug cij radius ne e definiran
  79.     return 0;
  80. }
Add Comment
Please, Sign In to add comment