c++ record- 11)C++ Run time Polymorphism Example: By using two derived class note:- 2nd year b.com 3sem record

 

  1. #include <iostream>    
  2. using namespace std;    
  3. class Shape {                                        //  base class  
  4.     public:    
  5. virtual void draw(){                             // virtual function  
  6. cout<<"drawing..."<<endl;      
  7.     }        
  8. };     
  9. class Rectangle: public Shape                  //  inheriting Shape class.  
  10. {      
  11.  public:    
  12.  void draw()      
  13.    {      
  14.        cout<<"drawing rectangle..."<<endl;      
  15.     }      
  16. };    
  17. class Circle: public Shape                        //  inheriting Shape class.  
  18.   
  19. {      
  20.  public:    
  21.  void draw()      
  22.    {      
  23.       cout<<"drawing circle..."<<endl;      
  24.    }      
  25. };    
  26. int main(void) {    
  27.     Shape *s;                               //  base class pointer.  
  28.     Shape sh;                               // base class object.  
  29.        Rectangle rec;    
  30.         Circle cir;    
  31.       s=&sh;    
  32.      s->draw();     
  33.         s=&rec;    
  34.      s->draw();      
  35.     s=?    
  36.     s->draw();     
  37. }    




Comments

Popular posts from this blog

digital marketing ppt-u1

SOFTWARE

cn lab

Computer Operations and Performing - D L Unit-1-1

DS-Record-mca-04) write a program for evaluating a given postfix expression using stack.

DBMS Degree Lab Records

Unit 2: Foundations of Ownership, Security Related Concepts in Blockchain

Unit-1 Foundations of Software Systems and Blockchain

Access the Internet to Browse Infromation & E-Mail Operation- D L Unit-2-1

6)what are the various service of internet and protocols ICT-unit-1