#include #include using namespace std; class rect { private: int width; int height; int area; void calc() { area=width*height; return; } public: int get_area() { return area; } void setsize(int w, int h) { // Prevent invalid numbers. if(w<0 || h<0) { cerr << "Invalid size parameter!" << endl; exit(-1); } width=w; height=h; calc(); return; } void print() { cout << "width = " << width << endl; cout << "height = " << height << endl; cout << "area = " << area << endl; return; } }; int main() { rect square; rect shapes[3]; square.setsize(5,5); cout << square.get_area() << endl; square.print(); cout << endl; shapes[0].setsize(3,5); shapes[1].setsize(2,4); shapes[2].setsize(1,3); for(int i=0;i<3;i++) { shapes[i].print(); cout << endl; } return 0; }