Solution:
lab10movies.cpp
#include<iostream>
#include<string>
#include<fstream>
struct Movie
{
std::string movieName;
int yearReleased;
};
//TODO: create a struct called Movie
//TODO: in the struct use a string called movieName to store the
movie name
//TODO: in the struct use an int called yearReleased to store the
year
//node represents a single node in the linked list
struct node
{
Movie aMovie;
node* prevPtr;
};
//Function: menu is used to display an interactive menu to the
user
void menu();
//TODO: create a function prototype called showBeforeYear
//TODO: showBeforeYear takes two inputs: a node* and an int
void showBeforeYear(node*,int);
//Function: listMovies is used to display all movies in the
linked list
void listMovies(node*);
int main()
{
std::ifstream inputHandler;
//file handler for input file
std::string movieNameFromFile; //store
movie name from file
int movieYearFromFile;
//store movie year from file
int userInput;
//get user
input for menu interaction
int userYear;
//get year
from user to list movies
node* currentPtr = NULL;
//currentPtr points to current list element,
initialized to NULL
node* headPtr = NULL;
//headPtr points to top of list, initialized to
NULL
//Open the movies.text file
inputHandler.open("movies.txt");
//Read the first line from the file
inputHandler >> movieNameFromFile >>
movieYearFromFile;
while (!inputHandler.eof())
{
//create a new node called
currentPtr
currentPtr = new node;
//TODO: set the value for
currentPtr to the values read from the file
currentPtr->aMovie.movieName=movieNameFromFile;
currentPtr->aMovie.yearReleased=movieYearFromFile;
//set currentPtr->prevPtr to
headPtr
currentPtr->prevPtr =
headPtr;
//update headPtr to
currentPtr
headPtr = currentPtr;
//read the next line from the
file
inputHandler >>
movieNameFromFile >> movieYearFromFile;
}
//Close the file
inputHandler.close();
//Display the menu to the user
menu();
std::cin >> userInput;
//Validate input
while (userInput > 3 || userInput < 1)
{
//Display the menu to the
user
menu();
std::cin >> userInput;
}
//List movies by year
if (userInput == 1)
{
//TODO: ask the user to enter the
year
//TODO: store the year entered by
the user in userYear
//TODO: call function
showBeforeYear with currentPtr and userYear
std::cout<<"Enter an
year:";
std::cin>>userYear;
showBeforeYear(currentPtr,userYear);
return 0;
}
//List all movies
else if (userInput == 2)
{
//Call function listMovies to print
all movies
listMovies(currentPtr);
return 0;
}
//Exit program
else
{
//Show exit message and terminate
program
std::cout << "Exiting
program." << std::endl;
return 0;
}
}
//Function: menu
//Inputs: none
//Outputs: none
//Errors: none
void menu()
{
std::cout << "Press 1 to list movies released
before a specific year." << std::endl;
std::cout << "Press 2 to list all movies."
<< std::endl;
std::cout << "Press 3 to quit." <<
std::endl;
std::cout << "Enter your choice: ";
}
//TODO: create function showBeforeYear
//Function: showBeforeYear
//Inputs: node* currentPtr and int userYear
//Outputs: displays all movies before a specific year
//Errors: none
void showBeforeYear(node* currentPtr, int userYear)
{
//TODO: function showBeforeYear should list all movies
released before userYear
//TODO: if you find 0 movies before userYear, tell the
user that you found no movies
int movies=0;
while(currentPtr)
{
if(currentPtr->aMovie.yearReleased<userYear)
{
movies++;
std::cout<<currentPtr->aMovie.movieName<<"
"<<currentPtr->aMovie.yearReleased<<"\n";
}
currentPtr=currentPtr->prevPtr;
}
if(movies==0)
std::cout<<"No movies
found";
}
//Function: listMovies
//Inputs: node* currentPtr
//Outputs: displays all movies stored in linked list
//Errors: none
void listMovies(node* currentPtr)
{
//Loop until currentPtr hits NULL
while(currentPtr)
{
//Print entry from linked
list
std::cout <<
currentPtr->aMovie.movieName << " released in " <<
currentPtr->aMovie.yearReleased << std::endl;
//Move currentPtr to next
location
currentPtr =
currentPtr->prevPtr;
}
}
movies.txt:
Alice_in_Wonderland 2010
Avatar 2009
Avengers:_Age_of_Ultron 2015
Despicable_Me_2 2013
Finding_Dory 2016
Finding_Nemo 2003
Frozen 2013
Furious_7 2015
Iron_Man_3 2013
Jurassic_Park 1993
Jurassic_World 2015
Minions 2015
Shrek_2 2004
Skyfall 2012
Spectre 2015
Spider-Man_3 2007
The_Avengers 2012
The_Dark_Knight 2008
The_Dark_Knight_Rises 2012
The_Jungle_Book 2016
The_Lion_King 1994
The_Secret_Life_of_Pets 2016
Titanic 1997
Toy_Story_3 2010
Zootopia_film 2016
Output:
The file lab10movies.cpp contains a program that allows the user to read movie names and movie re...
Topics: list, file input/output (Python) You will write a program that allows the user to read grade data from a text file, view computed statistical values based on the data, and to save the computed statistics to a text file. You will use a list to store the data read in, and for computing the statistics. You must use functions. The data: The user has the option to load a data file. The data consists of integer values representing student...
[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...
Need a program in python. Asterix and Obelix want to store and process information about movies they are interested in. So, you have been commissioned to write a program in Python to automate this. Since they are not very computer literate, your program must be easy for them to use. They want to store the information in a comma separated text file. Using this they would need to generate a report – see all items AND show a bar chart...
This homework problem has me pulling my hair out. We are working with text files in Java using NetBeans GUI application. We're suppose to make a movie list and be able to pull up movies already in the text file (which I can do) and also be able to add and delete movies to and from the file (which is what I'm having trouble with). I've attached the specifications and the movie list if you need it. Any help would...
Using the program segment and sample txt file below, write a program that contains a linked list of students. The program should allow the user to: 1. initialize list of students 2. add additional student to front of list 3. add additional student to rear of list 4. delete student 5. sort students alphabetically 6. sort students by idNum 7. show number of students in list 8. print students 9. quit program XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX The program should be divided into the...
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...
Need this in C++ Goals: Your task is to implement a binary search tree of linked lists of movies. Tree nodes will contain a letter of the alphabet and a linked list. The linked list will be an alphabetically sorted list of movies which start with that letter. MovieTree() ➔ Constructor: Initialize any member variables of the class to default ~MovieTree() ➔ Destructor: Free all memory that was allocated void printMovieInventory() ➔ Print every movie in the data structure in...
Finish FormatJavaProgram.java that prompts the user for a file name and assumes that the file contains a Java program. Your program should read the file (e.g., InputFile.java) and output its contents properly indented to ProgramName_Formatted.java (e.g., InputFile_Formatted.java). (Note: It will be up to the user to change the name appropriately for compilation later.) When you see a left-brace character ({) in the file, increase your indentation level by NUM_SPACES spaces. When you see a right-brace character (}), decrease your indentation...
c++ A menu-driven program gives the user the option to find statistics about different baseball players. The program reads from a file and stores the data for ten baseball players, including player’s team, name of player, number of homeruns, batting average, and runs batted in. (You can make up your data, or get it online, for example: http://espn.go.com/mlb/statistics ) Write a program that declares a struct to store the data for a player. Declare an array of 10 components to...
C++ Objective: Write a program to read a pre-specified file containing salespersons' names and daily sales for some number of weeks. It will create an output file with a file name you have gotten from the user that will hold a summary of sales data. Specifications: 1. You should do a functional decomposition to identify the functions that you will use in the program. These should include reading and writing the files, tallying and showing statistics, etc. 2. The program...