Advertisement
Dubwyn

Untitled

Jun 5th, 2018
257
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.39 KB | None | 0 0
  1. #include<iostream>
  2. #include<cmath>
  3. using namespace std;
  4.  
  5. class Point {
  6. private:
  7.     char label;
  8.     double x, y;
  9. public:
  10.     Point();
  11.     void setP(char, double, double);
  12.     void readP();
  13.     double distP();
  14.     char getLabel();
  15.     double getX();
  16.     double getY();
  17. };
  18.  
  19. Point::Point() {
  20.     x = y = 0;
  21.     label = '-';
  22. }
  23.  
  24. void Point::setP(char nc, double nx, double ny) {
  25.     label = nc;
  26.     x = nx;
  27.     y = ny;
  28. }
  29.  
  30. void Point::readP() {
  31.     cout << "label: "; cin >> label;
  32.     cout << "X: "; cin >> x;
  33.     cout << "Y: "; cin >> y;
  34. }
  35.  
  36. double Point::distP() {
  37.     return sqrt(x*x + y*y);
  38. }
  39.  
  40. char Point::getLabel() {
  41.     return label;
  42. }
  43.  
  44. double Point::getX() {
  45.     return x;
  46. }
  47.  
  48. double Point::getY() {
  49.     return y;
  50. }
  51.  
  52. int main() {
  53.     Point A, B;
  54.  
  55.     char c;
  56.     double x, y;
  57.  
  58.     cout << "label: ";
  59.     cin >> c;
  60.     cout << "X: ";
  61.     cin >> x;
  62.     cout << "Y: ";
  63.     cin >> y;
  64.     A.setP(c, x, y);
  65.  
  66.     B.readP();
  67.  
  68.     if (A.distP() != B.distP()) {
  69.         if (A.distP() < B.distP()) {
  70.             c = A.getLabel();
  71.             x = A.getX();
  72.             y = A.getY();
  73.         } else {
  74.             c = B.getLabel();
  75.             x = B.getX();
  76.             y = B.getY();
  77.         }
  78.         cout << c << " -( " << x << " ; " << y << " ) " << endl;
  79.     } else {
  80.         cout << "Tochkite sa na ravni raztoqniq." << endl;
  81.     }
  82.  
  83.     return 0;
  84. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement