View the step-by-step solution to:

//*************************************************************************** // // File: List.h // // Student: Sara Dysert // // Assignment:...

Hi, you worked on this program last week and I posted this as an open question, but the tutor missed the deadline. Can you help?


In the attached program, the movie information is not 'sticking' in the displayMovie function. It queries the csv and returns that the movie is found, but prints the default info for the movie. If you compile and run it, you can see what I mean. 

//*************************************************************************** // // File: List.h // // Student: Sara Dysert // // Assignment: Programming Assignment 3 // // Course Name: Data Structures I // // Course Number: COSC 3050 - 01 S1 2016 // // Due: Feb 16, 2016 // // // This file contains the class DT template for a list // // //************************************************************************** #include <string> using namespace std; #ifndef LIST_H #define LIST_H template<class DT> struct Node { DT info; Node<DT> *next; }; template<class DT> class List { private: Node<DT> *start; Node<DT> *current; public: List(); ~List(); void makeEmpty(); void addMember(DT&); bool getMember(DT&); bool getNext(DT&); bool first(DT&); void setItem(DT&, int); }; #endif template<class DT> List<DT>::List() { start = current = NULL; } template<class DT> void List<DT>::addMember(DT& newMember) { Node<DT> *ptr = new Node<DT>; ptr->info = newMember; ptr->next = start; start = ptr; } template<class DT> void List<DT>::setItem(DT& newMember, int index) { Node<DT> *ptr = start;
Background image of page 1
int i = 0; while (ptr != NULL) { if (i == index) { ptr->info = newMember; break; } i++; ptr = ptr->next; } } template<class DT> List<DT>::~List() { makeEmpty(); } template<class DT> void List<DT>::makeEmpty() { Node<DT> * delPtr; while (start != NULL) { delPtr = start; start = start->next; delete delPtr; } current = NULL; } template<class DT> bool List<DT>::first(DT & obj) { if (start == NULL) return false; current = start; obj = start->info; return true; } template<class DT> bool List<DT>::getNext(DT& obj) { current = current->next; if (current == NULL) return false; obj = current->info; return true; } template<class DT> bool List<DT>::getMember(DT& findMember) { Node<DT> *ptr = start; bool found = false; while (ptr != NULL && !found) { if(ptr->info == findMember ) found = true; if (!found) ptr = ptr->next; } return found; }
Background image of page 2
1101 1942 102 6 6 Casablanca 1200 1933 68 8 3 Duck Soup 5570 1953 118 10 3 From Here to Eternity 6601 1939 101 4 10 Wizard of Oz 1301 1941 119 7 2 Citizen Kane 1350 1978 109 3 12 Animal House 5102 1973 106 0 15 Young Frankenstein 5234 1933 100 3 9 King Kong 1405 1947 87 4 7 My Favorite Brunette 2200 1939 226 4 10 Gone with the Wind 3103 1954 120 12 1 White Christmas 3670 1946 130 11 2 It's a Wonderful Life 2345 1931 84 6 4 Public Enemy 2870 1927 88 9 3 Jazz Singer 4490 1965 200 8 5 Doctor Zhivago 4876 1965 174 7 7 Sound of Music 8330 1937 98 3 8 Topper 9400 1954 125 8 4 Caine Mutiny 7109 1941 134 6 6 Sergeant York 7405 1934 105 4 8 It Happened One Night
Background image of page 1
//*************************************************************************** // // File: movieStore.cpp // // Student: Sara Dysert // // Assignment: Programming Assignment 3 // // Course Name: Data Structures I // // Course Number: COSC 3050 - 01 S1 2016 // // Due: Feb 16, 2016 // // // This program lists movie data from a .csv file, updates the inventory, allows for a search by name // // Other files required: // 1. Movies.csv text file of integers // 2. list.h class template declaration & implementation // //************************************************************************** #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>&); void addInventory(List<Movie>&, double); int main() { List<Movie> ListMovies; getData(ListMovies); displayList(ListMovies); avgTime(ListMovies);
Background image of page 1
checkedIn(ListMovies); checkedOut(ListMovies); cout << endl; addInventory(ListMovies, 10.5); cout << "The following data is the updated Webster Movies store\n"; displayList(ListMovies); avgTime(ListMovies); checkedIn(ListMovies); checkedOut(ListMovies); displayMovie(ListMovies); return 0; } void getData(List<Movie>& cls) { Movie movie; ifstream inFile("Movies.csv"); if (!inFile) { std::cout << "Problem opening Movies.csv file" << endl; exit(99); } 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;
Background image of page 2
Show entire document
Sign up to view the entire interaction

Top Answer

View the full answer
List.h

//***************************************************************************
//
//
File:
List.h
//
//
Student:
Sara Dysert
//
//
Assignment:
Programming Assignment 3
//
//
Course Name:
Data...

Sign up to view the full answer

Why Join Course Hero?

Course Hero has all the homework and study help you need to succeed! We’ve got course-specific notes, study guides, and practice tests along with expert tutors.

-

Educational Resources
  • -

    Study Documents

    Find the best study resources around, tagged to your specific courses. Share your own to gain free Course Hero access.

    Browse Documents
  • -

    Question & Answers

    Get one-on-one homework help from our expert tutors—available online 24/7. Ask your own questions or browse existing Q&A threads. Satisfaction guaranteed!

    Ask a Question
Ask a homework question - tutors are online