Answer to Question #192962 in C++ for Steve

Question #192962

Consider a publishing company that markets book . Create a base class Publication that stores the title (a string), number of copies sold and price(type float) of a publication. Class Book which adds a page_count(int) is derived from the class Publication. Each class should have get_data() function to get its data from the user at the keyboard. Write the main() function to test the Book and publication classes by creating instances of them asking the user to fill in data with get_data() and then displaying it using put_data().


1
Expert's answer
2021-05-13T09:56:19-0400
#include <iostream>
using namespace std;
//define the publication class
class Publication{
    protected:
        string title;
        int num_of_copies;
        float price;
    public:
        //get data from the user
        void get_data()
        {
            cout<<"\nEnter the Title of Publication: ";
            cin>>title;
            cout<<"\nEnter the Number of copies sold: ";
            cin>>num_of_copies;
            cout<<"\nEnter the price: ";
            cin>>price;
        }
        //display the data
        void put_data(){
            cout<<"\nThe title of the publication is "<<title<<endl;
            cout<<"The number of copies sold is "<<num_of_copies<<endl;
            cout<<"The price is "<<price<<endl;
        }
};
//define the book class
class Book:public Publication{
    private:
        int page_count;
    public:
        //get data from the user
        void get_data(){
         cout<<"\nEnter number of pages: ";
         cin>>page_count;
        }
        //display the data
        void put_data(){
        cout<<"The number of pages is "<<page_count<<endl;
        }
};
int main(){
    Publication pub;
    Book b;
    pub.get_data();
    b.get_data();
    pub.put_data();
    b.put_data();
    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