Last active
November 18, 2019 01:26
-
-
Save theoctober19th/346e77d700934f0a0334263970562cda to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Create a class shape with a pure virtual member function display (). Derive two classes circle and rectangle. With member function by overriding member function in base class shape to display the name of respective shape. Write main function to create objects of derived classes and call display function. | |
*/ | |
#import <iostream> | |
using namespace std; | |
class Shape{ | |
public: | |
virtual void display() = 0; | |
}; | |
class Circle: public Shape{ | |
public: | |
void display(){ | |
cout << "I am a circle" << endl; | |
} | |
}; | |
class Rectangle: public Shape{ | |
public: | |
void display(){ | |
cout << "I am a Rectangle" << endl; | |
} | |
}; | |
int main(){ | |
Circle c; | |
Rectangle r; | |
c.display(); | |
r.display(); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment