edensheiko

Tragil_3->Circle class

Feb 13th, 2021 (edited)
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.53 KB | None | 0 0
  1. //Circle.h
  2. #pragma once
  3. class Circle
  4. {
  5. private:
  6.     double _pointX;
  7.     double _pointY;
  8.     double _raduis;
  9.     const double _Pi = 3.14;
  10.     int* _ptr = 0;
  11.  
  12.  
  13. public:
  14.     Circle(double,double,double);
  15.     ~Circle();
  16.     Circle();
  17.     void print_values();
  18.     void set_values(double, double);
  19.     double get_values(double&,double&);
  20.     double Perimeter();
  21.     double area();
  22.     int dyn_array();
  23.     void Set_values_by_user(double, double, double,int&);
  24. };
  25.  
  26. //----------------------------------------------------------------------
  27. //Main.cpp
  28. #include <iostream>
  29. #include <iomanip>
  30. #include "Circle.h"
  31.  
  32. using namespace std;
  33.  
  34. void main()
  35. {
  36.     double a, b;
  37.     double temp;
  38.     double temp_2;
  39.     double aa, bb, cc;
  40.     int amount;
  41.     Circle v1{ 5,5,0 };
  42.     v1.print_values();
  43.  
  44.     Circle v2{ 1,2,0 };
  45.     cout << "before change" << endl;
  46.     cout << "--------------------------" << endl;
  47.     v2.print_values();
  48.     cout << "--------------------------" << endl;
  49.     v2.set_values(9, 9);
  50.     v2.print_values();
  51.     temp = v2.get_values(a, b);
  52.     v2.print_values();
  53.     cout << "--------------------------" << endl;
  54.     Circle v3{ 0,0,0 };
  55.     v3.set_values(2, 0);
  56.     temp_2 = v3.Perimeter();
  57.     cout << "the Perimeter is ->:" << temp_2 << endl;
  58.     temp_2 = v3.area();
  59.     cout << "the Area is ->:" << temp_2 << endl;
  60.    
  61.  
  62.     cout << "--------------------------" << endl;
  63.     Circle v4;
  64.     cout << "enter the amount of circles to crate:" << endl;
  65.     cin >> amount;
  66.     int &ref = amount;
  67.     for (int i = 0; i < amount; i++)
  68.     {
  69.         cout << "please enter the data in (x,y,r)" << endl; // to call by for.
  70.         cin >> aa >> bb >> cc;
  71.         v4.Set_values_by_user(aa, bb, cc, amount);
  72.         v4.print_values();
  73.     }
  74.    
  75.    
  76.    
  77.  
  78.  
  79.  
  80.  
  81.  
  82.  
  83. }
  84. //--------------------------------------------------------------------------------------------------
  85. //Circle.cpp
  86. #include "Circle.h"
  87. #include <iostream>
  88. #include <iomanip>
  89. #include <cmath>
  90. #include <assert.h>
  91.  
  92. using namespace std;
  93.  
  94.  
  95. Circle::Circle(double x,double y,double rad)
  96. {
  97.     _pointX = x;
  98.     _pointY = y;
  99.     _raduis = rad;
  100. }
  101.  
  102. Circle::~Circle()
  103. {
  104.    
  105.  
  106. }
  107.  
  108. void Circle::print_values()
  109. {
  110.     cout << setw(5) << "x:" << _pointX << endl;
  111.     cout << setw(5) << "y:" << _pointY << endl;
  112.     cout << setw(5) << "rad:" << _raduis << endl;
  113.  
  114. }
  115.  
  116. void Circle::set_values(double Xx, double Yy)
  117. {
  118.     _pointX = Xx;
  119.     _pointY = Yy;
  120. }
  121.  
  122. double Circle::get_values(double& X_x, double& Y_y)
  123. {
  124.     X_x = _pointX;
  125.     Y_y = _pointY;
  126.  
  127.     return _raduis;
  128.  
  129.        
  130. }
  131.  
  132. double Circle::Perimeter()
  133. {
  134.     double per;
  135.     _pointX = abs(_pointX);
  136.     _pointY = abs(_pointY);
  137.     _raduis = (_pointX + _pointY) / 2;
  138.     per = _raduis * _Pi * 2;
  139.     return per;
  140. }
  141.  
  142. double Circle::area()
  143. {
  144.     double s_area;
  145.     _pointX = abs(_pointX);
  146.     _pointY = abs(_pointY);
  147.     _raduis = (_pointX + _pointY) / 2;
  148.     s_area = _Pi*pow((_raduis),2);
  149.     return s_area;
  150. }
  151.  
  152. int Circle::dyn_array()
  153. {
  154.     int n;
  155.     cout << "enter the amount of wanted circles:" << endl;
  156.     cin >> n;
  157.     _ptr = new int[n];
  158.     for (int i = 0; i < n; i++) // need to add values///
  159.     {
  160.         cout << "enter the values of the circles" << endl;
  161.         cin >>_ptr[i];
  162.     }
  163.  
  164.     return 0;
  165. }
  166.  
  167. Circle::Circle()
  168. {
  169.  
  170.  
  171. }
  172.  
  173. void Circle::Set_values_by_user(double XX, double YY, double rad,int & raf) // + ref from for , getting tge vlaues
  174. {
  175.  
  176.     /*_pointX = XX;
  177.     _pointY = YY;
  178.     _raduis = rad;*/
  179.  
  180.     _ptr = new int[raf]; //array of X
  181.     assert(_ptr);
  182.    
  183.     for (int i = 0; i < raf; i++) // need to add values/// // NEED TO RETURN? REF?
  184.     {
  185.         _pointX = XX;
  186.         _pointY = YY;
  187.         _raduis = rad;
  188.         break;
  189.     }
  190. }
  191. //------------------------------------------------------------------------------------------------------------------------
Add Comment
Please, Sign In to add comment