//boxes.cpp //Introduction to writing classes. #include //cin, cout, endl using namespace std; class Box { public: //constructors //default constructor, has no parameters //Makes a 2 x 5 box of x's Box(); //***overloaded constructors***; //an n x n box of s's Box(int n); //a h x w box of r's Box(int h, int w); //a h x w box of symbol s Box(int h, int w, char s); //destructors //We will use the computer provided default destructor. //accessors - they give access to the data int GetArea(); //other methods void Draw(); private: int height; int width; char symbol; };//end box //implementation of Box Box::Box() { height=2; width=5; symbol='x'; return; } Box::Box(int n) { height=n; width=n; symbol='s'; return; } Box::Box(int h, int w) { height=h; width=w; symbol='r'; return; } Box::Box(int h, int w, char s) { height=h; width=w; symbol=s; return; } int Box::GetArea() { return height*width; } void Box::Draw() { int row,col; for (row=1; row<=height; row++) { for (col=1; col<=width; col++) cout << symbol; cout << endl; } //end for (row= return; } //*******end of Box implementation******** class Triangle{ public: //constructors // makes a 4 high by 4 wide right triangle Triangle(); // makes an h high by w wide right triangle Triangle(int h,int w); //methods void Draw(); private: int height; int width; };//end Triangle //implementation of Triangle Triangle::Triangle() { height=4; width=4; return; } Triangle::Triangle(int h, int w) { height=h; width=w; return; } void Triangle::Draw() { float slant=static_cast(width) / height; int row,col; for (row=1;row<=height;row++) { for (col=1;col<=(slant*row);col++) cout << 'T'; cout << endl; } //end for(row= return; } int main() { Box plain; //default constructor Box square(3); Box rect(3,6); Box surprise(1,15,'!'); plain.Draw(); cout << "plain's area is: " << plain.GetArea()<< endl; square.Draw(); cout << "square's area is: " << square.GetArea()<< endl; rect.Draw(); surprise.Draw(); cout << rect.GetArea() << '\t' << surprise.GetArea() << endl; Triangle pythagoras; Triangle euclid(5,17); pythagoras.Draw(); cout << endl; euclid.Draw(); //If you want to see your output //when you run the .exe file or on debug char c; cout << "Type a key and return to close."; cin >> c; return 0; }