Question

In c++. The instructions are in the image. Please do not change existing code below just add to what is needed. I am very confused. Can you please show the input and output of the code it would help very much. There is also a text file which is named "input.txt" and it reads.

Movie 1
1
Genre1
Movie 2
2
Genre2
Movie 3
3
Genre3
Movie 4
4
Genre4
Movie 5
5
Genre5

main.cpp

#include <iostream>
#include <vector>
#include <string>
#include "functions.h"

 

int main()
{

vector<movie> movies;
char option;


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
cout << "Added " << nm << " to the catalog" << endl;
break;
}
case 'R':
{
string mn;
cout << "Movie Name:";
getline(cin, mn);
bool found;
found = //call you removeMovie()here
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
break;

}
case 'C':
{
cout << "There are " << movies.size() << " movies in the catalog" << endl;
// Call the printCatalog function here
break;
}
case 'F':
{
string inputFile;
bool isOpen;
cin >> inputFile;
cout << "Reading catalog info from " << inputFile << endl;
isOpen = //call you readFromFile() in here
if (isOpen == false)
cout << "File not found" << endl;
break;
}
case 'W':
{ string outputFile;
bool isOpen;
cin >> outputFile;
cout << "Writing catalog info to " << outputFile << endl;
isOpen = //call you writeToFile() in here
if (isOpen == false)
cout << "File not found" << endl;
break;
}
}
if (option == 'Q')
{
cout << "Quitting Program";
break;
}
}
}

functions.h

#ifndef FUNCTIONS_H
#define FUNCTIONS_H

#include <iostream>
#include <vector>
#include <string>
//include necessary libraries

using namespace std;


// Define the structure "movie" here


void printMenu()
{
cout << endl;
cout << "Menu:" << endl;
cout << "A - Add Movie" << endl;
cout << "R - Remove Movie" << endl;
cout << "O - Output Movie Info" << endl;
cout << "C - Output Catalog Info" << endl;
cout << "F - Read file" << endl;
cout << "W - Write file" << endl;
cout << "Q - Quit Program" << endl;
cout << "Choose an option: ";
}

void printMovieInfo(const string &mn, int yr, const string &gen)
{
cout << endl;
cout << "Name: " << mn << endl;
cout << "Year: " << yr << endl;
cout << "Genre: " << gen << endl;
}

// Write the definition and implementation of the printCatalog function here

// Write the definition and implementation of the findMovie function here

// Write the definition and implementation of the addMovie function here

// Write the definition and implementation of the removeMovie function here

// Write the definition and implementation of the movieInfo function here
// You must use the following cout statement if the movie is not in the catalog:
// cout << "Cannot find " << /*movie name variable identifier*/ << endl;

// Write the definition and implementation of the readFromFile function here

// Write the definition and implementation of the writeToFile function here

#endif

17.4 Programming Assignment 4 - Structs and File I/O
Problem:
You are asked to create a program for storing the catalog of movies at a DVD store using functions, files, and user-defined structures. The
program should let the user read the movie through the file, add, remove, and output movies to the file.
For this assignment, you must store the information about the movies in the catalog using a single vector. The vector's data type is a
user-defined structure that you must define on functions.h following these rules:
• Identifier for the user-define structure: movie.
• Member variables of the structure "movie": name (string), year (int), and genre (string).
Note: you must use the identifiers presented before when defining the user-defined structure. Your solution will NOT pass the unit test
cases if you do not follow the instructions presented above.
The main function is provided (you need to modify the code of the main function to call the user-defined functions described below).
The following user-defined functions are provided in the functions.h template file
printMenu: this function does not receive arguments and does not return a value. The function prints the options from the menu to
STDOUT.
Menu:
A - Add Movie
R - Remove Movie
O -
Output Movie Info
C -
Output Catalog Info
R- Read file
W- Write file
Quit Program
printMovielnfo: this function receives the following arguments:
A string representing the movie name. An integer representing the year of the movie. A string representing the movie genre.
The function prints the information about a movie (name, year, and genre) and does not return a value.
You must write the following user-defined functions:
1) printCatalog: this function receives the following arguments:
-A vector with the catalog of movies.
The function prints the information about each movie in the catalog using the output messages provided in the printMovielnfo function and
does not return a value.
2) findMovie: this function receives the following arguments:
• A string representing the movie name.
• A vector with the catalog of movies.
The function returns the index at which the movie name is located in the vector with the names of the movies in the catalog. If the movie is
not in the catalog, the function must return -1.
HINT: You may have to use this function in other functions.
3) addMovie: this function receives the following arguments:
• A string representing the name of the movie to be added to the catalog.
• An integer representing the year of the movie to be added to the catalog.
• A string representing the genre of the movie to be added to the catalog.
• A vector with the catalog of movies.
The function adds the information about the new movie to the corresponding vectors and does not return a value.
4) removeMovie: this function receives the following arguments:
• A string representing the name of the movie to be removed from the catalog.
• A vector with the catalog of movies.
If the movie is in the catalog, the function removes all the information about the movie from the vectors representing the catalog. The
function returns true (boolean) if the movie was removed from the catalog or false (boolean) if the movie was not found.
HINT: You may have to call another function within this function.
5) movielnfo: this function receives the following arguments:
• A string representing the name of the movie to find in the catalog.
• A vector with the catalog of movies.
If the movie is in the catalog, the function outputs the information about the movie using the output messages provided in the
printMovielnfo function. If the movie is not found, then the function must print to STDOUT the following message:
cout << "Cannot find " << /*movie name identifier*/ << endl;
This function does not return a value.
HINT: You may have to call another function within this function.
6) readFromFile: this function receives the following arguments:
• A string with the input file name
• A vector with the catalog of movies
The function reads the movie information from the input file and appends them to the Catalog. This function returns true (boolean) if the
program can open the file specified by the first argument or false (boolean) if the program cannot open the file specified by the first
argument.
The information about the catalog of movies is stored in the input file using the following format:
Movie Name 1 (string)
Yearl (int)
/ > COSC 1437: Introduction to Programming home > 17.4: Programming Assignment 4 - Structs and File I/O
zyBooks catalog
? Help/FA
Movie Name n (string)
YearN (int)
GenreN (string)
Given the previous format for the input file (where each field of a movie is stored in one line), here is an example of an input file:
Terminator
1984
Action
The Goonies
1985
Fiction
Avengers
2012
Action
7) writeToFile: this function receives the following arguments:
• A string with the name of the output file
• A vector with the catalog of movies
The function stores the information from the movie catalog in the output file. This function returns true (boolean) if the program can open
the file specified by the first argument or false (boolean) if the program cannot open the file specified by the first argument. You must save
the information about the movie catalog using the format of an input file presented above (each field of a movie is stored in one line).
HINT: Make sure that this function does not add an end-of-line character at the end of the file.
Expand
Transcribed Image Text

17.4 Programming Assignment 4 - Structs and File I/O Problem: You are asked to create a program for storing the catalog of movies at a DVD store using functions, files, and user-defined structures. The program should let the user read the movie through the file, add, remove, and output movies to the file. For this assignment, you must store the information about the movies in the catalog using a single vector. The vector's data type is a user-defined structure that you must define on functions.h following these rules: • Identifier for the user-define structure: movie. • Member variables of the structure "movie": name (string), year (int), and genre (string). Note: you must use the identifiers presented before when defining the user-defined structure. Your solution will NOT pass the unit test cases if you do not follow the instructions presented above. The main function is provided (you need to modify the code of the main function to call the user-defined functions described below). The following user-defined functions are provided in the functions.h template file printMenu: this function does not receive arguments and does not return a value. The function prints the options from the menu to STDOUT. Menu: A - Add Movie R - Remove Movie O - Output Movie Info C - Output Catalog Info R- Read file W- Write file Quit Program printMovielnfo: this function receives the following arguments: A string representing the movie name. An integer representing the year of the movie. A string representing the movie genre. The function prints the information about a movie (name, year, and genre) and does not return a value. You must write the following user-defined functions: 1) printCatalog: this function receives the following arguments: -A vector with the catalog of movies. The function prints the information about each movie in the catalog using the output messages provided in the printMovielnfo function and does not return a value. 2) findMovie: this function receives the following arguments: • A string representing the movie name. • A vector with the catalog of movies. The function returns the index at which the movie name is located in the vector with the names of the movies in the catalog. If the movie is not in the catalog, the function must return -1. HINT: You may have to use this function in other functions. 3) addMovie: this function receives the following arguments: • A string representing the name of the movie to be added to the catalog. • An integer representing the year of the movie to be added to the catalog. • A string representing the genre of the movie to be added to the catalog. • A vector with the catalog of movies. The function adds the information about the new movie to the corresponding vectors and does not return a value. 4) removeMovie: this function receives the following arguments: • A string representing the name of the movie to be removed from the catalog. • A vector with the catalog of movies. If the movie is in the catalog, the function removes all the information about the movie from the vectors representing the catalog. The function returns true (boolean) if the movie was removed from the catalog or false (boolean) if the movie was not found. HINT: You may have to call another function within this function. 5) movielnfo: this function receives the following arguments: • A string representing the name of the movie to find in the catalog. • A vector with the catalog of movies. If the movie is in the catalog, the function outputs the information about the movie using the output messages provided in the printMovielnfo function. If the movie is not found, then the function must print to STDOUT the following message: cout << "Cannot find " << /*movie name identifier*/ << endl; This function does not return a value. HINT: You may have to call another function within this function. 6) readFromFile: this function receives the following arguments: • A string with the input file name • A vector with the catalog of movies The function reads the movie information from the input file and appends them to the Catalog. This function returns true (boolean) if the program can open the file specified by the first argument or false (boolean) if the program cannot open the file specified by the first argument. The information about the catalog of movies is stored in the input file using the following format: Movie Name 1 (string) Yearl (int) / > COSC 1437: Introduction to Programming home > 17.4: Programming Assignment 4 - Structs and File I/O zyBooks catalog ? Help/FA Movie Name n (string) YearN (int) GenreN (string) Given the previous format for the input file (where each field of a movie is stored in one line), here is an example of an input file: Terminator 1984 Action The Goonies 1985 Fiction Avengers 2012 Action 7) writeToFile: this function receives the following arguments: • A string with the name of the output file • A vector with the catalog of movies The function stores the information from the movie catalog in the output file. This function returns true (boolean) if the program can open the file specified by the first argument or false (boolean) if the program cannot open the file specified by the first argument. You must save the information about the movie catalog using the format of an input file presented above (each field of a movie is stored in one line). HINT: Make sure that this function does not add an end-of-line character at the end of the file.

Expert Answer

Want to see the step-by-step answer?

Check out a sample Q&A here.

Want to see this answer and more?

Experts are waiting 24/7 to provide step-by-step solutions in as fast as 30 minutes!*

*Response times may vary by subject and question complexity. Median response time is 34 minutes for paid subscribers and may be longer for promotional offers.
Tagged in
Engineering
Computer Science

Programing Language

Related Computer Science Q&A

Find answers to questions asked by students like you.

Q: Pseudocode for the mystery algorithm 1. input two integers: a,b 2. initialize the value of x to a ...

A: Algorithm:- A technique for addressing a well-defined computing issue is known as an algorithm. All ...

Q: Recall in cellular respiration, the processes of glycolysis, pyruvate processing, and the citric aci...

A: Glycolysis yields the following components: ATP and NADH Pyruvate processing yields the following co...

Q: So, which of these options are true about the number of sellers in your market - the market for corn...

A: In case of Perfect Competition there are large number of buyers and sellers who have complete inform...

Q: About two centuries ago, Benjamin Franklin showed that 1 teaspoon of oil would cover about 0.5 acre ...

A: The volume of the oil (V) = Area (A) x Thickness (T), or T = V/A  Given: The volume is 5.0 cm3. The ...

Q: Write the chemical equation for the formation of CHCH from the single, isolated HH and CC atoms. equ...

A: As the bond dissociation energies are given.  But in case of C(g) and H(g) ,the bond dissociation en...

Q: 2) Na,CO3(aq) + CaCl2(aq) → 2 NaCl(aq) + CaCO3(s) Calculate the volume (in mL) of 0.200 M CaCl, need...

A: Click to see the answer

Q: A tank with 43.2 kg of water is leaking at a rate of 0.0135 kg/s. How many hours will it take until ...

A: We have to calculate time to empty the tank.  

Q: Jim Andrews opened a delivery business in March. He rented a small office and has a part-time assist...

A: Hi, since you have posted a question with multiple subparts we are solving the 1st 3 subparts for yo...

Q: Assume that females have pulse rates that are normally distributed with a mean of μ = 74.0 beats per...

A: Normal distribution is a continuous distribution which has many real life applications. For a normal...

Q: Kinesin is a motor protein that moves cargo within cells in a series of rapid 8-nm-long steps. Each ...

A: Length of steps of Kinesin = 8nm Time taken by each step = 50 ms Delay between each step =15 ms So, ...

Q: Identifying transactionsRocky Mountain Tours Co. is a travel agency. The nine transactionsrecorded b...

A: As per accounting equation, assets equal to sum of liabilities and shareholders' equity.  

Q: Ribbon diagrams show secondary structures and appear less detailed than other models. In one to two ...

A: Ribbon diagrams are the 3-D structure of the protein that shows the overall path and structure of th...

Q: A piston-cylinder assembly contains a mystery substance that undergoes a series of processes. Proces...

A: Click to see the answer

Q: Malik is looking to successfully implement MBO in his organization. To this end, he is focusing on t...

A: A management is defined as an act to coordinate and administrate the employees in order to achieve t...

Q: The unadjusted trial balance of Lakota Freight Co. at March 31, 2019, the end of the year, follows: ...

A: "Since you have asked multiple sub part question we will solve the first three sub part question for...

Q: Salts are composed of both cations and anions, both of which can potentially affect pH. Choose the f...

A: Salts affect the pH of solution based on their composition.

Q: Closing entries;After the accounts have been adjusted at November 30, the end of the fiscal year, th...

A: Closing Entry: Closing entries are passed at the end of accounting period to close the balances of l...

Q: Latoya is in the adolescent phase of life.  She is experiencing social and emotional development.  I...

A: Psychosocial development is an elegant expression that leads to how an individual personal requireme...

Q: Profit maximization and loss minimization BYOB is a monopolist in beer production and distribution i...

A: BYOB is a monopolist in beer production. Let BYOB cannot discriminate price and sell beer to all cus...

Q: Ken got 2/3 of a ton of gravel even though he ordered 3/4 of a ton of gravel. What fraction of his o...

A: ken wanted 3/4 of a ton but he got only 2/3 of a ton  let us take the lcm of the denominator of the ...

Q: Use a calculator to convert each of the following to degree measure to the nearest tenth of a degree...

A: The measure of angle is an amount of rotation from the initial side to the terminal side. The degree...

Q: What new technology allowed the Spanish and other Europeans to venture across the Atlantic Ocean

A: The period between the 1400s and the 1600s has been regarded as the Age of Exploration. It was the t...

Q: The cheetah is known for being extremely fast. A cheetah can run 1 meter in 0.0346812 seconds. How f...

A: Click to see the answer

Q: During  the year, TRC Corporation has the following inventory transactions.    Date Transaction Num...

A: As per the LIFO method, units that are purchased recently are issued first. So it means ending inven...

Q: A geometric sequence h starts at 16 and has a growth factor of 1.75. Sketch a graph of h showing the...

A: Given: To explain the given statement as follows, Here, The first term of the series, a=16 The growt...

Q: Q6.10. You are called in to track outbreaks of a new disease called simpox in two neighboring towns,...

A: In public health systems, epidemiological studies are very important and they project insight for fu...

Q: Calculate the number of grams of Mg needed for this reaction to release enough energy to increase th...

