#include #include //----------------------------------------------- // cPiste class cPiste { private: // pisteen koordinaatit int x; int y; public: cPiste(int koordX, int koordY); void piirra() const ; int getX() const { return x; } int getY() const { return y; } cPiste add(const cPiste &p) const { return cPiste(x+p.x,y+p.y); } bool operator<=(const cPiste &p) const { // varo vähän return (x <= p.x && y <= p.y); } }; // a = b = 4; ostream &operator<<(ostream &os,const cPiste &p) { os << "(" << p.getX() << "," << p.getY() << ")"; return os; } cPiste::cPiste(int koordX, int koordY) { x = koordX; y = koordY; } void cPiste::piirra() const { cout << "Piste: " << *this << endl; } //----------------------------------------------- // cSuorakaide class cSuorakaide { private: cPiste vy; // vas. yläkulman koordinaatit cPiste koko; public: cSuorakaide(int x, int y, int leveys, int korkeus); void piirra() const; bool onko_sisalla(const cPiste &p) const; cPiste getOa() const { return vy.add(koko); } const cPiste &getVy() const { return vy; } int x1() { return getVy().getX(); } int y1() { return getVy().getY(); } }; // cSuorakaide s(3,4,5,6); // int x = getVy().getX(); cSuorakaide::cSuorakaide(int x, int y, int leveys, int korkeus) : vy(x,y), koko(leveys,korkeus) { } void cSuorakaide::piirra() const { // metodi tulostaa suorakaiteen vas. yläkulman ja oik. alakulman cout << "Suorakaide: " << vy << " x " << getOa() << endl; } bool cSuorakaide::onko_sisalla(const cPiste &p) const { return ( vy <= p && p <= getOa() ); } //----------------------------------------------- // testipääohjelma int main (void) { cSuorakaide suorakaide(10,10, 200, 100); cPiste piste(25, 25); suorakaide.piirra(); piste.piirra(); if (suorakaide.onko_sisalla(cPiste(00,20))) cout << "Sisällä!" << endl; else cout << "Ei ole sisällä!" << endl; getch(); return 0; }