COIN-OR::LEMON - Graph Library

Changeset 207:9910d5a5be7f in lemon-0.x


Ignore:
Timestamp:
03/19/04 15:47:36 (20 years ago)
Author:
athos
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

Legend:

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

    r201 r207  
    22#include <iostream>
    33using namespace std;
     4using namespace hugo;
    45int main()
    56{
    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;
    713
    814        xy<int> osszeg;
     15        xy<int> kul;
    916        xy<int> z;
    1017
    1118        vector< xy<int> > v;
    12 
     19 
    1320        while(cin >> z) {
    1421                v.push_back(z);
    1522                osszeg += z;
     23                kul -= z;
    1624                cout << "Az összeg aktualisan: " << osszeg << endl;
     25                cout << "A különbség aktualisan: " << kul << endl;
    1726        }
    18 
    19 
    2027
    2128        cout << "A kovetkezo szamokat szoroztam ossze:" << endl;
    2229        for(unsigned int i=0; i<v.size(); ++i) {
    2330          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;
    2433        }
     34        if (v.size()>1){
     35          cout << "Az elsö kettö szorzata: " << v[0]*v[1] << endl;
     36        }
     37       
    2538        cout << "Eleg nehez volt." << endl;
    2639}
  • src/work/athos/xy/xy.h

    r201 r207  
     1// -*- c++ -*-
    12/**
    232 dimensional vector (plainvector) implementation
     
    89#include <iostream>
    910
    10 using namespace std;
    11 template<typename T>
    12 class xy {
    13   T _x,_y;
     11namespace hugo {
    1412
    15 public:
     13  template<typename T>
     14    class xy {
     15    T _x,_y;
    1616
    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; }
    1921
    20   ///Constructing from coordinates
    21   xy(T a, T b) { _x=a; _y=b; }
     22      ///Constructing from coordinates
     23      xy(T a, T b) { _x=a; _y=b; }
    2224
    23   ///Gives back the x coordinate
    24   T x(){
    25     return _x;
    26   };
     25      ///Gives back the x coordinate
     26      T x(){
     27        return _x;
     28      };
    2729
    28   ///Gives back the y coordinate
    29   T y(){
    30     return _y;
    31   };
     30      ///Gives back the y coordinate
     31      T y(){
     32        return _y;
     33      };
    3234
    33   ///Gives back the square of the norm of the vector
    34   T normSquare(){
    35     return _x*_x+_y*_y;
    36   };
     35      ///Gives back the square of the norm of the vector
     36      T normSquare(){
     37        return _x*_x+_y*_y;
     38      };
    3739 
    38   ///Increments the left hand side by u
    39   xy<T>& operator +=(const xy<T>& u){
    40     _x += u._x;
    41     _y += u._y;
    42     return *this;
    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      };
    4446 
    45   ///Decrements the left hand side by u
    46   xy<T>& operator -=(const xy<T>& u){
    47     _x -= u._x;
    48     _y -= u._y;
    49     return *this;
    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      };
    5153
    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      };
    5867 
    59   ///Returns the scalar product of two vectors
    60   T operator *(const xy<T>& u){
    61     return _x*u._x+_y*u._y;
    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      };
    6372 
    64   ///Returns the sum of two vectors
    65   xy<T> operator+(const xy<T> &u) const {
    66     xy<T> b=*this;
    67     return b+=u;
    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      };
    6978
    70   ///Returns the difference of two vectors
    71   xy<T> operator-(const xy<T> &u) const {
    72     xy<T> b=*this;
    73     return b-=u;
    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      };
    7584
    76   ///Returns a vector multiplied by a scalar
    77   xy<T> operator*(const T &u) const {
    78     xy<T> b=*this;
    79     return b*=u;
    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      };
    8190
    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      };
    8696
    87   ///Testing inequality
    88   bool operator!=(xy u){
    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      };
    91101
    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      };
    105106
    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    };
    114108
     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  }
    115121
     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
    116132
    117133#endif //HUGO_XY_H
Note: See TracChangeset for help on using the changeset viewer.