Using an object-oriented approach, write a program to read a file containing movie data (Tile, Director, Genre, Year Released, Running Time) into a vector of structures and perform the following operations:
Search for a specific title
Search for movies by a specific director
Search for movies by a specific genre
Search for movies released in a certain time period
Search for movies within a range for running time
Display the movies on the screen in a nice, easy to read format
Use the following basic implementations to start your project.
You only need to turn in MovieData.cpp main.cpp has an example of the basic layout of your program. You will need to finish it in order to test your program or you can just write your own. You don't need to turn it in.
MovieData.h has the class definition or interface. Don't change it or I won't be able to test your program.
MovieData.cpp already implements member function loadData(). You need to implement the constructor, destructor and all other member functions. This is the only file you will turn in. Add a header comment to MovieData.cpp with a brief description of the purpose of the MovieData class, your name and date.
main.cpp ___________________________________________
#include <iostream>
#include <string>
#include "MovieData.h"
using namespace std;
int menu();
int main(){
enum options { SEARCH_BY_TITLE, SEARCH_BY_DIRECTOR, SEARCH_BY_GENRE, SEARCH_BY_YEAR, SEARCH_BY_DURATION, EXIT };
ifstream inputFile;
string fileName;
cout << "Enter file name: ";
cin >> fileName;
MovieData *movieObj;
movieObj = new MovieData(fileName);
if (!movieObj->isLoaded())
{
cout << "Error openning file\n";
}
else
{
int option;
do
{
option = menu();
// Implement the switch options to test your program
switch (option)
{
case SEARCH_BY_TITLE:
break;
case SEARCH_BY_DIRECTOR:
break;
case SEARCH_BY_GENRE:
break;
case SEARCH_BY_YEAR:
break;
case SEARCH_BY_DURATION:
break;
default: cout << "Invalid option. Try again. \n";
}
} while (option != EXIT);
}
delete movieObj;
}
// You should implement this function to test your program
int menu()
{
return 0;
}
__________________________________________________________________________
MovieData.cpp_______________________________________________________
#include <iostream>
#include <sstream>
#include <algorithm>
#include "MovieData.h"
using namespace std;
MovieData::MovieData(string fileName)
{
// Implement constructor here
}
MovieData::~MovieData()
{
// Implement destructor here
}
// This function loads the movies from the file into the vector
void MovieData::loadData()
{
string line;
MovieType m; // holds one movie to be added to the vector of movies
while (getline(inputFile, line)) // reads a line from the file
{
stringstream lineStream(line); // transforms the line into a stream
// splits the string stream into individual fields separated by comma
getline(lineStream, m.title, ',');
getline(lineStream, m.director, ',');
getline(lineStream, m.genre, ',');
getline(lineStream, m.year, ',');
getline(lineStream, m.duration, ',');
moviesVector.push_back(m); // adds movie to the vector of movies
}
}
// Implement all other member functions here
____________________________________________
MovieData.h_______________________________________
#ifndef MOVIEDATA_H
#define MOVIEDATA_H
using namespace std;
#include <fstream>
#include <string>
#include <vector>
class MovieData
{
private:
struct MovieType {
string title;
string director;
string genre;
string year;
string duration;
};
vector<MovieType> moviesVector;
ifstream inputFile;
bool fileLoaded;
void loadData(); // this function is called in the constructor to load the movies from the file
void printMovie(MovieType); // this function is called by the search functions to print each movie on the screen
public:
// Constructor: opens the file passed as parameter, calls loadData to load the data from the file into the vector and sets fileLoaded to true if succeeded
MovieData(string fileName);
// Destructor: closes the file
virtual ~MovieData();
// Returns the value of the fileLoaded status variable
bool isLoaded();
// Searches for movies by title and displays them on the screen
void searchByTitle(string title);
// Searches for movies by director and displays them on the screen
void searchByDirector(string director);
// Searches for movies by genre and displays them on the screen
void searchByGenre(string genre);
// Searches for movies released between years start and end, and displays them on the screen
void searchByYear(int start, int end);
// Searches for movies with duration between min and max, and displays them on the screen
void searchByDuration(int min, int max);
};
#endif // MOVIEDATA_H
_____________________________
text file
IAvengers: Age of Ultron,Joss Whedon,science
fiction,2015,120
Mean Girls,Mark Waters,comedy,2004,97
Happy Feet,George Miller,comedy,2006,108
Surf's Up,Chris Buck,advanture,2007,85
The Great Escape,John Sturges,thriller,1963,172
Superbad,Gret Mottola,comedy,2007,113
Earthlings,Shaun Monson,documentary,2005,95
Limitless,Neil Burger,Thriller,2011,105
Guardians of the Galaxy,James Gunn,fantasy,2014,120
Kung Fu Hustle,Stephen Chow,fantasy,2004,99
Whiplash,Damien Chazelle,drama,2014,106
Ghost in the Shell,Mamoru Oshii,manga,1995,82
Inglourious Basterds,Quentin Tarantino,drama,2009,120
Under the Tuscan Sun,Audrey Wells,drama,2003,113
A Thousand Words,Brian Robbins,comedy,2012,91
Interstellar,Christopher Nollan,science fiction,2014,160
Zoolander,Ben Stiller,comedy,2001,105
Captain America: The Winter Soldier,Russo,science
fiction,2014,120
Chungking Express,Kai Wai Wong,drama,1994,98
The Matrix,Andy Wachowski,fantasy,1999,136
Gone Girl,David Fincher,mystery,2014,129
Saving Private Ryan,Steven Spielberg,drama,1998,120
#include <iostream>
#include <fstream>
#include <sstream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
struct Movie {
string title;
string director;
string genre;
string year;
string duration;
};
//function prototype
void display (vector<Movie>);
bool compareByTitle(Movie const& m1, Movie const& m2);
bool compareByDirector(Movie const& m1, Movie const& m2);
bool compareByYear(Movie const& m1, Movie const& m2);
bool compareByGenre(Movie const& m1, Movie const& m2);
bool compareByDuration(Movie const& m1, Movie const& m2);
int main()
{
//Declare variable
ifstream inputFile;
string line;
int choice;
Movie m;
vector <Movie> movies;
inputFile.open("Movie_entries.txt");
while (getline(inputFile, line)) // reads a line from the file
{
//cout << line << endl; // prints the line on the screen
stringstream lineStream(line); // transforms the line into a string stream
// get fields from the string stream to the struct fields; data is separated by comma
getline(lineStream, m.title, ',');
getline(lineStream, m.director, ',');
getline(lineStream, m.genre, ',');
getline(lineStream, m.year, ',');
getline(lineStream, m.duration, ',');
movies.push_back(m);
}
inputFile.close();
do {
//prompt the user input for the type of sorting
cout << "You can sort the movies by title, director, year released, or duration." << endl;
cout << "Please enter the corresponding number:" << endl;
cout << "1 : to sort by title" << endl;
cout << "2 : to sort by director" << endl;
cout << "3 : to sort by year released" << endl;
cout << "4 : to sort by genre" << endl;
cout << "5 : to sort by the duration time" << endl;
cout << "0 : to exit the program" << endl;
cin >> choice;
//sorting depending on users choice
if (choice == 1)
{
sort(movies.begin(), movies.end(), compareByTitle);
}
else if (choice == 2)
{
sort(movies.begin(), movies.end(), compareByDirector);
}
else if (choice == 3)
{
sort(movies.begin(), movies.end(), compareByYear);
}
else if (choice == 4)
{
sort(movies.begin(), movies.end(), compareByGenre);
}
else if (choice == 5)
{
sort(movies.begin(), movies.end(), compareByDuration);
}
else if (choice == 0) // exit the program
{
cout << "Goodbye!" << endl;
exit(1);
}
//Printing movie info once the sorting is done
display(movies);
}
while (choice <= 5); //this will repeat until user chooses to exit
return 0;
}//main
void display(vector<Movie> movies)
{
/* Pre: movies - the movie lists
Post: nothing
Purpose: print out the header and the sorted data
*/
//header
cout << left<< setw(35) << "\nTitle" << left << setw(25)<< "Director" << left << setw(25)<< "Genre" << left << setw(25)<< "Year Released" << left << setw(25) << "Duration"<< endl;
//loop through the movie list and display the data
for (int i = 0; i < movies.size(); ++i)
{
cout << left<< setw(35) << movies[i].title<< left << setw(25)<< movies[i].director<< left << setw(25)<< movies[i].genre<< left << setw(25)<< movies[i].year << left << setw(25) << movies[i].duration<< endl;
}
}//display
///////////////////////
//Comparing Functions
bool compareByTitle(Movie const& m1,Movie const& m2)
{return m1.title < m2.title;}
bool compareByDirector(Movie const& m1, Movie const& m2)
{return m1.director < m2.director;}
bool compareByYear(Movie const& m1, Movie const& m2)
{return m1.year < m2.year;}
bool compareByGenre(Movie const& m1, Movie const& m2)
{return m1.genre < m2.genre;}
bool compareByDuration(Movie const& m1, Movie const& m2)
{return m1.duration < m2.duration;}
Using an object-oriented approach, write a program to read a file containing movie data (Tile, Director,...
I keep getting errors and i am so confused can someone please help and show the input and output ive tried so many times cant seem to get it. main.cpp #include <iostream> #include <vector> #include <string> #include "functions.h" int main() { char option; vector<movie> movies; while (true) { printMenu(); cin >> option; cin.ignore(); switch (option) { case 'A': { string nm; int year; string genre; cout << "Movie Name: "; getline(cin, nm); cout << "Year: "; cin >> year; cout << "Genre: "; cin >> genre; //call you addMovie() here addMovie(nm, year, genre, &movies); cout << "Added " << nm << " to the catalog" << endl; break; } case 'R': { string mn; cout << "Movie Name:"; getline(cin, mn); bool found; //call you removeMovie() here found = removeMovie(mn, &movies); if (found == false) cout << "Cannot find " << mn << endl; else cout << "Removed " << mn << " from catalog" << endl; break; } case 'O': { string mn; cout << "Movie Name: "; getline(cin, mn); cout << endl; //call you movieInfo function here movieInfo(mn, movies); break; } case 'C': { cout << "There are " << movies.size() << " movies in the catalog" << endl; // Call the printCatalog function here printCatalog(movies); break; } case 'F': { string inputFile; bool isOpen; cin >> inputFile; cout << "Reading catalog info from " << inputFile << endl; //call you readFromFile() in here isOpen = readFile(inputFile, &movies); if (isOpen == false) cout << "File not found" << endl;...
[C++] Outline: The movie data is read from a file into an array of structs and is sorted using the Selection Sort method and the search is done using the Binary Search algorithm with the year of release as key. This assignment upgrades to an array of pointers to the database elements and converts the Selection Sort and Binary search procedure on the database to selection sort and binary search on the array of pointers to the database. Requirements: Your...
PLEASE COMPLETE THE CODES. package javaprogram; import java.io.PrintStream; import java.util.ArrayList; import java.util.Scanner; /** * Movie class definition. * * @author David Brown * @version 2019-01-22 */ public class Movie implements Comparable { // Constants public static final int FIRST_YEAR = 1888; public static final String[] GENRES = { "science fiction", "fantasy", "drama", "romance", "comedy", "zombie", "action", "historical", "horror", "war" }; public static final int MAX_RATING = 10; public static final int MIN_RATING = 0; /** * Converts a string of...
WONT COMPILE ERROR STRAY / TEXT.H AND CPP PROGRAM SAYING NOT DECLARED HAVE A DRIVER WILL PASTE AT BOTTOM MOVIES.CPP #include "movies.h" #include "Movie.h" Movies *Movies::createMovies(int max) { //dynamically create a new Movies structure Movies *myMovies = new Movies; myMovies->maxMovies = max; myMovies->numMovies = 0; //dynamically create the array that will hold the movies myMovies->moviesArray = new Movie *[max]; return myMovies; } void Movies::resizeMovieArray() { int max = maxMovies * 2; //increase size by 2 //make an array that is...
C++ Language I have a class named movie which allows a movie object to take the name, movie and rating of a movie that the user inputs. Everything works fine but when the user enters a space in the movie's name, the next function that is called loops infinetly. I can't find the source of the problem. Down below are my .cpp and .h file for the program. #include <iostream> #include "movie.h" using namespace std; movie::movie() { movieName = "Not...
LAB 7-Movie List Program Goali Your assignment is to write a C++program to implement the ADT List by creating a list of movies. This assignment will help you practice: multiple file programming, classes, pablic and private methods, dynamie memory, constructors and destructors, arrays and files Implementation the required classes This lab assignment gives you the opportunity to practice creating classes and using dynamic memory in one of There are two classes to implement: Movie and MovieList. As you can see...
I am having trouble trying to output my file Lab13.txt. It will say that everything is correct but won't output what is in the file. Please Help Write a program that will input data from the file Lab13.txt(downloadable file); a name, telephone number, and email address. Store the data in a simple local array to the main module, then sort the array by the names. You should have several functions that pass data by reference. Hint: make your array large...
Objective In this assignment, you will practice solving a problem using object-oriented programming and specifically, you will use the concept of object aggregation (i.e., has-a relationship between objects). You will implement a Java application, called MovieApplication that could be used in the movie industry. You are asked to implement three classes: Movie, Distributor, and MovieDriver. Each of these classes is described below. Problem Description The Movie class represents a movie and has the following attributes: name (of type String), directorName...
My C++ program is not compiling. Please explain how you fixed with detailed inline comments. I am using Visual Studio 2017. It's a character count program that keeps and displays a count of all the upper, lower case and digits in a .txt file. The requirement is to use classes to implement it. -----------------------------------------------------------------HEADER FILE - Text.h--------------------------------------------------------------------------------------------- /* Header file contains only the class declarations and method prototypes. Comple class definitions will be in the class file.*/ #ifndef TEXT_H #define...
Write a cpp program Server.h #ifndef SERVER_H #define SERVER_H #include #include #include #include using namespace std; class Server { public: Server(); Server(string, int); ~Server(); string getPiece(int); private: string *ascii; mutex access; }; #endif -------------------------------------------------------------------------------------------------------------------------- Server.cpp #include "Server.h" #include #include Server::Server(){} Server::Server(string filename, int threads) { vector loaded; ascii = new string[threads]; ifstream in; string line; in.open(filename); if (!in.is_open()) { cout << "Could not open file...