0

Compilation error

//Code: // Enter the width first, followed by an Enter, followed by the height #include <iostream> using namespace std; class Shape{ public: virtual void Draw() = 0; virtual int getArea() = 0; virtual int getEdge() = 0; }; class Rect : public Shape{ private: int width, height; public: Rect(int width, int height){ this -> width = width; this -> height = height; } ~Rect(); void Draw(){ int i, j; for(i = 0; i < height; i++){ for(j = 0; j < width; j++){ cout << "*"; } cout << endl; } } int getArea(){return width * height;} int getEdge(){return (2 * width) + (2 * height);} }; class Square : public Shape{ // Also derived from Rect but let's ignore that private: int length; public: Square(int length){ this -> length = length; } ~Square(); void Draw(){ int i, j; for(i = 0; i < length; i++){ for(j = 0; j < length; j++){ cout << "*"; } cout << endl; } } int getArea(){return length * length;} int getEdge(){return 4 * length;} }; int main() { int a, b, c; cin >> a; cin >> b; cin >> c; Shape *shape1 = new Rect(a, b); Shape *shape2 = new Square(c); //compilation error. shape1 -> Draw(); cout << "Perimeter is " << shape1 -> getEdge() << endl; cout << "Area is " << shape1 -> getArea() < endl; shape2 -> Draw(); cout << "Perimeter is " << shape2 -> getEdge() << endl; cout << "Area is " << shape2 -> getArea(); return 0; }

20th Jan 2019, 9:32 PM
mei
mei - avatar
5 Respuestas
+ 2
There's a cout line that is missing a '<' right before the endl in main
20th Jan 2019, 9:39 PM
Zeke Williams
Zeke Williams - avatar
+ 2
Also next time you should make a playground code and post that instead mei
20th Jan 2019, 9:41 PM
Zeke Williams
Zeke Williams - avatar
+ 1
oh, didn’t notice that lol thx
20th Jan 2019, 11:55 PM
mei
mei - avatar
0
line 61, maybe?
20th Jan 2019, 9:32 PM
mei
mei - avatar
0
😄 no problem. It happens to the best of us
21st Jan 2019, 12:07 AM
Zeke Williams
Zeke Williams - avatar