Advertisement
100rads

koordinatni sustav

Apr 5th, 2019
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.80 KB | None | 0 0
  1. #include "stdafx.h"
  2. #include <iostream>
  3.  
  4. using namespace std;
  5.  
  6. class Point {
  7.     int x;
  8.     int y;
  9.  
  10.     int distance() {
  11.         double rez;
  12.         rez = sqrt((double)(x * x) + (double)(y * y));
  13.         return rez;
  14.     }
  15. public:
  16.     Point() {
  17.         x = 0;
  18.         y = 0;
  19.     }
  20.  
  21.     Point(int x1, int y1) {
  22.         x = x1;
  23.         y = y1;
  24.     }
  25.  
  26.     void setX(int x1) {
  27.         x = x1;
  28.     }
  29.  
  30.     void setY(int y1) {
  31.         y = y1;
  32.     }
  33.  
  34.     int getX() {
  35.         return x;
  36.     }
  37.  
  38.     int getY() {
  39.         return y;
  40.     }
  41.  
  42.     void print() {
  43.         cout << "x: " << x << " ";
  44.         cout << "y: " << y << " ";
  45.         cout << endl;
  46.         if (distance() == 0) {
  47.             cout << "Point is centered.";
  48.         }
  49.         else {
  50.             cout << "Distance: " << distance();
  51.         }
  52.         cout << endl;
  53.     }
  54. };
  55.  
  56. int main()
  57. {
  58.     Point p1;
  59.     Point p2(20, 20);
  60.  
  61.     p1.setX(5);
  62.     p1.setY(10);
  63.  
  64.     p1.print();
  65.     p2.print();
  66.  
  67.     return 0;
  68. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement