M?g ?rtam bele 2 dolgot, meg a tesztelot is kibovitettem.
authorathos
Fri, 19 Mar 2004 14:47:36 +0000
changeset 2079910d5a5be7f
parent 206 47f62d789fe7
child 208 1e36245f905d
M?g ?rtam bele 2 dolgot, meg a tesztelot is kibovitettem.
src/work/athos/xy/xy.cc
src/work/athos/xy/xy.h
     1.1 --- a/src/work/athos/xy/xy.cc	Fri Mar 19 09:09:20 2004 +0000
     1.2 +++ b/src/work/athos/xy/xy.cc	Fri Mar 19 14:47:36 2004 +0000
     1.3 @@ -1,26 +1,39 @@
     1.4  #include <xy.h>
     1.5  #include <iostream>
     1.6  using namespace std;
     1.7 +using namespace hugo;
     1.8  int main()
     1.9  {
    1.10 -	cout << "Kerek sok sikvektorokat." << endl;
    1.11 +
    1.12 +	cout << "Még egy skalárt is kérek (szépen)!" << endl;
    1.13 +	int s;
    1.14 +	cin >> s;
    1.15 +
    1.16 +	cout << "Kerek sok sikvektort." << endl;
    1.17  
    1.18  	xy<int> osszeg;
    1.19 +	xy<int> kul;
    1.20  	xy<int> z;
    1.21  
    1.22  	vector< xy<int> > v;
    1.23 -
    1.24 + 
    1.25  	while(cin >> z) {
    1.26  		v.push_back(z);
    1.27  		osszeg += z;
    1.28 +		kul -= z;
    1.29         		cout << "Az összeg aktualisan: " << osszeg << endl;
    1.30 +       		cout << "A különbség aktualisan: " << kul << endl;
    1.31  	}
    1.32  
    1.33 -
    1.34 -
    1.35  	cout << "A kovetkezo szamokat szoroztam ossze:" << endl;
    1.36  	for(unsigned int i=0; i<v.size(); ++i) {
    1.37  	  cout << v[i] << ", A normanégyzete: " << v[i].normSquare() <<endl;
    1.38 +	  cout << v[i] << " " << s << " szorosa " << v[i]*s <<endl;
    1.39 +	  cout << v[i] << " " << s << " edrésze " << v[i]/s <<endl;
    1.40  	}
    1.41 +	if (v.size()>1){
    1.42 +	  cout << "Az elsö kettö szorzata: " << v[0]*v[1] << endl;
    1.43 +	}
    1.44 +	
    1.45  	cout << "Eleg nehez volt." << endl;
    1.46  }
     2.1 --- a/src/work/athos/xy/xy.h	Fri Mar 19 09:09:20 2004 +0000
     2.2 +++ b/src/work/athos/xy/xy.h	Fri Mar 19 14:47:36 2004 +0000
     2.3 @@ -1,3 +1,4 @@
     2.4 +// -*- c++ -*-
     2.5  /**
     2.6  2 dimensional vector (plainvector) implementation
     2.7  
     2.8 @@ -7,111 +8,126 @@
     2.9  
    2.10  #include <iostream>
    2.11  
    2.12 -using namespace std;
    2.13 -template<typename T>
    2.14 -class xy {
    2.15 -  T _x,_y;
    2.16 +namespace hugo {
    2.17  
    2.18 -public:
    2.19 +  template<typename T>
    2.20 +    class xy {
    2.21 +    T _x,_y;
    2.22  
    2.23 -  ///Default constructor: both coordinates become 0
    2.24 -  xy() { _x=_y=0; }
    2.25 +    public:
    2.26 +      
    2.27 +      ///Default constructor: both coordinates become 0
    2.28 +      xy() { _x=_y=0; }
    2.29  
    2.30 -  ///Constructing from coordinates
    2.31 -  xy(T a, T b) { _x=a; _y=b; }
    2.32 +      ///Constructing from coordinates
    2.33 +      xy(T a, T b) { _x=a; _y=b; }
    2.34  
    2.35 -  ///Gives back the x coordinate
    2.36 -  T x(){
    2.37 -    return _x;
    2.38 -  };
    2.39 +      ///Gives back the x coordinate
    2.40 +      T x(){
    2.41 +	return _x;
    2.42 +      };
    2.43  
    2.44 -  ///Gives back the y coordinate
    2.45 -  T y(){
    2.46 -    return _y;
    2.47 -  };
    2.48 +      ///Gives back the y coordinate
    2.49 +      T y(){
    2.50 +	return _y;
    2.51 +      };
    2.52  
    2.53 -  ///Gives back the square of the norm of the vector
    2.54 -  T normSquare(){
    2.55 -    return _x*_x+_y*_y;
    2.56 -  };
    2.57 +      ///Gives back the square of the norm of the vector
    2.58 +      T normSquare(){
    2.59 +	return _x*_x+_y*_y;
    2.60 +      };
    2.61    
    2.62 -  ///Increments the left hand side by u
    2.63 -  xy<T>& operator +=(const xy<T>& u){
    2.64 -    _x += u._x;
    2.65 -    _y += u._y;
    2.66 -    return *this;
    2.67 -  };
    2.68 +      ///Increments the left hand side by u
    2.69 +      xy<T>& operator +=(const xy<T>& u){
    2.70 +	_x += u._x;
    2.71 +	_y += u._y;
    2.72 +	return *this;
    2.73 +      };
    2.74    
    2.75 -  ///Decrements the left hand side by u
    2.76 -  xy<T>& operator -=(const xy<T>& u){
    2.77 -    _x -= u._x;
    2.78 -    _y -= u._y;
    2.79 -    return *this;
    2.80 -  };
    2.81 +      ///Decrements the left hand side by u
    2.82 +      xy<T>& operator -=(const xy<T>& u){
    2.83 +	_x -= u._x;
    2.84 +	_y -= u._y;
    2.85 +	return *this;
    2.86 +      };
    2.87  
    2.88 -  ///Multiplying the left hand side with a scalar
    2.89 -  xy<T>& operator *=(const T &u){
    2.90 -    _x *= u;
    2.91 -    _y *= u;
    2.92 -    return *this;
    2.93 -  };
    2.94 +      ///Multiplying the left hand side with a scalar
    2.95 +      xy<T>& operator *=(const T &u){
    2.96 +	_x *= u;
    2.97 +	_y *= u;
    2.98 +	return *this;
    2.99 +      };
   2.100 +
   2.101 +      ///Dividing the left hand side by a scalar
   2.102 +      xy<T>& operator /=(const T &u){
   2.103 +	_x /= u;
   2.104 +	_y /= u;
   2.105 +	return *this;
   2.106 +      };
   2.107    
   2.108 -  ///Returns the scalar product of two vectors
   2.109 -  T operator *(const xy<T>& u){
   2.110 -    return _x*u._x+_y*u._y;
   2.111 -  };
   2.112 +      ///Returns the scalar product of two vectors
   2.113 +      T operator *(const xy<T>& u){
   2.114 +	return _x*u._x+_y*u._y;
   2.115 +      };
   2.116    
   2.117 -  ///Returns the sum of two vectors
   2.118 -  xy<T> operator+(const xy<T> &u) const {
   2.119 -    xy<T> b=*this;
   2.120 -    return b+=u;
   2.121 -  };
   2.122 +      ///Returns the sum of two vectors
   2.123 +      xy<T> operator+(const xy<T> &u) const {
   2.124 +	xy<T> b=*this;
   2.125 +	return b+=u;
   2.126 +      };
   2.127  
   2.128 -  ///Returns the difference of two vectors
   2.129 -  xy<T> operator-(const xy<T> &u) const {
   2.130 -    xy<T> b=*this;
   2.131 -    return b-=u;
   2.132 -  };
   2.133 +      ///Returns the difference of two vectors
   2.134 +      xy<T> operator-(const xy<T> &u) const {
   2.135 +	xy<T> b=*this;
   2.136 +	return b-=u;
   2.137 +      };
   2.138  
   2.139 -  ///Returns a vector multiplied by a scalar
   2.140 -  xy<T> operator*(const T &u) const {
   2.141 -    xy<T> b=*this;
   2.142 -    return b*=u;
   2.143 -  };
   2.144 +      ///Returns a vector multiplied by a scalar
   2.145 +      xy<T> operator*(const T &u) const {
   2.146 +	xy<T> b=*this;
   2.147 +	return b*=u;
   2.148 +      };
   2.149  
   2.150 -  ///Testing equality
   2.151 -  bool operator==(const xy<T> &u){
   2.152 -    return (_x==u._x) && (_y==u._y);
   2.153 -  };
   2.154 +      ///Returns a vector divided by a scalar
   2.155 +      xy<T> operator/(const T &u) const {
   2.156 +	xy<T> b=*this;
   2.157 +	return b/=u;
   2.158 +      };
   2.159  
   2.160 -  ///Testing inequality
   2.161 -  bool operator!=(xy u){
   2.162 -    return  (_x!=u._x) || (_y!=u._y);
   2.163 -  };
   2.164 +      ///Testing equality
   2.165 +      bool operator==(const xy<T> &u){
   2.166 +	return (_x==u._x) && (_y==u._y);
   2.167 +      };
   2.168  
   2.169 -};
   2.170 -///Reading a plainvector from a stream
   2.171 -template<typename T>
   2.172 -inline
   2.173 -istream& operator>>(istream &is, xy<T> &z)
   2.174 -{
   2.175 -  ///This is not the best solution here: I didn't know how to solve this with friend functions
   2.176 -  T a,b;
   2.177 -  is >> a >> b;
   2.178 -  xy<T> buf(a,b);
   2.179 -  z=buf;
   2.180 -  return is;
   2.181 -}
   2.182 +      ///Testing inequality
   2.183 +      bool operator!=(xy u){
   2.184 +	return  (_x!=u._x) || (_y!=u._y);
   2.185 +      };
   2.186  
   2.187 -///Outputting a plainvector to a stream
   2.188 -template<typename T>
   2.189 -inline
   2.190 -ostream& operator<<(ostream &os, xy<T> z)
   2.191 -{
   2.192 -	os << "(" << z.x() << ", " << z.y() << ")";
   2.193 -	return os;
   2.194 -}
   2.195 +    };
   2.196  
   2.197 +  ///Reading a plainvector from a stream
   2.198 +  template<typename T>
   2.199 +  inline
   2.200 +  std::istream& operator>>(std::istream &is, xy<T> &z)
   2.201 +  {
   2.202 +    ///This is not the best solution here: I didn't know how to solve this with friend functions
   2.203 +    T a,b;
   2.204 +    is >> a >> b;
   2.205 +    xy<T> buf(a,b);
   2.206 +    z=buf;
   2.207 +    return is;
   2.208 +  }
   2.209  
   2.210 +  ///Outputting a plainvector to a stream
   2.211 +  template<typename T>
   2.212 +  inline
   2.213 +  std::ostream& operator<<(std::ostream &os, xy<T> z)
   2.214 +  {
   2.215 +    os << "(" << z.x() << ", " << z.y() << ")";
   2.216 +    return os;
   2.217 +  }
   2.218 +
   2.219 +} //namespace hugo
   2.220  
   2.221  #endif //HUGO_XY_H