Abstract Class

#include
#include
#include
#include

class Shape{
 public:
  virtual void draw(){cout<<"Hello";}//a pure virtual function
};  // an abstract class
class Circle : public Shape{
 int x, y, r;
 public:
 Circle(int x, int y, int r){
   this->x=x; this->y=y; this->r=r;  }
   void draw(){
    circle(x, y, r);
  }
};
class Color:public Shape{
 int c;
 public:
   Color(int c){ this->c = c;  }
   void draw(){
    setcolor(c);
   }
};
void main(){
  int gd=DETECT, gm;
  initgraph(&gd, &gm,"c:\\turboc3\\bgi");
  Shape *sp;
  do{
   if(kbhit())
    if(getch()==27) break;
   sp=new Color(random(16));
   sp->draw();
   delete sp;
   sp= new Circle(random(600), random(480), random(300));
   sp->draw();
   delete sp;
  } while(1);
}

1 comment:

Anonymous said...

the program must include
iostream.h
conio.h
graphics.h
stdlib.h