Starting from:
$26.99

$20.99

Programming Assignment 1 Solution

This program lists movie data from a .csv file, allows for a search by name

                                Other files required:

                                                1.            Movies.csv         –   text file of integers

                                                2.            list.h      –    class template declaration & implementation

 

 

/* TODO

You will need to write the addInventory function in the movieStore program that accepts a List object and a double that is the percentage increase to the total number of movies.

 

The function processes all elements in the List object calculating the increased number of movies to be the sum of the number of movies checked in plus the sum of the movies checked out multiplied by the percentage passed into the function.

 

Truncate the result of this calculation.

 

Then that increased amount is add to the number of movies checked in.

 

In order to update each of this element of the List, you need modify the template to include a setItem function that sets the associated element in the List object to the item that is passed to the setItem function.

 

HINT:  This function should only contain one C++ statement.

 

Output to look like this:

 

---------------------------------------------------------------------------

The following data is the updated Webster Movies store

The Webster Movie Store list includes:

MPAC    Title                   Year    RunTime  In      Out

------------------------------------------------------------

1101    Casablanca              1942     102      7        6

1200    Duck Soup               1933      68      9        3

5570    From Here to Eternity   1953     118     11        3

6601    Wizard of Oz            1939     101      5       10

1301    Citizen Kane            1941     119      7        2

1350    Animal House            1978     109      4       12

5102    Young Frankenstein      1973     106      1       15

5234    King Kong               1933     100      4        9

1405    My Favorite Brunette    1947      87      5        7

2200    Gone with the Wind      1939     226      5       10

3103    White Christmas         1954     120     13        1

3670    It's a Wonderful Life   1946     130     12        2

2345    Public Enemy            1931      84      7        4

2870    Jazz Singer             1927      88     10        3

4490    Doctor Zhivago          1965     200      9        5

4876    Sound of Music          1965     174      8        7

8330    Topper                  1937      98      4        8

9400    Caine Mutiny            1954     125      9        4

7109    Sergeant York           1941     134      7        6

7405    It Happened One Night   1934     105      5        8

The average run time for the 20 movies is 119.7

There are 142 movies checked in

There are 125 movies checked out

Press any key to continue . . .

 

*/

 

 

#include <iostream

#include <iomanip

#include<string

#include <fstream

#include "List.h"

using namespace std;

 

struct Movie

{

                int mpac, year, runtime, checkedIn, checkedOut;

                string title;

                Movie() { mpac = 0; year = 0; runtime = 0; checkedIn = 0; checkedOut = 0; title = "Unassigned"; }

                bool operator==(const Movie& s)

                {

                                if (mpac == s.mpac)return true;return false;

                }

};

 

void getData(List<Movie&);

void displayList(List<Movie&);

void avgTime(List<Movie&);

void checkedIn(List<Movie&);

void checkedOut(List<Movie&);

void displayMovie(List<Movie&);

 

int main()

{

                List<Movie ListMovies(100);

                getData(ListMovies);

                displayList(ListMovies);

                avgTime(ListMovies);

                checkedIn(ListMovies);

                checkedOut(ListMovies);

                cout << endl;

                displayMovie(ListMovies);

                addInventory(WebsterMovies, 10.5);

                cout << "The following data is the updated Webster Movies store\n";

                displayList(WebsterMovies);

 

                return 0;

}

 

void getData(List<Movie& cls)

{

                Movie movie;

                ifstream inFile("Movies.csv");

                if (!inFile)

                {

                                cout << "Problem opening Movies.csv file" << endl;

                                exit(99);

                }

 

                // integer mpac, year, runtime, checkedIn, checkedOut, and a string title 

                inFile movie.mpac;

                inFile.ignore();

                inFile movie.year;

                inFile.ignore();

                inFile movie.runtime;

                inFile.ignore();

                inFile movie.checkedIn;

                inFile.ignore();

                inFile movie.checkedOut;

                inFile.ignore();

                getline(inFile, movie.title);

 

                while (!inFile.eof())

                {

                                cls.addMember(movie);

                                inFile movie.mpac;

                                inFile.ignore();

                                if (movie.mpac != 0)

                                {

                                                inFile movie.year;

                                                inFile.ignore();

                                                inFile movie.runtime;

                                                inFile.ignore();

                                                inFile movie.checkedIn;

                                                inFile.ignore();

                                                inFile movie.checkedOut;

                                                inFile.ignore();

                                                getline(inFile, movie.title);

 

                                }

                }

}

 

void displayList(List<Movie& p)

{

                cout << "The Webster Movie Store list includes:" << endl;

                cout << "------------------------------------------------------------" << endl;

                cout << "MPAC" << '\t' << setw(20) << left << "Title" << '\t'

                                << setw(4) << right << fixed << setprecision(1) << "Year" << '\t'

                                << setw(4) << right << fixed << setprecision(1) << "Runtime" << '\t'

                                << setw(4) << right << fixed << setprecision(1) << "In" << '\t'

                                << setw(4) << right << fixed << setprecision(1) << "Out" << '\t'

 

                                << endl;

                Movie movie;

                for (int i = 0; i < p.getNumber();i++)

                {

                                movie = p.getNext();

                                cout << movie.mpac << '\t' << setw(20) << left << movie.title << '\t'

                                                << setw(4) << right << fixed << setprecision(1) << movie.year << '\t'

                                                << setw(4) << right << fixed << setprecision(1) << movie.runtime << '\t'

                                                << setw(4) << right << fixed << setprecision(1) << movie.checkedIn << '\t'

                                                << setw(4) << right << fixed << setprecision(1) << movie.checkedOut << '\t'

                                                << endl;

                }

}

 

void avgTime(List<Movie& p)

{

                Movie movie;

                double sum = 0, i = 0;

                for (i = 0; i < p.getNumber(); i++)

                {

                                movie = p.getNext();

                                sum += movie.runtime;

                }

                double avg = sum / i;

 

                cout << "The average runtime for the " << static_cast<int(i) << " movies is: " << avg << " minutes." << endl;

 

}

 

void checkedIn(List<Movie& p)

{

                Movie movie;

                int sum = 0;

                for (int i = 0;i < p.getNumber(); i++)

                {

                                movie = p.getNext();

                                sum += movie.checkedIn;

                }

                cout << "There are: " << sum << " movies checked in." << endl;

 

}

 

void checkedOut(List<Movie& p)

{

                Movie movie;

                int sum = 0;

                for (int i = 0;i < p.getNumber(); i++)

                {

                                movie = p.getNext();

                                sum += movie.checkedOut;

                }

                cout << "There are: " << sum << " movies checked out." << endl;

 

}

 

void displayMovie(List<Movie& p)

{

                Movie movie;

                int mpac;

                bool found = false;

                cout << "Enter the MPAC of the movie to display: ";

                cin mpac;

                while (mpac != 0)

                {

                                movie.mpac = mpac;

                                found = p.getMember(movie);

                                if (found)

 

                                                cout << "------------------------------------------------------------\n"

                                                << "MPAC" << '\t' << setw(20) << left << "Title" << '\t'

                                                << setw(4) << right << fixed << setprecision(1) << "Year" << '\t'

                                                << setw(4) << right << fixed << setprecision(1) << "Runtime" << '\t'

                                                << setw(4) << right << fixed << setprecision(1) << "In" << '\t'

                                                << setw(4) << right << fixed << setprecision(1) << "Out\n"

 

                                                << movie.mpac << '\t' << setw(20) << left << movie.title << '\t'

                                                << setw(4) << right << fixed << setprecision(1) << movie.year << '\t'

                                                << setw(4) << right << fixed << setprecision(1) << movie.runtime << '\t'

                                                << setw(4) << right << fixed << setprecision(1) << movie.checkedIn << '\t'

                                                << setw(4) << right << fixed << setprecision(1) << movie.checkedOut << '\t'

                                                << endl;

                                else

                                                cout << mpac << " is not a movie in the store\n";

                                cout << "Enter the MPAC of the movie to display: ";

                                cin mpac;

                }

}

 

 

 

 

More products