A publishing company markets both books and audiocassette versions of its works.Â
Create a class called publication that stores the title (a string) and price (type float) ofÂ
a publication. From this class derive two classes: book, which adds a page count (typeÂ
int); and tape, which adds a playing time in minutes (type float). Each of the threeÂ
class should have a getdata() function to get its data from the user, and a putdata()
function to display data. Also include two constants publisher name (a string) andÂ
address (type int) in the class publication.
Write a main() program that creates an array of pointers to publication. In a loop askÂ
the user for data about a particular book or tape, and use new to create an object ofÂ
type book or tape to hold the data. Put the pointer to the object in the array. When theÂ
user has finished entering the data for all books and tapes, display the resulting data forÂ
all books and tapes entered using a loop
#include<iostream>
using namespace std;
class publication
{Â
  protected:
        string title;
        float price;
       const string pName;
       const int pAddress;
 Â
  public:
      void getData()
      {
        cout<<"\nEnter Title of the Publication :";
        cin>>title;
        cout<<"\nEnter the price of Publication :";
        cin>>price;
      }
      void putData()
      {
        cout<<"Title :"<<title<<endl;
        cout<<"Price :"<<price<<endl;
      } Â
};
class book :public publicationÂ
{
  int page_count;
  Â
  public :
        void getData()
         {
           cout<<"\nEnter the page count of Book :";
           cin>> page_count;
         }
         void putData()
         {
           cout<<"Page count of Book is :"<< page_count<<endl;
         }
};
class tape :public publication
{
  float ptime;
   Â
  public :
        void getData()
        {
          cout<<"\nEnter playing time in minutes :";
          cin>>ptime;
        }
        void putData()
        {
          cout<<"Playing time in minutes :"<<ptime<<endl;
        }
};
int main()
{
  publication *ptr;
  //publication p ;
  ptr->getData();
  ptr->putData();
  Â
  book *b;
  ptr=b ;
  ptr->getData();
  ptr->putData();
  Â
  tape *t;
  ptr=t ;
  ptr->getData();
  ptr->putData();
  Â
}
Comments
Leave a comment