Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <chrono>
- using namespace std;
- class Square
- {
- protected:
- int length;
- int width;
- int line;
- public:
- Square(int a)
- {
- length = a;
- width = a;
- line = 0;
- }
- void draw()
- {
- for(int i = 0; i < width; i++)
- {
- drawline();
- }
- cout << endl;
- }
- void drawline()
- {
- for(int i = 0; i < length; i++)
- {
- cout << "*";
- }
- cout << endl;
- }
- };
- class Triangle : public Square
- {
- public:
- Triangle(int a) : Square(a)
- {
- length = a;
- line = a;
- }
- void draw()
- {
- for(int i = 0; i < line; i++)
- {
- drawline();
- length -= 1;
- }
- cout << endl;
- }
- };
- class Rectangle : public Square
- {
- public:
- Rectangle(int a, int b) : Square(a)
- {
- length = a;
- width = b;
- }
- void draw()
- {
- for(int i = 0; i < width; i++)
- {
- drawline();
- }
- cout << endl;
- }
- };
- int main()
- {
- Square A(5);
- Triangle B(4);
- Rectangle C(4,7);
- A.draw();
- B.draw();
- C.draw();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement