Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Help Needed for C++ (it has to be all in diffrent files) You will create an inhe

ID: 3822899 • Letter: H

Question

Help Needed for C++ (it has to be all in diffrent files)

You will create an inheritance set of classes. Use proper rules for data types, class definitions, and inheritance (check input/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 create a main class that will declare an array of three super media pointers (so you can combine movies and books together in the array). Then using a loop, prompt and input all the data fields (asking the user what kind of media for what added data to input). At the end of the loop, construct the next (proper type) object and assign it into the array. Put a blank line between prompts for the input objects.

When the input loop is over, call a function in the main program that will selection sort the array of media pointers. Use the overloaded < operator to perform the sort on the name field of the calling object.

In a separate loop, call the print function (with dynamic binding!). Put a blank line between output objects.

Run your program with the data below and create the output as shown below. 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.

MEDIA INHERITANCE - DATA

Input:

Enter name: Planet of the Apes

Enter price: 8.90

Is media a book(b) or movie(m): m

Enter rating: G

Enter name: Back to the Future

Enter price: 13.90

Is media a book(b) or movie(m): m

Enter rating: PG

i have a code and there is lots of error please help me with this i am including all the files i have

#ifndef Media_h
#define Media_h
#include
#include
#include
using namespace std;
class Media
{
public:
Media(string n, double h)
{
name = n;
price = h;
}
void seName(string w)
{
name = w;
}
  
void setPrice(double h)
{
price = h;
}
  
virtual void print()
{
cout << "name:" << name << endl;
cout << "price:" << price << endl;
}
  
  
bool operator<(const Media m)
{
// Meida box;
if (name < m.name)

return true;
else return false;

//e(this->name);
}
  
protected:
string name;
double price;
};
#endif

_____________________________________________________________________

#include
#include
#include
//#include<"MEDIA.h">
using namespace std;

// Base class
/*class Media
{
public:
Media(string n, double h)
{
name = n;
price = h;
}
void seName(string w)
{
name = w;
}
  
void setPrice(double h)
{
price = h;
}
  
virtual void print()
{
cout << "name:" << name << endl;
cout << "price:" << price << endl;
}
  
  
int operator<(const Media& m)
{
// Meida box;
return m.name.compare(this->name);
}
  
protected:
string name;
double price;
};*/

// Derived class

class Movie : public Media
{
public:
Movie(string n, double p, string r): Media(n,p)
{
// super(n,h);
rating = r;
}
void setRating(string r)
{
rating = r;
}
string getRating() {
return rating;
}
  
virtual void print()
{
cout << "It is a movie" << endl;
Media::print();
cout << "rating:" << rating< }
private:
string rating;
};

// Derived class
class Book: public Media
{
public:
Book(string n, double p,string a): Media(n,p)
{
author = a;
}
void setAuthor(string a)
{
author = a;
}
string getAuthor()
{
return author;
}
void print()
{
cout << "It is a Book" << endl;
Media::print();
cout << "Author:" << author< }
private:
string author;
};

_______________________________________________________________________________________________

#include
#include
#include
#include"MEDIA.h"
#include"Mediasub.h"

using namespace std;

void selectsort(Media* str[], int N); //prototype
int main(void)
{
  
Media* a[3];

cout << "Input: " <

for(int i=0;i<3;i++)
{
string name;
cout << "Enter name : ";
cin >> name;
// cout << endl;
double price;
cout << "Enter price: ";
cin >> price;

cout << "Is media a book(b) or a movie(m):";
char c;
cin >> c;
if(c=='b')
{
string author;
cout << "Enter author name:";
cin >> author;
a[i] = new Book(name,price,author);
}
else if(c=='m')
{
string rating;
cout << "Enter rating of the movie:";
cin >> rating;
a[i] = new Movie(name,price,rating);
}
else{
cout << "Invalid Input";
}
cout <   
}
selectsort(a, 3);
for(int i=0;i<3;i++)
{
a[i]->print();   
cout < }
return 0;
}

void selectsort(Media* str[], int N)
{
int pass, j, min;
Media* temp;
for (pass = 0; pass <= N - 2; pass++) // passes
{
min = pass;
for (j = pass + 1; j < N; j++) // in each pass
if ( *str[j] < *str[min])
min = j;
   (temp = str[min]);
(str[min] = str[pass]);
   (str[pass] = temp);
   }
}
_________________________________________________________________

// Derived class
#include
#include
#include
//#include<"MEDIA.h">
using namespace std;

class Movie : public Media
{
public:
Movie(string n, double p, string r): Media(n,p)
{
// super(n,h);
rating = r;
}
void setRating(string r)
{
rating = r;
}
string getRating()
{
return rating;
}
  
void print()
{
cout << "It is a movie" << endl;
Media::print();
cout << "rating:" << rating< }
private:
string rating;
};___________________________________________________________________________________________

#include
#include
#include
//#include<"MEDIA.h">
using namespace std;
// Derived class
class Book: public Media
{
public:
Book(string n, double p,string a): Media(n,p)
{
author = a;
}
void setAuthor(string a)
{
author = a;
}
string getAuthor()
{
return author;
}
void print()
{
cout << "It is a Book" << endl;
Media::print();
cout << "Author:" << author< }
private:
string author;
};

Explanation / Answer

#ifndef Media_h
#define Media_h
#include <iostream>
using namespace std;
class Media
{
  
public:
Media(string n, double h)
{
name = n;
price = h;
}
  
void seName(string w)
{
name = w;
}
  
void setPrice(double h)
{
price = h;
}
  
//adding the getter and setter since the member varaibales are delcared protected so we can't access them directly using objects.
string getName()
{
return name;
}
  
virtual void print()
{
cout << "name:" << name << endl;
cout << "price:" << price << endl;
}
  
  
bool operator<(const Media m)
{
// Meida box;
if (name < m.getName())
return true;
else
return false;
//e(this->name);
}
  
protected:
string name;
double price;
};
#endif
//_____________________________________________________________________
ifndef _MEDIA_SUB_H
#define _MEDIA_SUB_H
#include <iostream>
#include "MEDIA.h"
using namespace std;
// Base class
/*class Media
{
public:
Media(string n, double h)
{
name = n;
price = h;
}
void seName(string w)
{
name = w;
}
  
void setPrice(double h)
{
price = h;
}
  
virtual void print()
{
cout << "name:" << name << endl;
cout << "price:" << price << endl;
}
  
  
int operator<(const Media& m)
{
// Meida box;
return m.name.compare(this->name);
}
  
protected:
string name;
double price;
};*/
// Derived class
class Movie : public Media
{
public:
Movie(string n, double p, string r): Media(n,p)
{
// super(n,h);
rating = r;
}
void setRating(string r)
{
rating = r;
}
string getRating() {
return rating;
}
  
virtual void print()
{
cout << "It is a movie" << endl;
Media::print();
cout << "rating:" << rating << " ";
}
private:
string rating;
};
// Derived class
class Book: public Media
{
public:
Book(string n, double p,string a): Media(n,p)
{
author = a;
}
void setAuthor(string a)
{
author = a;
}
string getAuthor()
{
return author;
}
void print()
{
cout << "It is a Book" << endl;
Media::print();
cout << "Author:" << author << " ";
}
private:
string author;
};
#endif
//_______________________________________________________________________________________________
#include <iostream>
#include "MEDIA.h"
#include "Mediasub.h"
using namespace std;
void selectsort(Media* str[], int N); //prototype
int main(void)
{
  
Media* a[3];
cout << "Input: " <
for(int i=0;i<3;i++)
{
string name;
cout << "Enter name : ";
cin >> name;
// cout << endl;
double price;
cout << "Enter price: ";
cin >> price;
cout << "Is media a book(b) or a movie(m):";
char c;
cin >> c;
if(c=='b')
{
string author;
cout << "Enter author name:";
cin >> author;
a[i] = new Book(name,price,author);
}
else if(c=='m')
{
string rating;
cout << "Enter rating of the movie:";
cin >> rating;
a[i] = new Movie(name,price,rating);
}
else{
cout << "Invalid Input";
}
cout <   
}
selectsort(a, 3);
for(int i=0;i<3;i++)
{
a[i]->print();   
cout << " ";
}
return 0;
}
void selectsort(Media* str[], int N)
{
int pass, j, min;
Media* temp;
for (pass = 0; pass <= N - 2; pass++) // passes
{
min = pass;
for (j = pass + 1; j < N; j++) // in each pass
{
if ( *str[j] < *str[min])
min = j;
(temp = str[min]);
(str[min] = str[pass]);
(str[pass] = temp);
}
}
_________________________________________________________________
// Derived class
#include <iostream>
#include "MEDIA.h"
using namespace std;
class Movie : public Media
{
public:
Movie(string n, double p, string r): Media(n,p)
{
// super(n,h);
rating = r;
}
void setRating(string r)
{
rating = r;
}
string getRating()
{
return rating;
}
  
void print()
{
cout << "It is a movie" << endl;
Media::print();
cout << "rating:" << rating << " ";
}
private:
string rating;
};
//___________________________________________________________________________________________
#include <iostream>
#include "MEDIA.h"
using namespace std;
// Derived class
class Book: public Media
{
public:
Book(string n, double p,string a): Media(n,p)
{
author = a;
}
void setAuthor(string a)
{
author = a;
}
string getAuthor()
{
return author;
}
void print()
{
cout << "It is a Book" << endl;
Media::print();
cout << "Author:" << author;
}
private:
string author;
};