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(){
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;
}
Comments
Leave a comment