Q.Lally Publication House publishes two types of learning material, viz., books and recorded CDs. Both the books and CDs have ISBN number, Title, Author, Year of publication and Price. In addition to this, books contain the total number of pages and CDs or DVDs contain duration of the video, in minutes. Provide a function to get and print details. Also provide a function: calculate_Price which calculates the price of the books based on the total number of pages, Re 1 per page and the price of CDs/DVDs based on the duration of the CD/DVD, Rs 2 per minute of the duration. Design an OOP model and implement it using C++. (Hierarchical inheritance)
Input Format
Type of learning material (0 for book and 1 for CD/DVD)
ISBN number
Title
Author
Year of publication
Number of pages if book, and the duration in minutes if CD/DVD
Output format
isbn number of book/cd
title of book/cd
price of book/cd
Solution
class CD:public learning_Material
{
public:
int dur;
void get();
void print();
void calc_Price();
};class book:public learning_Material
{
public:
int pages;
void get();
void print();
void calc_Price();
};
void book::calc_Price()
{
price=pages;
}
void CD::calc_Price()
{
price=2*dur;
}
void book::print()
{
cout<<isbn<<endl<<title<<endl<<price; } void learning_Material::get() { cin>>isbn>>title>>author>>year;
}
void book::get()
{
learning_Material::get();
cin>>pages;
}
void CD::get()
{
learning_Material::get();
cin>>dur;
}
void CD::print()
{
cout<<isbn<<endl<<title<<endl<<price;
}