In c++. I have been stuck on this problem. I am not sure i keep getting errors can someone please help. The read file and write file seems to be wrong i am not sure please help!  Here is the input.

Microsoft Visual C#
7th Edition
ISBN:9781337102100
Author:Joyce, Farrell.
Publisher:Joyce, Farrell.
Chapter5: Looping
Section: Chapter Questions
Problem 7RQ
icon
Related questions
Question

In c++. I have been stuck on this problem. I am not sure i keep getting errors can someone please help. The read file and write file seems to be wrong i am not sure please help! 

Here is the input.txt

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()
{
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;
break;
}
case 'W':
{ string outputFile;
bool isOpen;
cin >> outputFile;
cout << "Writing catalog info to " << outputFile << endl;
//call you writeFromFile() in here
isOpen = writeFile(outputFile, movies);
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
#include <fstream>
#include <sstream>
using namespace std;


// Define the structure "movie" here
struct movie {
string name;
string genre;
int year;
};
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
void printCatalog(vector<movie> catalog) {
for(int i=0; i<(int)catalog.size(); i++) {
printMovieInfo(catalog.at(i).name, catalog.at(i).year, catalog.at(i).genre);
cout << endl;
}
}

// Write the definition and implementation of the findMovie function here
int findMovie(string n,vector<movie> catalog) {
for(int i=0; i<(int)catalog.size(); i++) {
if(catalog.at(i).name.compare(n)==0) {
return i;
}
}
return -1;
}

// Write the definition and implementation of the addMovie function here
void addMovie(string n, int y, string g, vector<movie> *catalog) {
movie m;
m.name = n;
m.year = y;
m.genre = g;
catalog->push_back(m);
}

// Write the definition and implementation of the removeMovie function here
bool removeMovie(string n, vector<movie> *catalog) {
int index = findMovie(n, *catalog);
if(index!=-1) {
catalog->erase(catalog->begin() + index);
return true;
}
return false;
}

// 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;
void movieInfo(string n, vector<movie> catalog) {
int index = findMovie(n, catalog);
if(index!=-1) {
printMovieInfo(n, catalog.at(index).year, catalog.at(index).genre);
}
else {
cout << "Cannot find " << n << endl;
}
}

// Write the definition and implementation of the readFromFile function here
bool readFile(string filename, vector <movie> *catalog) {
ifstream in(filename);
string line;
if(!in.is_open()) {
return false;
}
while(getline(in, line)) {
int i = 0;
movie m;
stringstream ss(line);
string token;
while(getline(ss, token, '\t')) {
if(i==0) {
m.name = token;
} else if(i==1) {
m.year = stoi(token);
} else(i==2); {
m.genre = token;
i = -1;
}
i++;
}
catalog->push_back(m);
}
in.close();
return true;
}

// Write the definition and implementation of the writeToFile function here
bool writeFile(string filename, vector<movie> catalog) {
ofstream out(filename);
if(!out.is_open()) {
return false;
}
for(int i = 0; i <(int)catalog.size(); i++) {
out << catalog.at(i).name << "\t" << catalog.at(i).year << "\t" << catalog.at(i).genre << endl;
}
out.close();
return true;
}

#endif

Enter program input (optional)
If your code requires input values, provide them here.
Your program expects input
main.cpp
(Your program)
Run program
Input (from above)
Output (shown below)
Program errors displayed here
Program generated too much output.
Output restricted to 50000 characters.
Check program for any unterminated loops generating output.
Program output displayed here
Menu:
A - Add Movie
R - Remove Movie
O - Output Movie Info
C - Output Catalog Info
F - Read file
W - Write file
Q - Quit Program
Choose an option:
Menu:
A - Add Movie
R - Remove Movie
Output Movie Info
C - Output Catalog Info
F - Read file
W - Write file
Q - Quit Program
Choose an option:
rogramming Assignment 4 - Structs and File l/0
O - Output Movie Info
C - Output Catalog Info
F - Read file
W - Write file
Q - Quit Program
Choose an option:
Menu:
A - Add Movie
R
Remove Movie
O - Output Movie Info
C - Output Catalog Info
F - Read file
W - Write file
O -
Q - Quit Program
Choose an option:
Menu:
A - Add Movie
R -
Remove Movie
Output Movie Info
C - Output Catalog Info
O -
F - Read file
W - Write file
Q - Quit Program
O -
Choose an option:
Menu:
A - Add Movie
R - Remove Movie
O - Output Movie Info
C -
Output Catalog Info
F - Read file
W - Write file
Q - Quit Program
Choose an option:
Menu:
A - Add Movie
R - Remove Movie
O - Output Movie Info
C - Output Catalog Info
F - Read file
W - Write file
Transcribed Image Text:Enter program input (optional) If your code requires input values, provide them here. Your program expects input main.cpp (Your program) Run program Input (from above) Output (shown below) Program errors displayed here Program generated too much output. Output restricted to 50000 characters. Check program for any unterminated loops generating output. Program output displayed here Menu: A - Add Movie R - Remove Movie O - Output Movie Info C - Output Catalog Info F - Read file W - Write file Q - Quit Program Choose an option: Menu: A - Add Movie R - Remove Movie Output Movie Info C - Output Catalog Info F - Read file W - Write file Q - Quit Program Choose an option: rogramming Assignment 4 - Structs and File l/0 O - Output Movie Info C - Output Catalog Info F - Read file W - Write file Q - Quit Program Choose an option: Menu: A - Add Movie R Remove Movie O - Output Movie Info C - Output Catalog Info F - Read file W - Write file O - Q - Quit Program Choose an option: Menu: A - Add Movie R - Remove Movie Output Movie Info C - Output Catalog Info O - F - Read file W - Write file Q - Quit Program O - Choose an option: Menu: A - Add Movie R - Remove Movie O - Output Movie Info C - Output Catalog Info F - Read file W - Write file Q - Quit Program Choose an option: Menu: A - Add Movie R - Remove Movie O - Output Movie Info C - Output Catalog Info F - Read file W - Write file
1: Unit test a
0/25
Testing the readFromFile function (using input.txt)
Compilation failed
main.cpp: In function 'bool testPassed (std::ofstreams)' :
main.cpp:32:4: error: 'readFromFile' was not declared in this scope; di
32 |
readFromFile ("input.txt", movies) :
Compilation failed
readFile
>
2: Compare output ^
25 / 25
Menu:
A - Add Movie
R - Remove Movie
Output Movie Info
C - Output Catalog Info
F - Read file
W - Write file
Q - Quit Program
Choose an option: Movie Name: Year: Genre: Added Free Guy to the catalog
Menu:
A - Add Movie
R - Remove Movie
O - Output Movie Info
C - Output Catalog Info
F
Read file
W - Write file
Q - Quit Program
Choose an option: Writing catalog info to output.txt
Menu:
A - Add Movie
R - Remove Movie
O - Output Movie Info
Output Catalog Info
F - Read file
W - Write file
Q - Quit Program
Choose an option: Quitting Program
A
Free Guy
2021
Input
Comedy
W
output.txt
Free Guy
Your file content
2021
Comedy
3: Compare output a
0/ 25
Output differs. See highlights below.
Special character legend
A.
lalaland
2008
love
A
Free Guy
2021
Input
Comedy
Free Guy
F
input.txt
Menu:
A - Add Movie
R - Remove Movie
O - Output Movie Info
C - Output Catalog Info
F - Read file
W - Write file
Q - Quit Program
Choose an option: Movie Name: Year: Genre: Added lalaland to the catalog
Menu:
A - Add Movie
R - Remove Movie
O - Output Movie Info
C - Output Catalog Info
F - Read file
W - Write file
Q - Quit Program
Choose an option: Movie Name: Year: Genre: Added Free Guy to the catalog
Menu:
A - Add Movie
R - Remove Movie
O - Output Movie Info
C - Output Catalog Info
F - Read file
W - Write file
Q - Quit Program
Choose an option: Movie Name:
Name: Free Guy
Year: 2021
Genre : Comedy
Menu:
A - Add Movie
R - Remove Movie
O - Output Movie Info
C - Output Catalog Info
F - Read file
W - Write file
Q - Quit Program
Choose an option: Reading catalog info from input.txt
Menu:
A - Add Movie
R - Remove Movie
O - Output Movie Info
C - Output Catalog Info
F - Read file
W - Write file
Q - Quit Program
Choose an option: There are 17 movies in the catalog
Name: lalaland
Year: 2008
Genre : love
Name: Free Guy
Year: 2021
Genre : Comedy
Name: Movie 1
Year: -1
Genre : Movie 1.
Name: 1d
Year: -1d
Genre: 1
Your output
Name: Genreld
Year: -1d
Genre: Genreld
Name: Movie 2
Year: -1
Genre : Movie 2
Name: 2
Year: -14
Genre : 2
Name: Genre2
Year: -1
Genre : Genre2d
Name: Movie 3
Year: -1d
Genre: Movie 3
Name: 3.
Year: -1
Genre : 3l
Name: Genre3
Year: -1
Genre: Genre3
Name: Movie 4
Year: -14
Genre: Movie 4
Name: 4.
Year: -1l
Genre : 4
Name: Genre4
Year: -1
Genre: Genre4.
Name: Movie 5
Year: -14
Genre: Movie 5
Name: 5
Year: -14
Genre: 5
Name: Genre5
Year: -1
Genre : Genre5
Menu:
A - Add Movie
R - Remove Movie
O - Output Movie Info
C - Output Catalog Info
F - Read file
W - Write file
Q - Quit Program
Choose an option: Quitting Program
Menu:
A - Add Movie
R - Remove Movie
O - Output Movie Info
C - Output Catalog Info
F - Read file
W - Write file
Q - Quit Program
Choose an option: Movie Name: Year: Genre: Added lalaland to the catalog
Menu:
A - Add Movie
R - Remove Movie
O - Output Movie Info
C - Output Catalog Info
F - Read file
W - Write file
Q - Quit Program
Choose an option: Movie Name: Year: Genre: Added Free Guy to the catalog
Menu:
A - Add Movie
R - Remove Movie
O - Output Movie Info
C - Output Catalog Info
F - Read file
W - Write file
Q - Quit Program
Choose an option: Movie Name:
Name: Free Guy
Year: 2021
Genre: Comedy
Menu:
A - Add Movie
R - Remove Movie
O - Output Movie Info
C - Output Catalog Info
F - Read file
W - Write file
Q - Quit Program
Choose an option: Reading catalog info from input.txt
Menu:
Expected output
A - Add Movie
R - Remove Movie
O - Output Movie Info
C - Output Catalog Info
F - Read file
W - Write file
Q - Quit Program
Choose an option: There are 7 movies in the catalog
Name: lalaland
Year: 2008
Genre: love
Name: Free Guy
Year: 2021
Genre : Comedy
Name: Movie 1
Year: 1
Genre: Genrel
Name: Movie 2
Year: 2
Genre: Genre2
Name: Movie 3
Year: 3
Genre: Genre3
Name: Movie 4
Year: 4
Genre : Genre4
Name: Movie 5
Year: 5
Genre : Genre5
Menu:
A - Add Movie
R - Remove Movie
O - Output Movie Info
C - Output Catalog Info
F - Read file
W - Write file
Q - Quit Program
Choose an option: Quitting Program
4: Unit test A
0/25
Testing readFromFile and write ToFile
Compilation failed
main.cpp: In function 'bool testPassed (std::ofstreama)' :
main.cpp:32:32: error: cannot convert 'std::vector<movie>' to
'std::vec1
32 |
addMovie ("Movie 1", 1, "1", movies);
^~~~~~
std::vector<movie>
In file included from main.cpp :5:
functions.h:61:57: note:
initializing argument 4 of 'void addMovie (sto
61 | void addMovie (string n,
int y, string g, vector<movie> *catalog)
main.cpp:33:32: error: cannot convert
'std::vector<movie>' to 'std:: vect
33 |
addMovie ("Movie 2", 2, "2", movies);
nming Assignment 4- Structs and File I/0
In file included from main.cpp :5:
initializing argument 4 of 'void addMovie (ste
61 | void addMovie (string n, int y, string g, vector<movie> *catalog)
functions.h:61:57: note:
~~~~~ ~~~~ ~~~~^ ~~~~~
main.cpp:34:32: error: cannot convert
'std::vector<movie>' to 'std::vect
34 I
addMovie ("Movie 3", 3, "3", movies);
Compilation failed
std::vector<movie>
In file included from main.cpp :5:
initializing argument 4 of 'void addMovie (st
61 | void addMovie (string n, int y, string g, vector<movie> *catalog
functions.h:61:57: note:
main.cpp:35:32: error: cannot convert
'std::vector<movie>' to
'std::vec1
35 |
addMovie ("Movie 4", 4, "4", movies);
std::vector<movie>
In file included from main.cpp:5:
functions.h:61:57: note:
initializing argument 4 of 'void addMovie (sto
61 | void addMovie (string n,
int y, string g, vector<movie> *catalog
main.cpp:37:4: error: 'writeToFile'
was not declared in this scope; did
37 |
writeToFile ("output .txt", movies);
writeFile
main.cpp:38:4: error: 'readFromFile' was not declared in this scope; die
38 |
readFromFile ("output.txt", movies2);
readFile
Transcribed Image Text:1: Unit test a 0/25 Testing the readFromFile function (using input.txt) Compilation failed main.cpp: In function 'bool testPassed (std::ofstreams)' : main.cpp:32:4: error: 'readFromFile' was not declared in this scope; di 32 | readFromFile ("input.txt", movies) : Compilation failed readFile > 2: Compare output ^ 25 / 25 Menu: A - Add Movie R - Remove Movie Output Movie Info C - Output Catalog Info F - Read file W - Write file Q - Quit Program Choose an option: Movie Name: Year: Genre: Added Free Guy to the catalog Menu: A - Add Movie R - Remove Movie O - Output Movie Info C - Output Catalog Info F Read file W - Write file Q - Quit Program Choose an option: Writing catalog info to output.txt Menu: A - Add Movie R - Remove Movie O - Output Movie Info Output Catalog Info F - Read file W - Write file Q - Quit Program Choose an option: Quitting Program A Free Guy 2021 Input Comedy W output.txt Free Guy Your file content 2021 Comedy 3: Compare output a 0/ 25 Output differs. See highlights below. Special character legend A. lalaland 2008 love A Free Guy 2021 Input Comedy Free Guy F input.txt Menu: A - Add Movie R - Remove Movie O - Output Movie Info C - Output Catalog Info F - Read file W - Write file Q - Quit Program Choose an option: Movie Name: Year: Genre: Added lalaland to the catalog Menu: A - Add Movie R - Remove Movie O - Output Movie Info C - Output Catalog Info F - Read file W - Write file Q - Quit Program Choose an option: Movie Name: Year: Genre: Added Free Guy to the catalog Menu: A - Add Movie R - Remove Movie O - Output Movie Info C - Output Catalog Info F - Read file W - Write file Q - Quit Program Choose an option: Movie Name: Name: Free Guy Year: 2021 Genre : Comedy Menu: A - Add Movie R - Remove Movie O - Output Movie Info C - Output Catalog Info F - Read file W - Write file Q - Quit Program Choose an option: Reading catalog info from input.txt Menu: A - Add Movie R - Remove Movie O - Output Movie Info C - Output Catalog Info F - Read file W - Write file Q - Quit Program Choose an option: There are 17 movies in the catalog Name: lalaland Year: 2008 Genre : love Name: Free Guy Year: 2021 Genre : Comedy Name: Movie 1 Year: -1 Genre : Movie 1. Name: 1d Year: -1d Genre: 1 Your output Name: Genreld Year: -1d Genre: Genreld Name: Movie 2 Year: -1 Genre : Movie 2 Name: 2 Year: -14 Genre : 2 Name: Genre2 Year: -1 Genre : Genre2d Name: Movie 3 Year: -1d Genre: Movie 3 Name: 3. Year: -1 Genre : 3l Name: Genre3 Year: -1 Genre: Genre3 Name: Movie 4 Year: -14 Genre: Movie 4 Name: 4. Year: -1l Genre : 4 Name: Genre4 Year: -1 Genre: Genre4. Name: Movie 5 Year: -14 Genre: Movie 5 Name: 5 Year: -14 Genre: 5 Name: Genre5 Year: -1 Genre : Genre5 Menu: A - Add Movie R - Remove Movie O - Output Movie Info C - Output Catalog Info F - Read file W - Write file Q - Quit Program Choose an option: Quitting Program Menu: A - Add Movie R - Remove Movie O - Output Movie Info C - Output Catalog Info F - Read file W - Write file Q - Quit Program Choose an option: Movie Name: Year: Genre: Added lalaland to the catalog Menu: A - Add Movie R - Remove Movie O - Output Movie Info C - Output Catalog Info F - Read file W - Write file Q - Quit Program Choose an option: Movie Name: Year: Genre: Added Free Guy to the catalog Menu: A - Add Movie R - Remove Movie O - Output Movie Info C - Output Catalog Info F - Read file W - Write file Q - Quit Program Choose an option: Movie Name: Name: Free Guy Year: 2021 Genre: Comedy Menu: A - Add Movie R - Remove Movie O - Output Movie Info C - Output Catalog Info F - Read file W - Write file Q - Quit Program Choose an option: Reading catalog info from input.txt Menu: Expected output A - Add Movie R - Remove Movie O - Output Movie Info C - Output Catalog Info F - Read file W - Write file Q - Quit Program Choose an option: There are 7 movies in the catalog Name: lalaland Year: 2008 Genre: love Name: Free Guy Year: 2021 Genre : Comedy Name: Movie 1 Year: 1 Genre: Genrel Name: Movie 2 Year: 2 Genre: Genre2 Name: Movie 3 Year: 3 Genre: Genre3 Name: Movie 4 Year: 4 Genre : Genre4 Name: Movie 5 Year: 5 Genre : Genre5 Menu: A - Add Movie R - Remove Movie O - Output Movie Info C - Output Catalog Info F - Read file W - Write file Q - Quit Program Choose an option: Quitting Program 4: Unit test A 0/25 Testing readFromFile and write ToFile Compilation failed main.cpp: In function 'bool testPassed (std::ofstreama)' : main.cpp:32:32: error: cannot convert 'std::vector<movie>' to 'std::vec1 32 | addMovie ("Movie 1", 1, "1", movies); ^~~~~~ std::vector<movie> In file included from main.cpp :5: functions.h:61:57: note: initializing argument 4 of 'void addMovie (sto 61 | void addMovie (string n, int y, string g, vector<movie> *catalog) main.cpp:33:32: error: cannot convert 'std::vector<movie>' to 'std:: vect 33 | addMovie ("Movie 2", 2, "2", movies); nming Assignment 4- Structs and File I/0 In file included from main.cpp :5: initializing argument 4 of 'void addMovie (ste 61 | void addMovie (string n, int y, string g, vector<movie> *catalog) functions.h:61:57: note: ~~~~~ ~~~~ ~~~~^ ~~~~~ main.cpp:34:32: error: cannot convert 'std::vector<movie>' to 'std::vect 34 I addMovie ("Movie 3", 3, "3", movies); Compilation failed std::vector<movie> In file included from main.cpp :5: initializing argument 4 of 'void addMovie (st 61 | void addMovie (string n, int y, string g, vector<movie> *catalog functions.h:61:57: note: main.cpp:35:32: error: cannot convert 'std::vector<movie>' to 'std::vec1 35 | addMovie ("Movie 4", 4, "4", movies); std::vector<movie> In file included from main.cpp:5: functions.h:61:57: note: initializing argument 4 of 'void addMovie (sto 61 | void addMovie (string n, int y, string g, vector<movie> *catalog main.cpp:37:4: error: 'writeToFile' was not declared in this scope; did 37 | writeToFile ("output .txt", movies); writeFile main.cpp:38:4: error: 'readFromFile' was not declared in this scope; die 38 | readFromFile ("output.txt", movies2); readFile
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 4 steps with 3 images

Blurred answer
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Microsoft Visual C#
Microsoft Visual C#
Computer Science
ISBN:
9781337102100
Author:
Joyce, Farrell.
Publisher:
Cengage Learning,
C++ for Engineers and Scientists
C++ for Engineers and Scientists
Computer Science
ISBN:
9781133187844
Author:
Bronson, Gary J.
Publisher:
Course Technology Ptr
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning