c++ homework

Option A – 100 points maximum

Modify Assignment 8 (or 7, or 5) to:

  1. Modify the movies class to created a linked list.
    Movies is now the head node pointer.
    Sample code will be provided although you are free to ignore it (zero credit for using an existing collection class, and see the note below).
  2. Load the list by inserting movies in ascending sequence by title.
    Add an overloaded operator< to the Movie class for this.
  3. Retrieve movies by a search key (not the full title; a search key of “or” should not yield any Toy Story movie).
    The key should not be case senstive; ‘xx’ and ‘xX’ should both retrieve ‘XXX’.
  4. If using Assignment 7/5 as the base, delete the options to retrieve movies by movie number and to get the next sequential movie.


It should not abort if the movie is not found.

You are free to create your own linked list solution, but it must incorporate templates, the node as a class, previous and next link pointers, and separate compilation.
Note the key word ‘create’; please do not submit canned linked list solutions copied from elsewhere.

Option B – 125 points maximum

Same as Option A, except

  1. A separate List class should be created, which would contain head and tail (last node) pointers, and all node navigation methods.
    (Node is still a separate class, which should now have all private members, with the list class as a friend.)
  2. Nodes are not referenced outside of the List class; Movies has (or is?) a list object and only references list methods.
  3. The search should start at the end of the list and work backward, returning the last movie in the list containing the search key (which is still the first one found; a search key of “ar” should not yield Avatar).

I Cant Seem to attach the Folder with it on the bottom for some reason. I pasted the homework assignment on the bottom.


Movie.cpp FILE


// Movies.cpp

#include “Movie.h” // include Movie class definition

#include “Movies.h” // include Movies class definition

#include <fstream>

#include <string>

using namespace std;


Movies::Movies(string fn){loadMovies(fn);}


void Movies::MakeTable(int S) {

for (int i = 0; i<S; i++)

movies[i] = NULL;



void Movies::loadMovies(string fn) {


ifstream iS(fn);


string s;

int itemfound;

string SecTitle;

int SecHash;

getline(iS, s); // skip heading

getline(iS, s);


while(!iS.eof()) {


itemfound = s.find_first_of(“t”);

for (int i = 0; i < itemfound; i++)

SecTitle += s[i];

SecHash = runHash(SecTitle);

movies[SecHash] = new Movie(s);


getline(iS, s);





const Movie * Movies::operator [] (int MM) const{

return movies[MM];


int Movies::runHash(string s) {

int hashing = 0;

for (int i = 0; i < s.length(); i++) {

hashing = ((31 * hashing) + s[i]);


int table = abs(hashing);

return table % SizeOfTable;



MovieInforApp.cpp FILE


// MovieInfoApp.cpp


#include “Movie.h” // include Movie class definition

#include “Movies.h” // include Movies class definition

#include <iostream>

#include <iomanip>

#include <string>

using namespace std;


void main() {

double ratioCalc = 0;

int Statement = 2;

Movies movies(“Box Office Mojo.txt”);

string movieCode;



while (Statement != 0) {

cout <<“===========================Welcome To a Movie Search Program=================” <<endl <<endl;

cout << “Enter the Exact Movie Title that you would like to search” <<endl;

cout <<“If you are done searching, Please Press Enter to Exit: ” <<endl;


getline(cin, movieCode);

if(movieCode.length() > 0) {


int hash = Movies::runHash(movieCode);

Movie m = *movies[hash];


if(m.getTitle().length() > 0) {

cout << m.toString() << “n”;

if(m.getWorldBoxOffice() > 0) {

ratioCalc = ((float)m.getNonUSBoxOffice()/(float)m.getWorldBoxOffice())*100;

cout << “The ratio of World Boxx Office to Non-Us Box Office is : ” 

<<std::fixed << std::setprecision(2) << ratioCalc

<< “%” << “nnn”;}


cout << “No ratio due to zero value for World Box Officennn”;}


cout << “”;

Statement = 8;}

else {

cout << “n”;

Statement = 0;





Movie.cpp FILE


// Movie.cpp

#include “Movie.h” // include Movie class definition

#include <string>

#include <sstream>

using namespace std;


Movie::Movie() {

title = studio = “”;

boxOffice[WORLD] = boxOffice[US] = boxOffice[NON_US] = 

rank[WORLD] = rank[US] = rank[NON_US] = releaseYear = 0;



Movie::Movie(string temp) {

istringstream iS(temp);

getline(iS, title, ‘t’);

getline(iS, studio, ‘t’);

iS >> releaseYear >> boxOffice[WORLD] >> boxOffice[US] >> boxOffice[NON_US] >>

rank[WORLD] >> rank[US] >> rank[NON_US];



string Movie::getTitle() {return title;}

string Movie::getStudio() {return studio;}

long long Movie::getWorldBoxOffice() {return boxOffice[WORLD];}

long long Movie::getUSBoxOffice() {return boxOffice[US];}

long long Movie::getNonUSBoxOffice() {return boxOffice[NON_US];}

int Movie::getWorldRank() {return rank[WORLD];}

int Movie::getUSRank() {return rank[US];}

int Movie::getNonUSRank() {return rank[NON_US];}

int Movie::getReleaseYear() {return releaseYear;}


string Movie::toString() {

ostringstream oS;

oS << “nn                 Movie Informationn===================================================”

<< “n             Movie Title:t” << title << ”  (” << releaseYear << “)”

<< “n    US Rank & Box Office:t” << rank[US] << “t$” << boxOffice[US]

<< “nNon-US Rank & Box Office:t” << rank[NON_US] << “t$” << boxOffice[NON_US]

<< “n World Rank & Box Office:t” << rank[WORLD] << “t$” << boxOffice[WORLD]

<< “n”;

return oS.str();



Movies.h FILE


// Movies.h

#ifndef MOVIES_H

#define MOVIES_H

#include “Movie.h” 

#include <string>

using namespace std;


class Movies {

void MakeTable(int);

static const int SizeOfTable = 23298;



const Movie * operator [] (int) const;

static int runHash(string s);


void loadMovies(string);

Movie * movies[SizeOfTable];




Movie.h FILE


// Movie.h

#ifndef MOVIE_H

#define MOVIE_H

#include <string>

using namespace std;


class Movie {


    string title, studio;

long long boxOffice[3]; 

short rank[3], releaseYear; 

enum unit {WORLD, US, NON_US};





  string getTitle();

  string getStudio();

string toString();

    long long getWorldBoxOffice();

    long long getUSBoxOffice();

    long long getNonUSBoxOffice();

    int getWorldRank();

    int getUSRank();

    int getNonUSRank();

    int getReleaseYear();





I can email you the folder if you want. Please Let me know.