Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

C++ program Correctly complete the following assignment. Follow all directions. The main purpose is to show super and sub class relationships with an array of

C++ program

Correctly complete the following assignment. Follow all directions. 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. The selection sort method will be in the main .cpp file because it will sort the array created in main. The final .cpp file, the three .h header class files, and a separate output .txt text file (copied and pasted from the console screen) should be submitted.

The selection sort function for an array of cstrings from chapter 3 notes is also attached with some hints on how to adjust that function to a selection sort function for an array of super media pointers.

Hint: Good Guides: 5-12b inheritance with super pointer array including virtual function, 5-10 operator overload, attached selection sort function.

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. 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.

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

Enter name: Intensity

Enter price: 7.90

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

Enter author: Dean Koontz

Output:

Movie

Name is Back to the Future

Price is 13.90

Rating is PG

Book

Name is Intensity

Price is 7.90

Author is Dean Koontz

Movie

Name is Planet of the Apes

Price is 8.90

Rating is G

SORT.docx

The code for selection sort (for an array of cstrings) is:

void selectsort(char str[][20], int N)

{

int pass, j, min;

char temp[20];

for (pass = 0; pass <= N - 2; pass++) // passes

{

min = pass;

for (j = pass + 1; j < N; j++) // in each pass

if (strcmp(str[min], str[j]) > 0)

min = j;

strcpy(temp, str[min]);

strcpy(str[min], str[pass]);

strcpy(str[pass], temp);

}

}

The 2-D character array becomes a super media pointer array. Change > to <, remove strcmp and directly use < overloaded operator. Change strcpy to directly use = assignment operator. Compare the media object the array element is pointing at. Swap the contents of the array element, which is the address of the media object.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Microsoft Visual Basic 2017 For Windows Web And Database Applications

Authors: Corinne Hoisington

1st Edition

1337102113, 978-1337102117

More Books

Students also viewed these Databases questions

Question

Differentiate between hard and soft measures of service quality.

Answered: 1 week ago

Question

Be familiar with the different perspectives of service quality.

Answered: 1 week ago

Question

Describe key customer feedback collection tools.

Answered: 1 week ago