< previous page page_288 next page >

Page 288
LISTING 18.3 continued
d5ef64f4d3250b96ba5c07ca5bbc2f56.gif
74:
75:    Square::Square(int len, int width):
76:       Rectangle(len,width)
77:
78:    {
79:       if (GetLength() != GetWidth())
80:          cout << Error, not a square a Rectangle??\n;
81:    }
82:
83:    int main()
84:    {
85:       int choice;
86:       bool fQuit = false;
87:       Shape * sp;
88:
89:       while (1)
90:       {
91:          cout << (1)Circle (2)Rectangle (3)Square (0)Quit: ;
92:          cin >> choice;
93:
94:          switch (choice)
95:          {
96:             case 1: sp = new Circle(5);
97:             break;
98:            case 2: sp = new Rectangle(4,6);
99:            break;
100:           case 3: sp = new Square(5);
101:           break;
102:           default: fQuit = true;
103:           break;
104:         }
105:         if (fQuit)
106:            break;
107:
108:         sp->Draw();
109:         cout << \n;
110:      }
111:      return 0;
112:   }

Output:
(1)Circle (2)Rectangle (3)Square (0)Quit: 2
× × × × × ×
× × × × × ×
× × × × × ×
× × × × × ×
(1)Circle (2)Rectangle (3)Square (0)Quit:3
× × × × ×

 
< previous page page_288 next page >

If you like this book, buy it!