codepad
[
create a new paste
]
login
|
about
Language:
C
C++
D
Haskell
Lua
OCaml
PHP
Perl
Plain Text
Python
Ruby
Scheme
Tcl
#include <iostream> #include <string> class Rectangle { private: static const unsigned int MAX_HEIGHT = 30; static const unsigned int MAX_WIDTH = 30; static const char FILLING = '_'; unsigned int width; unsigned int height; void drawHorizontalSides(); void drawVerticalSide(); public: Rectangle(unsigned int w, unsigned int h); void draw(); }; Rectangle::Rectangle (unsigned int w, unsigned int h) : width(w), height(h) { } void Rectangle::draw () { if(this->width > MAX_WIDTH) { std::cout << "Too large of a width, enter in something smaller!"; std::cout << std::endl << std::endl; } else if(this->width > MAX_HEIGHT) { std::cout << "Too large of a height, enter in something smaller!"; std::cout << std::endl << std::endl; } else { // Draw top. std::cout << " "; this->drawVerticalSide(); std::cout << " " << std::endl; // Draw sides. this->drawHorizontalSides(); // Draw bottom. std::cout << "|"; this->drawVerticalSide(); std::cout << "|"; } } void Rectangle::drawHorizontalSides() { std::string spacing(this->width, this->FILLING); for(unsigned int n = this->height - 1; n > 0; --n) { std::cout << "|" << spacing << spacing << "|" << std::endl; } } void Rectangle::drawVerticalSide() { for(unsigned int n = this->width; n > 0; --n) { std::cout << "__"; } } int main(int argc, char* argv[]) { Rectangle sample_rectangle(10, 7); sample_rectangle.draw(); }
Private
[
?
]
Run code
Submit