Project #17694 - C++

MEDIA INHERITANCE - C++

 

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.

 

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

 

 

2   5-8a. Modify the rectangle class definition from 5-1 so it is the super class.  Add a sub class for a cube and adjust the main to work with the new rectangle super class and cube sub class.  Following is the main class.

Note this could be a rectangular prism, since we have separate values for length, width, and depth.  The perimeter will be the distance around all sides and the area will be the surface area of all sides.

This exercise will be similar to 5-8b shown above.

Modify last week's lab exercise rectangle5-1 class to super class rectangle5-8a.h

Add the new sub class cube5-8a.h that will inherit from rectangle5-8a.  Add the new depth field.  Code the no argument constructor to call the rectangle5-8a constructor, then initializes the new depth field to 1, and gives the new formula for area and perimeter.  Add the new setdepth and getdepth functions.  Override the inherited calcarea and calcperimeter so it uses the new cube formulas.  Submit the cube5-8a.h header file.

Use the following main class for ex5-8a.cpp.  Make sure the functions match the main. 

/* Exercise 5-8a
This program will create a rectangle object
*/
#include<iostream>
#include"cube5-8a.h"
using namespace std;

void main()
{
    rectangle58a r;
    cube58a c;     // run no argument cube constructor
    r.setlength(20);
    r.setwidth(10);
    r.calcarea();
    r.calcperimeter();

    c.setlength(10);
    c.setwidth(5);
    c.setdepth(3);
    c.calcarea();
    c.calcperimeter();

    cout << "\nRectangle's length = " << r.getlength() << endl;
    cout << "Rectangle's width = " << r.getwidth() << endl;
    cout << "Rectangle's area = " << r.getarea() << endl;
    cout << "Rectangle's perimeter = " << r.getperimeter() << endl;

    cout << "\nCube's length = " << c.getlength() << endl;
    cout << "Cube's width = " << c.getwidth() << endl;
    cout << "Cube's depth = " << c.getdepth() << endl;
    cout << "Cube's area = " << c.getarea() << endl;
    cout << "Cube's perimeter = " << c.getperimeter() << endl;
}

 

 

 

3 5-10.    a.    Modify the rectangle class from 5-8b (shown above and attached) so rectangles can be added or subtracted by overloading the + and - operators to mean adding the length and width of both rectangles or subtracting the lengths and widths of the second rectangle from the first rectangle.
    b.    Modify the rectangle class again so rectangles can be compared by overloading the comparison operators (=, !=, <, >) to compare the area of the two rectangles.

Use the following ex5-10.cpp and create the corresponding rectangle5-10.h header file.  Submit the rectangle5-10.h with both parts a and b.

/*Exercise 5-10
This program will create a rectangle object
*/
#include<iostream>
#include"rectangle5-10.h"  // modified rectangle5-8b.h with operators overloaded
using namespace std;

void main()
{
    rectangle510 r1(7, 5), r2(5, 3);  // construct two rectangles 
    float sum, dif;        // use the overload operator + to add length and width from both rectangles ; 
    sum = r1 + r2;      dif = r1 - r2;
    if (r1 > r2)   // use the overload operator > to compare areas
        cout << "r1 has a greater area\n";
    else if (r1 < r2)
        cout << "r1 has a less area\n";
    else if (r1 == r2) 
        cout << "r1 and r2 have the same area\n";
    if (r1 != r2)
        cout << "Not equal\n";
    cout << "Sum of two rectangles is " << sum << endl;
    cout << "Difference of two rectangles is " << dif << endl;
    cout << "Rectangle 1\n";
    r1.print();
    cout << "Rectangle 2\n";
    r2.print();
}

 

Subject Computer
Due By (Pacific Time) 11/24/2013 12:00 am
Report DMCA
TutorRating
pallavi

Chat Now!

out of 1971 reviews
More..
amosmm

Chat Now!

out of 766 reviews
More..
PhyzKyd

Chat Now!

out of 1164 reviews
More..
rajdeep77

Chat Now!

out of 721 reviews
More..
sctys

Chat Now!

out of 1600 reviews
More..
sharadgreen

Chat Now!

out of 770 reviews
More..
topnotcher

Chat Now!

out of 766 reviews
More..
XXXIAO

Chat Now!

out of 680 reviews
More..
All Rights Reserved. Copyright by AceMyHW.com - Copyright Policy