Przesyłanie wielu elementów do funkcji.
Ostatnio zmodyfikowano 2016-11-02 14:12
mateczek |
» 2016-11-02 14:12:34 Zobacz sobie tak napisaną klasę punkt !!! odległość liczona w konstruktorze z automatu #include<iostream> #include<vector> #include<cmath> #include<algorithm>
using namespace std; class punkt { int x, y; double odleglosc; friend ostream & operator <<( ostream & c, punkt p ); public: punkt( int _x, int _y ) : x( _x ) , y( _y ) { odleglosc = sqrt( x * x + y * y ); } punkt() { } bool operator <( punkt p ) { return odleglosc < p.odleglosc; } };
ostream & operator <<( ostream & c, punkt p ) { return c << p.x << " " << p.y << " odleglosc miedzy punktami: " << p.odleglosc << endl; }
int main() { vector < punkt > tablica = { punkt( 2, 3 ), punkt( 3, 4 ), punkt( 1, 1 ) }; sort( tablica.begin(), tablica.end() ); cout << "najdalej polozony punkt : " << tablica[ 2 ]; cout << "najblizej polozony punkt: " << tablica[ 0 ]; }
|
|
1 « 2 » |