Advertisement
Aseron

Untitled

Sep 18th, 2017
364
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.71 KB | None | 0 0
  1. #include <iostream>
  2. #include <math.h>
  3.  
  4. using namespace std;
  5.  
  6. class Vector{
  7.    
  8.     double x;
  9.     double y;
  10.    
  11.     public:
  12.        
  13.     Vector();
  14.     Vector(double, double);
  15.    
  16.     void print();
  17.     double abs();
  18. };
  19.  
  20. Vector::Vector(double x, double y){
  21.     this->x=x;
  22.     this->y=y;
  23. }
  24.  
  25. Vector::Vector(){
  26.     cin >> x >> y;
  27. }
  28. void Vector::print(){
  29.     cout << "(" << x << "," << y << ")" << endl;;
  30. }
  31.  
  32. double Vector::abs(){
  33.    
  34.     return sqrt(x*x+y*y);
  35. }
  36.  
  37.  
  38.  
  39. int main(int argc, char** argv) {
  40.     // Vector *v = new Vector(1,2); // konstruktoros obj letrehozas
  41.     Vector *v = new Vector(); //obj letrehozas
  42.     v -> print(); // fuggvenyhivas
  43.     cout << v -> abs(); // kiiratni az absz erteket
  44.     delete v; // memoria felszabaditas
  45.    
  46.     return 0;
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement