[Lemon-commits] [lemon_svn] athos: r299 - hugo/trunk/src/work/athos/xy
Lemon SVN
svn at lemon.cs.elte.hu
Mon Nov 6 20:38:36 CET 2006
Author: athos
Date: Fri Mar 19 15:47:36 2004
New Revision: 299
Modified:
hugo/trunk/src/work/athos/xy/xy.cc
hugo/trunk/src/work/athos/xy/xy.h
Log:
Még Ãrtam bele 2 dolgot, meg a tesztelot is kibovitettem.
Modified: hugo/trunk/src/work/athos/xy/xy.cc
==============================================================================
--- hugo/trunk/src/work/athos/xy/xy.cc (original)
+++ hugo/trunk/src/work/athos/xy/xy.cc Fri Mar 19 15:47:36 2004
@@ -1,26 +1,39 @@
#include <xy.h>
#include <iostream>
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<int> osszeg;
+ xy<int> kul;
xy<int> z;
vector< xy<int> > 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; i<v.size(); ++i) {
cout << v[i] << ", A normanégyzete: " << v[i].normSquare() <<endl;
+ cout << v[i] << " " << s << " szorosa " << v[i]*s <<endl;
+ cout << v[i] << " " << s << " edrésze " << v[i]/s <<endl;
+ }
+ if (v.size()>1){
+ cout << "Az elsö kettö szorzata: " << v[0]*v[1] << endl;
}
+
cout << "Eleg nehez volt." << endl;
}
Modified: hugo/trunk/src/work/athos/xy/xy.h
==============================================================================
--- hugo/trunk/src/work/athos/xy/xy.h (original)
+++ hugo/trunk/src/work/athos/xy/xy.h Fri Mar 19 15:47:36 2004
@@ -1,3 +1,4 @@
+// -*- c++ -*-
/**
2 dimensional vector (plainvector) implementation
@@ -7,111 +8,126 @@
#include <iostream>
-using namespace std;
-template<typename T>
-class xy {
- T _x,_y;
-
-public:
-
- ///Default constructor: both coordinates become 0
- xy() { _x=_y=0; }
-
- ///Constructing from coordinates
- xy(T a, T b) { _x=a; _y=b; }
-
- ///Gives back the x coordinate
- T x(){
- return _x;
- };
-
- ///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;
- };
+namespace hugo {
+
+ template<typename T>
+ class xy {
+ T _x,_y;
+
+ public:
+
+ ///Default constructor: both coordinates become 0
+ xy() { _x=_y=0; }
+
+ ///Constructing from coordinates
+ xy(T a, T b) { _x=a; _y=b; }
+
+ ///Gives back the x coordinate
+ T x(){
+ return _x;
+ };
+
+ ///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;
+ };
- ///Increments the left hand side by u
- xy<T>& operator +=(const xy<T>& u){
- _x += u._x;
- _y += u._y;
- return *this;
- };
+ ///Increments the left hand side by u
+ xy<T>& operator +=(const xy<T>& u){
+ _x += u._x;
+ _y += u._y;
+ return *this;
+ };
- ///Decrements the left hand side by u
- xy<T>& operator -=(const xy<T>& u){
- _x -= u._x;
- _y -= u._y;
- return *this;
- };
-
- ///Multiplying the left hand side with a scalar
- xy<T>& operator *=(const T &u){
- _x *= u;
- _y *= u;
- return *this;
- };
+ ///Decrements the left hand side by u
+ xy<T>& operator -=(const xy<T>& u){
+ _x -= u._x;
+ _y -= u._y;
+ return *this;
+ };
+
+ ///Multiplying the left hand side with a scalar
+ xy<T>& operator *=(const T &u){
+ _x *= u;
+ _y *= u;
+ return *this;
+ };
+
+ ///Dividing the left hand side by a scalar
+ xy<T>& operator /=(const T &u){
+ _x /= u;
+ _y /= u;
+ return *this;
+ };
- ///Returns the scalar product of two vectors
- T operator *(const xy<T>& u){
- return _x*u._x+_y*u._y;
- };
+ ///Returns the scalar product of two vectors
+ T operator *(const xy<T>& u){
+ return _x*u._x+_y*u._y;
+ };
- ///Returns the sum of two vectors
- xy<T> operator+(const xy<T> &u) const {
- xy<T> b=*this;
- return b+=u;
- };
-
- ///Returns the difference of two vectors
- xy<T> operator-(const xy<T> &u) const {
- xy<T> b=*this;
- return b-=u;
- };
-
- ///Returns a vector multiplied by a scalar
- xy<T> operator*(const T &u) const {
- xy<T> b=*this;
- return b*=u;
- };
-
- ///Testing equality
- bool operator==(const xy<T> &u){
- return (_x==u._x) && (_y==u._y);
- };
-
- ///Testing inequality
- bool operator!=(xy u){
- return (_x!=u._x) || (_y!=u._y);
- };
-
-};
-///Reading a plainvector from a stream
-template<typename T>
-inline
-istream& operator>>(istream &is, xy<T> &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<T> buf(a,b);
- z=buf;
- return is;
-}
-
-///Outputting a plainvector to a stream
-template<typename T>
-inline
-ostream& operator<<(ostream &os, xy<T> z)
-{
- os << "(" << z.x() << ", " << z.y() << ")";
- return os;
-}
-
+ ///Returns the sum of two vectors
+ xy<T> operator+(const xy<T> &u) const {
+ xy<T> b=*this;
+ return b+=u;
+ };
+
+ ///Returns the difference of two vectors
+ xy<T> operator-(const xy<T> &u) const {
+ xy<T> b=*this;
+ return b-=u;
+ };
+
+ ///Returns a vector multiplied by a scalar
+ xy<T> operator*(const T &u) const {
+ xy<T> b=*this;
+ return b*=u;
+ };
+
+ ///Returns a vector divided by a scalar
+ xy<T> operator/(const T &u) const {
+ xy<T> b=*this;
+ return b/=u;
+ };
+
+ ///Testing equality
+ bool operator==(const xy<T> &u){
+ return (_x==u._x) && (_y==u._y);
+ };
+
+ ///Testing inequality
+ bool operator!=(xy u){
+ return (_x!=u._x) || (_y!=u._y);
+ };
+
+ };
+
+ ///Reading a plainvector from a stream
+ template<typename T>
+ inline
+ std::istream& operator>>(std::istream &is, xy<T> &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<T> buf(a,b);
+ z=buf;
+ return is;
+ }
+
+ ///Outputting a plainvector to a stream
+ template<typename T>
+ inline
+ std::ostream& operator<<(std::ostream &os, xy<T> z)
+ {
+ os << "(" << z.x() << ", " << z.y() << ")";
+ return os;
+ }
+} //namespace hugo
#endif //HUGO_XY_H
More information about the Lemon-commits
mailing list