+ 1

Inheritance C++ | I need assistance!

Question: "You are making a drawing application. The code you are given declares a Shape base class, and you are making separate classes for each shape that your application is going to support. Inherit the Rectangle class from the Shape class and call its draw() method." Here Is what I have acording to the solution it shows, after many attempts at solving it myself: #include <iostream> using namespace std; class Shape { public: void draw() { cout << "Drawing..."; } }; //inherit from Shape class Rectangle : shape { private: int width; int height; public: Rectangle(int w, int h): width(w), height(h) { cout <<w<<"x"<<h<<endl; }; }; int main() { int x, y; cin>>x>>y; Rectangle d(x, y); //call the draw() method Shape sh ; sh.draw(); } Please if someone can show me what it wrong that would be great!

23rd Jun 2022, 2:14 PM
Stella
Stella - avatar
2 Réponses
+ 3
shape not exist Shape exist in inheritance Mis Spelled
23rd Jun 2022, 2:26 PM
Jayakrishna 🇮🇳
+ 1
#include <iostream> using namespace std; class Shape { public: void draw() { cout << "Drawing..."; } }; //inherit from Shape class Rectangle : Shape { private: int width; int height; public: Rectangle(int w, int h): width(w), height(h) { cout <<w<<"x"<<h<<endl; }; }; int main() { int x, y; cin>>x>>y; Rectangle d(x, y); Shape sh; sh.draw(); } //this is the correct answer
26th Apr 2023, 9:35 AM
palash sanghvi
palash sanghvi - avatar