Answer to Question #213309 in C++ for Hemambar

Question #213309

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-08-01T00:29:12-0400
#include <iostream>
#include <iomanip>
#include <string>
using namespace std;


class Publication {
public:
    Publication(string title, double price)  :
        title(title), price(price) {}
    virtual void Display();


private:
    string title;
    double price;
};


void Publication::Display() {
    cout << "Title: " << title <<endl;
    cout << "Price: $" << fixed << setprecision(2) << price << endl;
}


class Book : public Publication {
public: 
    Book(string title, double price, int no_page) :
        Publication(title, price), no_page(no_page) {}
    virtual void Display();


private:
    int no_page;
};


void Book::Display() {
    Publication::Display();
    cout << "Pages: " << no_page << endl;
}

class Lecture : public Publication {
public:
    Lecture(string title, double price, int play_time) :
        Publication(title, price), play_time(play_time) {}
    virtual void Display();

private:
    int play_time;
};

void Lecture::Display() {
    Publication::Display();
    cout << "Time:  " << play_time/60 << ":" << setw(2) << setfill('0') 
         << play_time%60 << endl;
}

int main() {
    Publication* store[2];

    store[0] = new Book("Head First C", 40.59, 632);
    store[1] = new Lecture("Modern C++ Course", 20.99, 245);

    store[0]->Display();
    cout << endl;
    store[1]->Display();

}

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