/* Run time polymorhism */
# include<iostream.h>
# include<conio.h>
# include<stdio.h>
# include<string.h>
class publication
{
private:
char title[50];
float price;
public:
virtual void getdata()
{
cout<<"\n Enter title: ";
cin>>title;
cout<<"\n Enter price: ";
cin>>price;
}
virtual void putdata()
{
cout<<"\n\nTitle: "<<title;
cout<<"\nPrice: "<<price;
}
};
class book : public publication
{
private:
int pages;
public:
void getdata()
{
publication::getdata();
cout<<"\n Enter number of pages: ";
cin>>pages;
}
void putdata()
{
publication::putdata();
cout<<"\nPages: "<<pages;
}
};
class tape : public publication
{
private:
float time;
public:
void getdata()
{
publication::getdata();
cout<<"\n Enter playing time: ";
cin>>time;
}
void putdata()
{
publication::putdata();
cout<<"\nPlaying time: "<<time;
}
};
int main()
{
publication* arr[100]; //array pointers to publication
int n=0; //number of publication in array
char choice; //user's choice
clrscr();
do
{
cout<<"\n Enter data for book or tape (b/t)? ";
cin>>choice;
if(choice=='b') //make a book object
arr[n]= new book; //put in array
else //make a tape object
arr[n]= new tape; //put in array
arr[n++]->getdata(); //get data for object
cout<<" \n Enter another publication (y/n)? ";
cin>>choice;
}while(choice=='y');
for(int j=0;j<n;j++)
arr[j]->putdata();
cout<<endl;
return 0;
getch();
}