Question
C++ You will create an inheritance set of classes. The main purpose is to show super and sub class relationships with an array of super
C++
You will create an inheritance set of classes. The main purpose is to show super and sub class relationships with an array of super media pointers to sub class objects and dynamic binding. The < operator will be overloaded in the super class so all subclasses can use it. Use proper rules for data types, class definitions, and inheritance (check output of data below).
You will create a super media class that will define a general form of media. A media properties will consist of the name and price. The media should be able to construct itself out of the arguments sent to it, virtually print both data fields labeled (price to two decimal places) and overload the < operator to compare two medias by comparing their name field.
You will then create two subclasses of media for a movie and a book. A movie "is a" media, but also has a rating. It also should construct itself by initializing all data fields, but use the super media constructor to initialize the inherited data fields. It will also override the media print function. In the new version, it should print that it is a movie, then call the super print function to print the name and price, then print the new labeled rating data field itself.
A book "is a" media, but also has an author and will be set up similar to a movie. It also should override the media print function. In the new version, it should print that it is a book, then call the super print function to print the name and price, then print the new labeled author data field itself.
You will then use the given main class that will declare an array of three super media pointers (so you can combine movies and books together in the array). You must use the given main, so make sure the classes match up. You will add a selection sort function to main that uses your overloaded < operator.
Run your program and create the output as shown below. Submit your three class definitions, main program, and output text file. Document all files with at least 4 lines of comments at the top and at least 5 comments throughout the code for all of the not easily understandable lines of code.
Provided main .cpp file:
This program will create an array of media pointers
*/
#include
#include"media.h"
#include"movie.h"
#include"book.h"
using namespace std;
void sort (media *mm[], int N); // selection sort array of media pointers of size N
void main()
{
media *m[3]; // array of three super media pointers
int j;
string name, rating, author;
float price;
name = "Planet of the Apes";
price = 8.90;
rating = "G";
m[0] = new movie(name, price, rating);
// address of sub object assigned into pointer element of array
name = "Back to the Future";
price = 13.90;
rating = "PG";
m[1] = new movie(name, price, rating);
name = "Intensity";
price = 7.90;
author = "Dean Koontz";
m[2] = new book(name, price, author);
sort (m, 3); // selection sort array of media pointers of size N
for (j = 0; j < 3; j++)
{
m[j]->print(); // dynamic binding
cout << endl;
}
}
void sort (media *mm[], int N) // build sort funciton
{
}
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started