Question
Plea5e help! Program 6 is mentioned below. I need help writing this program. THANKS! Driver.cpp -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- #include Movies.h #include Movie.h #include Text.h #include Timer.h #include
Plea5e help!
Program 6 is mentioned below. I need help writing this program. THANKS!
Driver.cpp
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
#include "Movies.h"
#include "Movie.h"
#include "Text.h"
#include "Timer.h"
#include
using namespace std;
int main()
{
int menuChoice;
int movieChoice;
char filename[25];
Movies* movieLibrary = new Movies();
do
{
cout
cout
cout
cout
cout
cout
cout
cout
cout
cin >> menuChoice;
while(menuChoice 8)
{
cout
cout
cin >> menuChoice;
}
switch(menuChoice)
{
case 1: cout
cin >> filename;
movieLibrary->readMoviesFromFile(filename);
break;
case 2: cout
cin >> filename;
movieLibrary->saveToFile(filename);
break;
case 3: //add a movie
movieLibrary->addMovieToList();
break;
case 4: //delete a movie if there is more than one movie in the library.
movieLibrary->removeMovieFromList();
break;
case 5: //edit a movie
movieLibrary->editMovieInList();
break;
case 6: //print all movies
movieLibrary->displayMovies();
break;
case 7: //delete all movies
delete movieLibrary;
break;
case 8: //algorithm analysis
movieLibrary->algorithmAnalysis();
break;
}
} while(menuChoice != 8);
cout
return 0;
}
______________________________________________________________________________________________________________________________________________
Movies.cpp
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
#include "Movies.h"
#include "Movie.h"
Movies::Movies()
{
linkedList = new LinkedList;
}
Movies::~Movies()
{
for(int x = 0; x getLength();x++)
{
delete linkedList->getNodeValue(x)->getMovieTitle();
delete linkedList->getNodeValue(x)->getMovieGenre();
delete linkedList->getNodeValue(x)->getMovieRating();
}
}
void Movies::addMovieToList()
{
char tempString[100];
int length, year, numOscars;
double numStars;
Text* title;
Text* genre;
Text* rating;
cin.ignore();
cout
cin.getline(tempString, 100);
title = new Text(tempString);
if(binarySearch(title)==-1)
{
cout
cin >> length;
cout
cin >> year;
cin.ignore();
cout
cin.getline(tempString, 100);
genre = new Text(tempString);
cout
cin.getline(tempString, 100);
rating = new Text(tempString);
cout
cin >> numOscars;
cout
cin >> numStars;
Movie* oneMovie = new Movie(title, length, year, genre, rating, numOscars, numStars);
linkedList->appendNode(oneMovie);
insertionSort();
}
else
{
cout
title->displayText();
cout
delete title;
}
}
void Movies::removeMovieFromList()
{
int movieChoice;
if(linkedList->getLength()
{
cout
cout
}
else
{
cout
displayMovieTitles();
cout getLength()
cin >> movieChoice;
while(movieChoice linkedList->getLength())
{
cout getLength()
cin >> movieChoice;
}
int movieIndexToBeRemoved = movieChoice-1;
Text* movieTitle;
movieTitle = linkedList->getNodeValue(movieIndexToBeRemoved)->getMovieTitle();
cout
movieTitle->displayText();
cout
linkedList->deleteNode(movieIndexToBeRemoved);
int numElementsToMoveBack = (linkedList->getLength()) - 1;
}
}
void Movies::editMovieInList()
{
int movieChoice;
cout
displayMovieTitles();
cout getLength()
cin >> movieChoice;
while(movieChoice linkedList->getLength())
{
cout
cin >> movieChoice;
}
Movie* oneMovie = linkedList->getNodeValue(movieChoice-1);
oneMovie->editMovie();
}
void Movies::displayMovies()
{
if(linkedList->getLength() > 0)
{
for(int x=0; x getLength(); x++)
{
cout
linkedList->getNodeValue(x)->printMovieDetails();
}
}
else
cout
}
void Movies::displayMovieTitles()
{
Text* movieTitle;
for(int x=0; xgetLength(); x++)
{
cout
movieTitle =linkedList->getNodeValue(x)->getMovieTitle();
movieTitle->displayText();
}
}
void Movies::readMoviesFromFile(char *filename)
{
int numMoviesReadFromFile = 0;
ifstream inFile;
char temp[100];
Text* title;
Text* genre;
Text* rating;
Movie* oneMovie;
int movieLength;
int movieYear;
int movieOscars;
float movieNumStars;
inFile.open(filename);
if(inFile.good())
{
inFile.getline(temp, 100);
while(!inFile.eof())
{
title = new Text(temp);
inFile >> movieLength;
inFile >> movieYear;
inFile.ignore();
inFile.getline(temp, 100);
genre = new Text(temp);
inFile.getline(temp, 100);
rating = new Text(temp);
inFile >> movieOscars;
inFile >> movieNumStars;
inFile.ignore();
if(-1!=binarySearch(title))
{
title->displayText();
cout
delete title;
delete rating;
delete genre;
}
else
{
cout
oneMovie = new Movie(title, movieLength, movieYear, genre, rating, movieOscars, movieNumStars);
linkedList->appendNode(oneMovie);
cout
title->displayText();
cout
numMoviesReadFromFile++;
}
inFile.getline(temp, 100);
}
cout
}
else
{
cout
}
insertionSort();
}
void Movies::saveToFile(char *filename)
{
ofstream outFile;
outFile.open(filename);
for(int x=0; xgetLength(); x++)
{
linkedList->getNodeValue(x)->printMovieDetailsToFile(outFile); //function in Movies.cpp
}
outFile.close();
cout
}
int Movies::getNumMovies() const
{
return linkedList->getLength();
}
int Movies::binarySearch(Text* title){
int found = -1;
if(linkedList->getLength() == 0)
{
return found;
}
else
{
for(int x = 0; x getLength()-1;x++)
{
if(0==strcmp(linkedList->getNodeValue(x)->getMovieTitle()->getText(),title->getText()))
{
found = x;
}
}
}
return found;
}
void Movies::insertionSort()
{
int j;
for(int i =1; igetLength();i++)
{
j = i;
while(j>0 && 0getNodeValue(j-1)->getMovieTitle()->getText(),linkedList->getNodeValue(j)->getMovieTitle()->getText()))
{
linkedList->swap(j-1,j);
j--;
}
}
}
____________________________________________________________________________________________________________________________________________
Movies.h
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
#ifndef MOVIES_H #define MOVIES_H
#include "LinkedList.h" #include "Movie.h" #include #include #include
using namespace std;
class Movies { private: LinkedList *linkedList; public: Movies();
~Movies(); void addMovieToList(); void displayMovies(); void displayMovieTitles(); void readMoviesFromFile(char* filename); void removeMovieFromList(); void editMovieInList(); void saveToFile(char *filename);
int getNumMovies() const; void insertionSort(); int binarySearch(Text*); };
#endif
_________________________________________________________________________________________________________________________________
Timer.cpp
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
#include "Timer.h"
using namespace std;
time_t getTime()
{
return time(NULL);
}
double totalTime (time_t start, time_t end)
{
return difftime (end, start);
}
____________________________________________________________________________________________________________________________________________
Timer.h
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
#include
#include
#include
/*
Pre: None
Post: Returns the current system time
*/
time_t getTime();
/*
Pre: start and end are variables of type time_t containing 2 different system times, start is before end
Post: Will return the number of seconds separating two times
*/
double totalTime (time_t start, time_t end);
TIMER CLASS Whenever you see "start timer and "stop timer" and "print out total time" in the directions in this document, that means you will be using the Timer class provided for you. You will need to # include "Tiner. h" to use this class. When you want to use a timer in your program, you will first need to create variables of data type time_t. time t start: time_t end: The getTime() function will get the current time and return it as a time t data type. You will use this function to get the start time and the end time. The totalTimel) function accepts two timet variables (start & end) and then returns the difference as a double (which is the & end time. DRIVER.CPP Modify the menu so that there is an addition option. The option should be inserted after "Print all movies" and before "Delete All movies and will be your new #7. Then the user will choose between 1 and 8. If the user chooses #7, then you should call the algorithmAnalysis function, which is a member function of the Movies class. TIMER CLASS Whenever you see "start timer and "stop timer" and "print out total time" in the directions in this document, that means you will be using the Timer class provided for you. You will need to # include "Tiner. h" to use this class. When you want to use a timer in your program, you will first need to create variables of data type time_t. time t start: time_t end: The getTime() function will get the current time and return it as a time t data type. You will use this function to get the start time and the end time. The totalTimel) function accepts two timet variables (start & end) and then returns the difference as a double (which is the & end time. DRIVER.CPP Modify the menu so that there is an addition option. The option should be inserted after "Print all movies" and before "Delete All movies and will be your new #7. Then the user will choose between 1 and 8. If the user chooses #7, then you should call the algorithmAnalysis function, which is a member function of the Movies classStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started