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.
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.
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.
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
// 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
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
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
Quantities that have magnitude and direction but not position. Some examples of vectors are velocity, displacement, acceleration, and force. They are sometimes called Euclidean or spatial vectors.
Expert Solution
This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.