#include <iostream>

#include<cstring>

using namespace std;

class Media

{

    protected: 

    char name[40];

    float price;

    public:

    Media(char *nm,float b)

    {

        strcpy(name,nm);

        price=b;

    }

    virtual void display()

    {}

};

class Book:public Media

{

 int pages;

 public:

 Book(char *nm, float b, int pg): Media(nm,b)

 {

     pages=pg;

 }

void display()

{

    cout<<"\n Title: " << name;

    cout<<"\n Pages: " << pages;

    cout<<"\n Price: " << price;

}

};

class Tape:public Media

{

 float time;

 public:

 Tape(char *nm, float b, float tm): Media(nm,b)

 {

     time=tm;

 }

void display()

{

    cout<<"\n Title: " << name;

    cout<<"\n Play time: " << time <<" mins";

    cout<<"\n Price: " << price;

}

    

};


int main()

{

    cout<<"Virtual function based program";

 char *title=new char[30];

 float price,time;

 int pages;

 // Book details

 cout<<"\n Enter Book details\n";

 cout<<" Title: "; cin>>title;

 cout<<" Price: "; cin>>price;

 cout<<" Pages: "; cin>>pages;

  Book book1(title,price,pages);

 

 // Tape details

 cout<<"\n Enter Tape details\n";

 cout<<" Title: "; cin>>title;

 cout<<" Price: "; cin>>price;

 cout<<" Play time (mins) : "; cin>>time;

  Tape tape1(title,price,time);

 

Media *ls[2];

 ls[0]=&book1;

 ls[1]=&tape1;

 cout<<"\n Media details ";

 cout<<"\n ..........Book........";

 ls[0]-> display();

 cout<<"\n ..........Tape........";

 ls[1]-> display();

 

    return 0;

}

output:
Virtual function based program
 Enter Book details
 Title: OOP
 Price: 250
 Pages: 650
 Enter Tape details
 Title: C++_Concpets
 Price: 100
 Play time (mins) : 45
 Media details 
 ..........Book........
 Title: OOP
 Pages: 650
 Price: 250
 ..........Tape........
 Title: C++_Concpets
 Play time: 45 mins
 Price: 100