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...


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
#include
#include
#include "functions.h"


int main()
{
char option;
vector 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"=""><>
break;
}
case 'R':
{

string mn;
cout < "movie="">
getline(cin, mn);
bool found;
//call you removeMovie() here
found = removeMovie(mn, &movies);
if (found == false)
cout < "cannot="" find="" "="">< mn=""><>
else
cout < "removed="" "="">< mn="">< "="" from="" catalog"=""><>
break;
}
case 'O':
{
string mn;
cout < "movie="" name:="">
getline(cin, mn);
cout <>
//call you movieInfo function here
movieInfo(mn, movies);
break;


}
case 'C':
{
cout < "there="" are="" "="">< movies.size()="">< "="" movies="" in="" the="" catalog"=""><>
// Call the printCatalog function here
printCatalog(movies);
break;
}
case 'F':
{
string inputFile;
bool isOpen;
cin >> inputFile;
cout < "reading="" catalog="" info="" from="" "="">< inputfile=""><>
//call you readFromFile() in here
isOpen = readFile(inputFile, &movies);
if (isOpen == false)
cout < "file="" not="" found"=""><>
break;
}
case 'W':
{ string outputFile;
bool isOpen;
cin >> outputFile;
cout < "writing="" catalog="" info="" to="" "="">< outputfile=""><>
//call you writeFromFile() in here
isOpen = writeFile(outputFile, movies);
if (isOpen == false)
cout < "file="" not="" found"=""><>
break;
}
}
if (option == 'Q')
{
cout < "quitting="">
break;
}
}
}



functions.h


#ifndef FUNCTIONS_H
#define FUNCTIONS_H


#include
#include
#include
//include necessary libraries
#include
#include
using namespace std;




// Define the structure "movie" here
struct movie {
string name;
string genre;
int year;
};
void printMenu()
{
cout <>
cout < "menu:"=""><>
cout < "a="" -="" add="" movie"=""><>
cout < "r="" -="" remove="" movie"=""><>
cout < "o="" -="" output="" movie="" info"=""><>
cout < "c="" -="" output="" catalog="" info"=""><>
cout < "f="" -="" read="" file"=""><>
cout < "w="" -="" write="" file"=""><>
cout < "q="" -="" quit="" program"=""><>
cout < "choose="" an="" option:="">
}




void printMovieInfo(const string &mn, int yr, const string &gen)
{
cout <>
cout < "name:="" "="">< mn=""><>
cout < "year:="" "="">< yr=""><>
cout < "genre:="" "="">< gen=""><>
}


// Write the definition and implementation of the printCatalog function here
void printCatalog(vector catalog) {
for(int i=0; i<(int)catalog.size(); i++)="">
printMovieInfo(catalog.at(i).name, catalog.at(i).year, catalog.at(i).genre);
cout <>
}
}


// Write the definition and implementation of the findMovie function here
int findMovie(string n,vector 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 *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 *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*/=""><>
void movieInfo(string n, vector catalog) {
int index = findMovie(n, catalog);
if(index!=-1) {
printMovieInfo(n, catalog.at(index).year, catalog.at(index).genre);
}
else {
cout < "cannot="" find="" "="">< n=""><>
}
}


// Write the definition and implementation of the readFromFile function here
bool readFile(string filename, vector *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 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=""><>
}
out.close();
return true;
}


#endif


Enter program input (optional)<br>If your code requires input values, provide them here.<br>Your program expects input<br>main.cpp<br>(Your program)<br>Run program<br>Input (from above)<br>Output (shown below)<br>Program errors displayed here<br>Program generated too much output.<br>Output restricted to 50000 characters.<br>Check program for any unterminated loops generating output.<br>Program output displayed here<br>Menu:<br>A - Add Movie<br>R - Remove Movie<br>O - Output Movie Info<br>C - Output Catalog Info<br>F - Read file<br>W - Write file<br>Q - Quit Program<br>Choose an option:<br>Menu:<br>A - Add Movie<br>R - Remove Movie<br>Output Movie Info<br>C - Output Catalog Info<br>F - Read file<br>W - Write file<br>Q - Quit Program<br>Choose an option:<br>rogramming Assignment 4 - Structs and File l/0<br>O - Output Movie Info<br>C - Output Catalog Info<br>F - Read file<br>W - Write file<br>Q - Quit Program<br>Choose an option:<br>Menu:<br>A - Add Movie<br>R<br>Remove Movie<br>O - Output Movie Info<br>C - Output Catalog Info<br>F - Read file<br>W - Write file<br>O -<br>Q - Quit Program<br>Choose an option:<br>Menu:<br>A - Add Movie<br>R -<br>Remove Movie<br>Output Movie Info<br>C - Output Catalog Info<br>O -<br>F - Read file<br>W - Write file<br>Q - Quit Program<br>O -<br>Choose an option:<br>Menu:<br>A - Add Movie<br>R - Remove Movie<br>O - Output Movie Info<br>C -<br>Output Catalog Info<br>F - Read file<br>W - Write file<br>Q - Quit Program<br>Choose an option:<br>Menu:<br>A - Add Movie<br>R - Remove Movie<br>O - Output Movie Info<br>C - Output Catalog Info<br>F - Read file<br>W - Write file<br>

Extracted 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<br>0/25<br>Testing the readFromFile function (using input.txt)<br>Compilation failed<br>main.cpp: In function 'bool testPassed (std::ofstreams)' :<br>main.cpp:32:4: error: 'readFromFile' was not declared in this scope; di<br>32 |<br>readFromFile (
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' to 'std::vec1 32 | addMovie ("Movie 1", 1, "1", movies); ^~~~~~ std::vector 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 *catalog) main.cpp:33:32: error: cannot convert 'std::vector' 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 *catalog) functions.h:61:57: note: ~~~~~ ~~~~ ~~~~^ ~~~~~ main.cpp:34:32: error: cannot convert 'std::vector' to 'std::vect 34 I addMovie ("Movie 3", 3, "3", movies); Compilation failed std::vector In file included from main.cpp :5: initializing argument 4 of 'void addMovie (st 61 | void addMovie (string n, int y, string g, vector *catalog functions.h:61:57: note: main.cpp:35:32: error: cannot convert 'std::vector' to 'std::vec1 35 | addMovie ("Movie 4", 4, "4", movies); std::vector 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 *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 "/>
Extracted 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' to 'std::vec1 32 | addMovie ("Movie 1", 1, "1", movies); ^~~~~~ std::vector 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 *catalog) main.cpp:33:32: error: cannot convert 'std::vector' 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 *catalog) functions.h:61:57: note: ~~~~~ ~~~~ ~~~~^ ~~~~~ main.cpp:34:32: error: cannot convert 'std::vector' to 'std::vect 34 I addMovie ("Movie 3", 3, "3", movies); Compilation failed std::vector In file included from main.cpp :5: initializing argument 4 of 'void addMovie (st 61 | void addMovie (string n, int y, string g, vector *catalog functions.h:61:57: note: main.cpp:35:32: error: cannot convert 'std::vector' to 'std::vec1 35 | addMovie ("Movie 4", 4, "4", movies); std::vector 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 *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
Jun 08, 2022
SOLUTION.PDF

Get Answer To This Question

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here