//----------------------------------------------------------------- // // arrayso.cpp // // An array of objects, in this case the familiar point object. // // written by: Elizabeth Sklar, modified by Simon Parsons // modified : 25th April 2009 // //----------------------------------------------------------------- /* arrayso.cpp */ #include using namespace std; class Point { private: int x, y; public: Point() { } Point( int x0, int y0 ) : x(x0), y(y0) { } void set( int x0, int y0 ) { x = x0; y = y0; } int getX() { return x; } int getY() { return y; } void print() const { cout << "(" << x << "," << y << ") "; } }; int main() { Point triangle[3]; // Declare the array of point objects triangle[0].set( 0,0 ); triangle[1].set( 0,3 ); triangle[2].set( 3,0 ); cout << "here is the triangle: "; for ( int i=0; i<3; i++ ) { triangle[i].print(); } cout << endl; }