A publication company that markets both book and audio-cassettes. Create a class “publication” that stores the title and price. From this class derive two classes “book” which adds a page count and “tape” which adds a playing time in minutes. Each of the three classes should have a getdata( ) and putdata( ) function. Write a main function to test the book and tape classes by creating instances of them, and fill their data with getdata( ), and then displaying the data with putdata( )

#include<iostream.h>
#include<conio.h>
#include<stdio.h>
class publication
{
      char title[30];
      float price;
   public:
      void getdata(){cout<<endl<<"Enter Title : ";gets(title);
       cout<<"Enter Price : ";cin>>price;}
      void putdata(){cout<<endl<<"      Title : "<<title
    <<endl<<"      Price : "<<price;}
};
class book:public publication
{
      int pagecount;
      publication p;
   public:
      void getdata(){p.getdata();cout<<"Enter Pages : ";cin>>pagecount;}
      void putdata(){p.putdata();cout<<endl<<"No of Pages : "<<pagecount;}
};
class tape:public publication
{
      float p_time;
      publication p;
   public:
      void getdata(){p.getdata();cout<<" Enter Time : ";cin>>p_time;}
      void putdata(){p.putdata();cout<<endl<<"  Play Time : "<<p_time;}
};
void main()
{
   book B;
   tape T;
   clrscr();
   cout<<endl<<"Enter Details of Book";
   cout<<endl<<"---------------------";
   B.getdata();
   cout<<endl<<"Enter Details of Tape";
   cout<<endl<<"---------------------";
   T.getdata();
   cout<<endl<<"Book Details";
   cout<<endl<<"------------";
   B.putdata();
   cout<<endl<<"==================================";
   cout<<endl<<"Tape Details";
   cout<<endl<<"------------";
   T.putdata();
   cout<<endl<<"==================================";
   getch();
}

No comments:

Post a comment