A: Click to see the answer

Q: accounts, adjusting entries, financial statements, and closing entries;optional end-of-period spread...

A: Given:

Q: 1986M1. The figure above shows an 80-kilogram person standing on a 20-kilogram platform suspended by...

A: mass of person = M = 80 kg mass of platform = m = 20 kg

Q: your sketch to find the absolute and local maximum and minimum values of f. (Enter your answers as a...

A: Click to see the answer

Q: Adjusting entriesOn March 31, the following data were accumulated to assist dieaccountant in prepari...

A: Adjusting entries are entries that are passed at the end of the period in order to accurately reflec...

Q: In cell G1, type Fast Track as the column heading. In cell G2, enter a formula using the AND functio...

A:  

Q: The Na+/K+/ATPase is the protein that creates an electrochemical gradient in your cells. It accompli...

A: The Na+K+-ATPase pump helps to maintain osmotic equilibrium and membrane potential in cells. It main...

Q: Joe often lies and steals, and he is very aggressive and violent. He behaves badly around others and...

A: Mental health reflects a state of subjective well-being in several life domains including emotional,...

Q: There are three industrial firms in Happy Valley.The government wants to reduce pollution to 60 unit...

A: a) Firm B would like to purchase 20 permits from another firm as it has the biggest share of lowerin...

Q: Yann's bakery operates in a perfectly competitive market where the prevailing price for a baguette (...

A: The Profit maximizing condition in Perfect competition is where Marginal cost = Price = Marginal rev...

Q: -/ 1 Question 11 of 16 View Policies Current Attempt in Progress Transgender Adults A study' of tran...

A: We have to find confidence interval  for given  data...

Q: 1. PART A: VWhich statement best identifies the central idea of the text? O A The Harlem Renaissance...

A: C is the correct option. The Harlem Renaissance was a scholarly and social restoration of African Am...

Q: Drag each tile to the correct location. Match each characteristic to the type of protist it describe...

A: The Kingdom Protista includes a broad group of eukaryotic organisms known as protists. Individual me...

Q: Steelhead trout, otherwise known as rainbow trout, have seen a population decline in the Western Uni...

A: We have to sketch the graph of the steelhead trout using the given table of values with the water te...

Q: A student dissolves a Jefferson nickel to make 100.00 mL of solution in a volumetric flask. The stud...

A: Mass of Copper in Jefferson nickel used for making the first solution is taken as ‘x’ g.Hence, molar...

Q: Write a balanced chemical equation for the standard formation reaction of solid magnesium bromide (M...

A: Standard formation reaction is a chemical equation in which one mole of a substance forms from eleme...

Q: What is the ratio of the sun's gravitational force on you to the earth's gravitational force on you?

A: Given  A person is on earth surface .  Let gravitational force on person due to sun is  Fs .... Grav...

Q: In fractional distillation, the greater the length of a fractionating column: * the lower its effici...

A: Click to see the answer

Q: a. If a constant c is added to each xi in a sample, yielding yi = xi + c, how do the sample mean and...

A: Mean: For a set of n observations, x1, x2, ... , xn mean is defined as, Median: For a frequency dis...

Q: Platinum has a density of 21.4 g/cm3. What is the mass of 5.9 cm3 of this metal?

A: Platinum has a density of 21.4 g/cm3. What is the mass of 5.9 cm3 of this metal

Q: A soccer ball is kicked 8m north. Then a teammate kicks it 6m east into the goal. What is the soccer...

A: Click to see the answer

Q: The following total liabilities and stockholders’ equity information (in millions) is provided for A...

A: Ratio of Liabilities to stockholders equity is calculated by dividing the total liabilities by total...

Q: Laiho Industries's 2020 and 2021 balance sheets (in thousands of dollars) are shown.   Laiho Indus...

A: Hi, since you have asked a question with multiple subparts we are solving the 1st 3 subparts for you...

Q: Missing amounts from financial statements   The financial statements at the end of Atlas Realty's fi...

A: Financial statements are the report that represent the financial performance, position, activities, ...