Answer to Question #214393 in C++ for Hemambar

Question #214393

Write a program for a publishing company that markets both printed books and audio visual

lectures stored on CDs. Write a class Publication thatstores title and price. Derive a class book which

has an additional member as no_pages and a class Lecture with member play_time.


1
Expert's answer
2021-07-11T14:38:38-0400
#include <iostream>
#include <string>
using namespace std;
class Publication{
    protected:
    string title = "";
    float price;
    public:
    Publication(){
        get();
    }
    void get(){
        cout<<"\nInput title: ";
        char c = cin.get();
        getline(cin, title);
        if(c != '\n') title = c + title;
        cout<<"Input price: ";
        cin>>price;
    }
};
class Book: public Publication{
    int no_pages;
    public:
    Book():Publication(){
        cout<<"Input number of pages: ";
        cin>>no_pages;
    }
    void show(){
        cout<<"\nType: Book";
        cout<<"\nTitle: "<<title;
        cout<<"\nPrice: "<<price;
        cout<<"\nNumber of pages: "<<no_pages<<endl;
    }
};
class Lecture:public Publication{
    float play_time;
    public:
    Lecture():Publication(){
        cout<<"Input play time in mimutes: ";
        cin>>play_time;
    }
    void show(){
        cout<<"\nType: Audio visual lecture CD";
        cout<<"\nTitle: "<<title;
        cout<<"\nPrice: "<<price;
        cout<<"\nPlay time: "<<play_time<<endl;
    }
};
int main(){
    Book book;
    Lecture audio_cd;
    book.show();
    audio_cd.show();
    return 0;
}

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
APPROVED BY CLIENTS