Answer to Question #213287 in C++ for Hemambar

Question #213287

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-31T07:16:23-0400
#include <iostream>
#include <string>
using namespace std;
class Publication{
protected:
    string title;
    float price;
public:
    Publication(){
        getDetails();
    }
    void getDetails(){
        cout<<"\nEnter title: ";
        cin>>title;
        cout<<"Enter price: ";
        cin>>price;
    }
};
class Book: public Publication{
    int no_pages;
public:
    Book():Publication(){
        cout<<"Enter number of pages: ";
        cin>>no_pages;
    }
    void view(){
        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<<"Enter play_time: ";
        cin>>play_time;
    }
    void view(){
        cout<<"\nType: Lecture";
        cout<<"\nTitle: "<<title;
        cout<<"\nPrice: "<<price;
        cout<<"\nPlay time: "<<play_time<<endl;
    }
};
int main(){
    Book book;
    Lecture cd;
    book.view();
    cd.view();
    return 0;
}

Example:

Enter title: Harry
Enter price: 14
Enter number of pages: 216


Enter title: Homosapiens
Enter price: 50
Enter play_time: 20


Type: Book
Title: Harry
Price: 14
Number of pages: 216


Type: Lecture
Title: Homosapiens
Price: 50
Play time: 20

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