# Changeset 207:9910d5a5be7f in lemon-0.x for src/work/athos/xy

Ignore:
Timestamp:
03/19/04 15:47:36 (17 years ago)
Branch:
default
Phase:
public
Convert:
svn:c9d7d8f5-90d6-0310-b91f-818b3a526b0e/lemon/trunk@299
Message:

Még írtam bele 2 dolgot, meg a tesztelot is kibovitettem.

Location:
src/work/athos/xy
Files:
2 edited

Unmodified
Added
Removed
• ## src/work/athos/xy/xy.cc

 r201 #include using namespace std; using namespace hugo; int main() { cout << "Kerek sok sikvektorokat." << endl; cout << "Még egy skalárt is kérek (szépen)!" << endl; int s; cin >> s; cout << "Kerek sok sikvektort." << endl; xy osszeg; xy kul; xy z; vector< xy > v; while(cin >> z) { v.push_back(z); osszeg += z; kul -= z; cout << "Az összeg aktualisan: " << osszeg << endl; cout << "A különbség aktualisan: " << kul << endl; } cout << "A kovetkezo szamokat szoroztam ossze:" << endl; for(unsigned int i=0; i1){ cout << "Az elsö kettö szorzata: " << v[0]*v[1] << endl; } cout << "Eleg nehez volt." << endl; }
• ## src/work/athos/xy/xy.h

 r201 // -*- c++ -*- /** 2 dimensional vector (plainvector) implementation #include using namespace std; template class xy { T _x,_y; namespace hugo { public: template class xy { T _x,_y; ///Default constructor: both coordinates become 0 xy() { _x=_y=0; } public: ///Default constructor: both coordinates become 0 xy() { _x=_y=0; } ///Constructing from coordinates xy(T a, T b) { _x=a; _y=b; } ///Constructing from coordinates xy(T a, T b) { _x=a; _y=b; } ///Gives back the x coordinate T x(){ return _x; }; ///Gives back the x coordinate T x(){ return _x; }; ///Gives back the y coordinate T y(){ return _y; }; ///Gives back the y coordinate T y(){ return _y; }; ///Gives back the square of the norm of the vector T normSquare(){ return _x*_x+_y*_y; }; ///Gives back the square of the norm of the vector T normSquare(){ return _x*_x+_y*_y; }; ///Increments the left hand side by u xy& operator +=(const xy& u){ _x += u._x; _y += u._y; return *this; }; ///Increments the left hand side by u xy& operator +=(const xy& u){ _x += u._x; _y += u._y; return *this; }; ///Decrements the left hand side by u xy& operator -=(const xy& u){ _x -= u._x; _y -= u._y; return *this; }; ///Decrements the left hand side by u xy& operator -=(const xy& u){ _x -= u._x; _y -= u._y; return *this; }; ///Multiplying the left hand side with a scalar xy& operator *=(const T &u){ _x *= u; _y *= u; return *this; }; ///Multiplying the left hand side with a scalar xy& operator *=(const T &u){ _x *= u; _y *= u; return *this; }; ///Dividing the left hand side by a scalar xy& operator /=(const T &u){ _x /= u; _y /= u; return *this; }; ///Returns the scalar product of two vectors T operator *(const xy& u){ return _x*u._x+_y*u._y; }; ///Returns the scalar product of two vectors T operator *(const xy& u){ return _x*u._x+_y*u._y; }; ///Returns the sum of two vectors xy operator+(const xy &u) const { xy b=*this; return b+=u; }; ///Returns the sum of two vectors xy operator+(const xy &u) const { xy b=*this; return b+=u; }; ///Returns the difference of two vectors xy operator-(const xy &u) const { xy b=*this; return b-=u; }; ///Returns the difference of two vectors xy operator-(const xy &u) const { xy b=*this; return b-=u; }; ///Returns a vector multiplied by a scalar xy operator*(const T &u) const { xy b=*this; return b*=u; }; ///Returns a vector multiplied by a scalar xy operator*(const T &u) const { xy b=*this; return b*=u; }; ///Testing equality bool operator==(const xy &u){ return (_x==u._x) && (_y==u._y); }; ///Returns a vector divided by a scalar xy operator/(const T &u) const { xy b=*this; return b/=u; }; ///Testing inequality bool operator!=(xy u){ return  (_x!=u._x) || (_y!=u._y); }; ///Testing equality bool operator==(const xy &u){ return (_x==u._x) && (_y==u._y); }; }; ///Reading a plainvector from a stream template inline istream& operator>>(istream &is, xy &z) { ///This is not the best solution here: I didn't know how to solve this with friend functions T a,b; is >> a >> b; xy buf(a,b); z=buf; return is; } ///Testing inequality bool operator!=(xy u){ return  (_x!=u._x) || (_y!=u._y); }; ///Outputting a plainvector to a stream template inline ostream& operator<<(ostream &os, xy z) { os << "(" << z.x() << ", " << z.y() << ")"; return os; } }; ///Reading a plainvector from a stream template inline std::istream& operator>>(std::istream &is, xy &z) { ///This is not the best solution here: I didn't know how to solve this with friend functions T a,b; is >> a >> b; xy buf(a,b); z=buf; return is; } ///Outputting a plainvector to a stream template inline std::ostream& operator<<(std::ostream &os, xy z) { os << "(" << z.x() << ", " << z.y() << ")"; return os; } } //namespace hugo #endif //HUGO_XY_H
Note: See TracChangeset for help on using the changeset viewer.