In: Computer Science
C++ language
Using classes (OOD), design a system that will support lending various types of media starting with books. Program should be able to handle a maximum of 500 books. Program should meet at least the following requirements:
1. Define a base media class with a book class derived from it. (Specific class names determined by programmer.)
2. The classes should contain at least the following information: title, up to four authors, ISBN.
3. Define a collection class that will hold up to 500 books.
4. The program should be able to perform the following operations supported by the class definitions:
a) Load data from a drive
b)Sort and display the books by title
c)Sort and display the books by author
d)Add and remove books
Programming requirements: Must include examples of inheritance and composition
~~~Function/Class comments (Description, pre and post conditions)
~~~Internal comments for all functions
#include <iostream>
#include <cstring>
using namespace std;
class media
{
protected:
character title[50];
float ISBN;
public:
media( char * s, float a)
{
Strcpy(title, s);
ISBN = a;
}
Virtual void display() {}
};
class book: public media
{
int pages;
public:
book ( char * s, float a, int p) : media(s,a)
{
pages = p;
}
void display();
};
class dvd: public media
{
Float time;
public:
dvd ( char * s, float a, float t) : media(s,a)
{
time = t;
}
void display();
};
Void book :: display()
{
cout << “\n Title: “ << title;
cout << “\n Pages: “ << pages;
cout << “\n ISBN: “ << ISBN;
}
Void dvd :: display()
{
cout << “\n Title: “ << title;
cout << “\n Play time: “ << time;
cout << “\n Price: “ << price;
}
// Main function for the program
int main( )
{
Char * title = new char[30] ;
Float price, time;
Int pages;
//Book Details
cout << “\n Enter book details\n”;
cout << “ Title: “; cin>> title;
cout << “\n ISBN: “ <; cin>> ISBN;
cout << “\n Pages: “; cin>> pages;
book book1 (title, ISBN, pages);
//Dvd Details
cout << “\n Enter dvd details\n”;
cout << “ Title: “; cin>> title;
cout << “\n Play time: “; cin>> time;
cout << “\n Price: “ <; cin>> price;
tape tape1 (title, price, time);
media * list[2];
list[0] = &book1;
list[1] = &dvd1;
cout << “\n BOOK”;
list[0] -> display();
cout << “\n Dvd”;
list[1] -> display();
return 0;
}