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.
#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
Comments
Leave a comment