Changeset 240:4a1d2e642552 in lemon0.x
 Timestamp:
 03/23/04 18:28:47 (18 years ago)
 Branch:
 default
 Phase:
 public
 Convert:
 svn:c9d7d8f590d60310b91f818b3a526b0e/lemon/trunk@338
 Location:
 src/work/athos/xy
 Files:

 2 added
 2 edited
Legend:
 Unmodified
 Added
 Removed

src/work/athos/xy/xy.cc
r207 r240 6 6 { 7 7 8 cout << " Még egy skalárt is kérek (szépen)!" << endl;8 cout << "Kérek szépen egy egész számot!" << endl; 9 9 int s; 10 10 cin >> s; 
src/work/athos/xy/xy.h
r237 r240 13 13 template<typename T> 14 14 class xy { 15 T _x,_y;16 15 17 16 public: 17 18 T x,y; 18 19 19 20 ///Default constructor: both coordinates become 0 20 xy() : _x(0), _y(0 ){ /*_x=_y=0;*/}21 xy() : x(0), y(0) {} 21 22 22 ///Constructing from coordinates23 xy(T a, T b) : _x(a), _x(b) { /*_x=a; _y=b;*/}23 ///Constructing the instance from coordinates 24 xy(T a, T b) : x(a), y(a) { } 24 25 25 ///Gives back the x coordinate26 T x(){27 return _x;28 };29 30 ///Gives back the y coordinate31 T y(){32 return _y;33 };34 26 35 27 ///Gives back the square of the norm of the vector 36 28 T normSquare(){ 37 return _x*_x+_y*_y;29 return x*x+y*y; 38 30 }; 39 31 40 32 ///Increments the left hand side by u 41 33 xy<T>& operator +=(const xy<T>& u){ 42 _x += u._x;43 _y += u._y;34 x += u.x; 35 y += u.y; 44 36 return *this; 45 37 }; … … 47 39 ///Decrements the left hand side by u 48 40 xy<T>& operator =(const xy<T>& u){ 49 _x = u._x;50 _y = u._y;41 x = u.x; 42 y = u.y; 51 43 return *this; 52 44 }; … … 54 46 ///Multiplying the left hand side with a scalar 55 47 xy<T>& operator *=(const T &u){ 56 _x *= u;57 _y *= u;48 x *= u; 49 y *= u; 58 50 return *this; 59 51 }; … … 61 53 ///Dividing the left hand side by a scalar 62 54 xy<T>& operator /=(const T &u){ 63 _x /= u;64 _y /= u;55 x /= u; 56 y /= u; 65 57 return *this; 66 58 }; … … 68 60 ///Returns the scalar product of two vectors 69 61 T operator *(const xy<T>& u){ 70 return _x*u._x+_y*u._y;62 return x*u.x+y*u.y; 71 63 }; 72 64 … … 97 89 ///Testing equality 98 90 bool operator==(const xy<T> &u){ 99 return ( _x==u._x) && (_y==u._y);91 return (x==u.x) && (y==u.y); 100 92 }; 101 93 102 94 ///Testing inequality 103 95 bool operator!=(xy u){ 104 return ( _x!=u._x)  (_y!=u._y);96 return (x!=u.x)  (y!=u.y); 105 97 }; 106 98 … … 112 104 std::istream& operator>>(std::istream &is, xy<T> &z) 113 105 { 114 ///This is not the best solution here: I didn't know how to solve this with friend functions 115 T a,b; 116 is >> a >> b; 117 xy<T> buf(a,b); 118 z=buf; 106 107 is >> z.x >> z.y; 119 108 return is; 120 109 } … … 125 114 std::ostream& operator<<(std::ostream &os, xy<T> z) 126 115 { 127 os << "(" << z.x () << ", " << z.y()<< ")";116 os << "(" << z.x << ", " << z.y << ")"; 128 117 return os; 129 118 }
Note: See TracChangeset
for help on using the changeset viewer.