Points

# Points - void print const for(unsigned i = 0 i<...

This preview shows pages 1–2. Sign up to view the full content.

// Points.cpp / // Points and shapes // Demonstrates aggregation, and the vector class. Also // shows the construction and destruction of objects. // Updated 11/02/03 / #include <iostream> #include <vector> using namespace std; u class Point { public: Point( int x = 0, int y = 0 ) :mX(x), mY(y) // initializer list { cout << "Point constructor" << endl; } { ~Point( ) { cout << "Point destructor" << endl; } { void print( ) const { cout << "(" << mX << "," << mY << ")"; } { private: int mX; int mY; }; } class Shape { public: :mVertices(vertices) { cout << "Shape constructor" << endl; } ~Shape( ) { cout << "Shape destructor" << endl; }

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: { void print( ) const { for(unsigned i = 0; i < mVertices.size(); i++) { mVertices[i].print( ); cout << " "; } cout << endl; } private: vector<Point> mVertices; }; } // Demonstrates how temporary objects are created and destroyed // while being inserted in a vector. / void Example1() { vector<Point> vertices; vertices.push_back( Point(0,0) ); vertices.push_back( Point(10,0) ); vertices.push_back( Point(10,10) ); cout << "All points inserted in vector" << endl; c Shape triangle( vertices ); triangle.print( ); } void main() { Example1(); E }...
View Full Document

## This note was uploaded on 10/17/2010 for the course SCIS COP 4338 taught by Professor Kipirvine during the Spring '10 term at FIU.

### Page1 / 2

Points - void print const for(unsigned i = 0 i<...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online