Answer to Question #201302 in C++ for Harsh

Question #201302

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


1
Expert's answer
2021-06-01T00:05:22-0400
#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();
    
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog