Homework Help Question & Answers

Coding in c++

I keep getting errors and i am so confused can someone please help and show the input and output ive tried so many times cant seem to get it.
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<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<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 < catalog.size(); i++) {
      out << catalog.at(i).name
<< "\t" << catalog.at(i).year << "\t" <<
catalog.at(i).genre << endl;
   }
      out.close();
      return true;
}
#endif

ERRORS.png

0 0
Add a comment
Request Professional Answer

Request Answer!

We need at least 9 more requests to produce the answer.

1 / 10 have requested this problem solution

The more requests, the faster the answer.

Request! (Login Required)


All students who have requested the answer will be notified once they are available.
Know the answer?
Add Answer to:
Coding in c++
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coin

Coins can be redeemed for fabulous gifts.

Similar Homework Help Questions
  •    moviestruct.cpp #include <iostream> #include <fstream> #include <cstdlib> #include <ostream> #include <fstream> #include <cstdlib> #include <cstring>...

       moviestruct.cpp #include <iostream> #include <fstream> #include <cstdlib> #include <ostream> #include <fstream> #include <cstdlib> #include <cstring> using namespace std; typedef struct{ int id; char title[250]; int year; char rating[6]; int totalCopies; int rentedCopies; }movie; int loadData(ifstream &infile, movie movies[]); void printAll(movie movies[], int count); void printRated(movie movies[], int count); void printTitled(movie movies[], int count); void addMovie(movie movies[],int &count); void returnMovie(movie movies[],int count); void rentMovie(movie movies[],int count); void saveToFile(movie movies[], int count, char *filename); void printMovie(movie &m); int find(movie movies[], int...

  • I need help with a program. My program wont run. I cant fix the errors. Its...

    I need help with a program. My program wont run. I cant fix the errors. Its mainly c++. I am trying to run it in dev c++. if anyone can fix this program i will be glad. #include <iostream> #include <fstream> #include <string> #include <vector> #include <map> #include <iomanip> #include <algorithm> #include <stdlib.h> #include <time.h> using namespace std; bool buildMap(); void writeIndex(); void AddWordtoMap(string); void writeSorted(); void Filter(); map <string, int> jobMap; map <string, int> filterMap; typedef pair<string, int> myPair;...

  • C++ getline errors I am getting getline is undefined error messages. I would like the variables...

    C++ getline errors I am getting getline is undefined error messages. I would like the variables to remain as strings. Below is my code. #include <iostream> #include<string.h> using namespace std; int index = 0; // variable to hold how many customers are entered struct Address //Structure for the address. { int street; int city; int state; int zipcode; }; // Customer structure struct Customer { string firstNm, lastNm; Address busAddr, homeAddr; }; // Functions int displayMenu(); Customer getCustomer(); void showCustomer(Customer);...

  • Using an object-oriented approach, write a program to read a file containing movie data (Tile, Director,...

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

  • 9.10 Lab 9 Program 1: Data visualization

    C++ programmingThis my code I keep having trouble of spacing:#include <iostream>#include <string>#include <vector>#include<iomanip> //For using setw()using namespace std;int countComma(string s){ //Counting commas in the string functionint count=0;for(int i=0;i<s.size();i++){if(s[i]==',')count++;}return count;}bool check_number(string str) { //For checking the part after comma if it is valid integerfor (int i = 0; i < str.length(); i++)if (isdigit(str[i]) == false)return false;return true;}int main(){string title,column1,column2;cout << "Enter a title for the data:\n";getline(cin,title);cout<<"You entered: "<<title<<endl;cout << "Enter the column 1 header:\n";getline(cin,column1);cout<<"You entered: "<<column1<<endl;cout << "Enter the column 2...

  • C++ Language I have a class named movie which allows a movie object to take the...

    C++ Language I have a class named movie which allows a movie object to take the name, movie and rating of a movie that the user inputs. Everything works fine but when the user enters a space in the movie's name, the next function that is called loops infinetly. I can't find the source of the problem. Down below are my .cpp and .h file for the program. #include <iostream> #include "movie.h" using namespace std; movie::movie() { movieName = "Not...

  • I NEED A PSEUDOCODE ALGORITHM FOR THIS CODE PLEASE C++: #include #include #include #include using...

    I NEED A PSEUDOCODE ALGORITHM FOR THIS CODE PLEASE C++: #include #include #include #include using namespace std; int NumOfEmployees(); int TotDaysAbsent(int); double AverageAbsent(int, int); int main() {         cout << endl << "Calculate the average number of days a company's employees are absent." << endl << endl;      int numOfEmployees = NumOfEmployees();         TotDaysAbsent(numOfEmployees);    return 0; } int NumOfEmployees() {    int numOfEmployees = 0;     cout << "Please enter the number of employees in the company: ";         cin >> numOfEmployees;     while(numOfEmployees <= 0)     {            ...

  • The following C++ code include 3 files: Patient.h, Patient.cpp and Main.cpp. The program basically creates and stores patient records. The original code has everything in a single .cpp file. I tried t...

    The following C++ code include 3 files: Patient.h, Patient.cpp and Main.cpp. The program basically creates and stores patient records. The original code has everything in a single .cpp file. I tried to divide the code in 3 parts (Patient.h, Patient.cpp and Main.cpp), but it is giving me errors. Patient.h #ifndef PATIENT_H #define PATIENT_H #include <string> #include "Patient.cpp" using namespace std; class Patient{ private : string firstname; string lastname; string location; static int cnt; int id; public : Patient(string, string, string);...

  • Hello, I have some errors in my C++ code when I try to debug it. I...

    Hello, I have some errors in my C++ code when I try to debug it. I tried to follow the requirements stated below: Code: // Linked.h #ifndef INTLINKEDQUEUE #define INTLINKEDQUEUE #include <iostream> usingnamespace std; class IntLinkedQueue { private: struct Node { int data; Node *next; }; Node *front; // -> first item Node *rear; // -> last item Node *p; // traversal position Node *pp ; // previous position int size; // number of elements in the queue public: IntLinkedQueue();...

  • CODES: main.cpp #include <iostream> #include <string> #include "ShoppingCart.h" using namespace std; char PrintMenu() { char answer;...

    CODES: main.cpp #include <iostream> #include <string> #include "ShoppingCart.h" using namespace std; char PrintMenu() { char answer; cout << "MENU" << endl; cout << "a - Add item to cart" << endl; cout << "d - Remove item from cart" << endl; cout << "c - Change item quantity" << endl; cout << "i - Output items' descriptions" << endl; cout << "o - Output shopping cart" << endl; cout << "q - Quit" << endl << endl; while (true) {...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
Active Questions
ADVERTISEMENT