Imagine a publishing company that does marketing for book and audio cassette versions. Create a class publication that stores the name (string) and price (float) of the publication. Two classes are derived from this class: book, which adds the number of pages (type int), and tape, which adds the playback time in minutes (type float). Write a program that instantiates the Book and Tape classes, allows the user to enter data, and displays the data members.

Imagine a publishing company which does marketing for book and audiocassette versions.
Create a class 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).
Write a program that instantiates the book and tape classes, allows user to enter data and
displays the data members.
OUTPUT OF THE PROGRAM

#include<iostream>
using namespace std;

class publication
               char title[10];
               float price;
   
   public:
            void read()
            {
                cout<<"\nEnter Title of the Publication :";
                cin>>title;
                cout<<"\nEnter the price of Publication :";
                cin>>price;
            }
           void show()
            {
                cout<<"Title is :"<<title<<"\n";
                cout<<"Price is :"<<price<<"\n";
            }   
};

class book :public publication 
{
    int page_count;
    
    public :
                void read()
                 {
                     cout<<"\nEnter the page count of Book :";
                     cin>> page_count;
                 }
                 void show()
                 {
                     cout<<"Page count of  Book is :"<< page_count<<"\n";
                 }
};

class tape :public publication
{
    float playing_time;
       
    public :
                void read()
                {
                    cout<<"\nEnter playing time in minutes :";
                    cin>>playing_time;
                }
                void show()
                {
                    cout<<"Playing time in minutes :"<<playing_time<<"\n";
                }
};

int main()
{
    publication *ptr;
    publication  p ;
    p.read();
    p.show();
    
    book b;
    ptr=&b ;
    ptr->read();
    ptr->show();
    
    tape t;
    ptr=&t ;
    ptr->read();
    ptr->show();
    
}

For more such posts click the link:-http://svencrai.com/G8W

2 Comments

  1. Very usefull, go ahed by which we can direct copy paste our Assignments🤞😛

    ReplyDelete
Previous Post Next Post