Changeset 207:9910d5a5be7f in lemon0.x
 Timestamp:
 03/19/04 15:47:36 (17 years ago)
 Branch:
 default
 Phase:
 public
 Convert:
 svn:c9d7d8f590d60310b91f818b3a526b0e/lemon/trunk@299
 Location:
 src/work/athos/xy
 Files:

 2 edited
Legend:
 Unmodified
 Added
 Removed

src/work/athos/xy/xy.cc
r201 r207 2 2 #include <iostream> 3 3 using namespace std; 4 using namespace hugo; 4 5 int main() 5 6 { 6 cout << "Kerek sok sikvektorokat." << endl; 7 8 cout << "Még egy skalárt is kérek (szépen)!" << endl; 9 int s; 10 cin >> s; 11 12 cout << "Kerek sok sikvektort." << endl; 7 13 8 14 xy<int> osszeg; 15 xy<int> kul; 9 16 xy<int> z; 10 17 11 18 vector< xy<int> > v; 12 19 13 20 while(cin >> z) { 14 21 v.push_back(z); 15 22 osszeg += z; 23 kul = z; 16 24 cout << "Az összeg aktualisan: " << osszeg << endl; 25 cout << "A különbség aktualisan: " << kul << endl; 17 26 } 18 19 20 27 21 28 cout << "A kovetkezo szamokat szoroztam ossze:" << endl; 22 29 for(unsigned int i=0; i<v.size(); ++i) { 23 30 cout << v[i] << ", A normanégyzete: " << v[i].normSquare() <<endl; 31 cout << v[i] << " " << s << " szorosa " << v[i]*s <<endl; 32 cout << v[i] << " " << s << " edrésze " << v[i]/s <<endl; 24 33 } 34 if (v.size()>1){ 35 cout << "Az elsö kettö szorzata: " << v[0]*v[1] << endl; 36 } 37 25 38 cout << "Eleg nehez volt." << endl; 26 39 } 
src/work/athos/xy/xy.h
r201 r207 1 // * c++ * 1 2 /** 2 3 2 dimensional vector (plainvector) implementation … … 8 9 #include <iostream> 9 10 10 using namespace std; 11 template<typename T> 12 class xy { 13 T _x,_y; 11 namespace hugo { 14 12 15 public: 13 template<typename T> 14 class xy { 15 T _x,_y; 16 16 17 ///Default constructor: both coordinates become 0 18 xy() { _x=_y=0; } 17 public: 18 19 ///Default constructor: both coordinates become 0 20 xy() { _x=_y=0; } 19 21 20 ///Constructing from coordinates21 xy(T a, T b) { _x=a; _y=b; }22 ///Constructing from coordinates 23 xy(T a, T b) { _x=a; _y=b; } 22 24 23 ///Gives back the x coordinate24 T x(){25 26 };25 ///Gives back the x coordinate 26 T x(){ 27 return _x; 28 }; 27 29 28 ///Gives back the y coordinate29 T y(){30 31 };30 ///Gives back the y coordinate 31 T y(){ 32 return _y; 33 }; 32 34 33 ///Gives back the square of the norm of the vector34 T normSquare(){35 36 };35 ///Gives back the square of the norm of the vector 36 T normSquare(){ 37 return _x*_x+_y*_y; 38 }; 37 39 38 ///Increments the left hand side by u39 xy<T>& operator +=(const xy<T>& u){40 41 42 43 };40 ///Increments the left hand side by u 41 xy<T>& operator +=(const xy<T>& u){ 42 _x += u._x; 43 _y += u._y; 44 return *this; 45 }; 44 46 45 ///Decrements the left hand side by u46 xy<T>& operator =(const xy<T>& u){47 48 49 50 };47 ///Decrements the left hand side by u 48 xy<T>& operator =(const xy<T>& u){ 49 _x = u._x; 50 _y = u._y; 51 return *this; 52 }; 51 53 52 ///Multiplying the left hand side with a scalar 53 xy<T>& operator *=(const T &u){ 54 _x *= u; 55 _y *= u; 56 return *this; 57 }; 54 ///Multiplying the left hand side with a scalar 55 xy<T>& operator *=(const T &u){ 56 _x *= u; 57 _y *= u; 58 return *this; 59 }; 60 61 ///Dividing the left hand side by a scalar 62 xy<T>& operator /=(const T &u){ 63 _x /= u; 64 _y /= u; 65 return *this; 66 }; 58 67 59 ///Returns the scalar product of two vectors60 T operator *(const xy<T>& u){61 62 };68 ///Returns the scalar product of two vectors 69 T operator *(const xy<T>& u){ 70 return _x*u._x+_y*u._y; 71 }; 63 72 64 ///Returns the sum of two vectors65 xy<T> operator+(const xy<T> &u) const {66 67 68 };73 ///Returns the sum of two vectors 74 xy<T> operator+(const xy<T> &u) const { 75 xy<T> b=*this; 76 return b+=u; 77 }; 69 78 70 ///Returns the difference of two vectors71 xy<T> operator(const xy<T> &u) const {72 73 74 };79 ///Returns the difference of two vectors 80 xy<T> operator(const xy<T> &u) const { 81 xy<T> b=*this; 82 return b=u; 83 }; 75 84 76 ///Returns a vector multiplied by a scalar77 xy<T> operator*(const T &u) const {78 79 80 };85 ///Returns a vector multiplied by a scalar 86 xy<T> operator*(const T &u) const { 87 xy<T> b=*this; 88 return b*=u; 89 }; 81 90 82 ///Testing equality 83 bool operator==(const xy<T> &u){ 84 return (_x==u._x) && (_y==u._y); 85 }; 91 ///Returns a vector divided by a scalar 92 xy<T> operator/(const T &u) const { 93 xy<T> b=*this; 94 return b/=u; 95 }; 86 96 87 ///Testing inequality88 bool operator!=(xyu){89 return (_x!=u._x)  (_y!=u._y);90 };97 ///Testing equality 98 bool operator==(const xy<T> &u){ 99 return (_x==u._x) && (_y==u._y); 100 }; 91 101 92 }; 93 ///Reading a plainvector from a stream 94 template<typename T> 95 inline 96 istream& operator>>(istream &is, xy<T> &z) 97 { 98 ///This is not the best solution here: I didn't know how to solve this with friend functions 99 T a,b; 100 is >> a >> b; 101 xy<T> buf(a,b); 102 z=buf; 103 return is; 104 } 102 ///Testing inequality 103 bool operator!=(xy u){ 104 return (_x!=u._x)  (_y!=u._y); 105 }; 105 106 106 ///Outputting a plainvector to a stream 107 template<typename T> 108 inline 109 ostream& operator<<(ostream &os, xy<T> z) 110 { 111 os << "(" << z.x() << ", " << z.y() << ")"; 112 return os; 113 } 107 }; 114 108 109 ///Reading a plainvector from a stream 110 template<typename T> 111 inline 112 std::istream& operator>>(std::istream &is, xy<T> &z) 113 { 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; 119 return is; 120 } 115 121 122 ///Outputting a plainvector to a stream 123 template<typename T> 124 inline 125 std::ostream& operator<<(std::ostream &os, xy<T> z) 126 { 127 os << "(" << z.x() << ", " << z.y() << ")"; 128 return os; 129 } 130 131 } //namespace hugo 116 132 117 133 #endif //HUGO_XY_H
Note: See TracChangeset
for help on using the changeset viewer.