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
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.
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...
Write a C++ program which performs +, -, *, / and $ on hexadecimal operands. The maximum length of any operand or a solution is 40 digits. The input will be in the following format: Op1 op op2 = There is no space between operands and operator. Note 5/2 = quotient 2, remainder 1 2$3 = 8 The output should be of the form 2*3=6. Read date from a file. TEST DATA (input.txt): AAAA+BBF= BFD+2DE= 100*AA= 100$5= 100/F= 10000000000000-1= AAAAABBBBBCCCCCDDDDDEEEEEFFFFF-ABCDEF0123456789ABCDEF=...
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...
(Coding done in c++, Virtual Studio) Having a problem with the line trying to compare the date of birth. **fall.sort(compare_DOB); //Here lies your error** #include <fstream> #include <iostream> #include <string> #include <list> #include <cctype> using namespace std; const char THIS_TERM[] = "fall.txt"; const string HEADER = "\nWhat do you want to do ?\n\n" "\t. Add a new friend name and DOB ? \n" "\t. Edit/Erase a friend record ? \n" "\t. Sort a Friend's record ? \n"...
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);...
Fix my code, if I the song or the artist name is not on the vector, I want to user re-enter the correct song or artist name in the list, so no bug found in the program #include <iostream> #include <vector> #include <string> #include <algorithm> using namespace std; class musicList{ private: vector<string> songName; vector<string> artistName; public: void addSong(string sName, string aName){ songName.push_back(sName); artistName.push_back(aName); } void deleteSongName(string sName){ vector<string>::iterator result = find(songName.begin(), songName.end(), sName); if (result == songName.end()){ cout << "The...
Can somebody help me with this coding the program allow 2 players play tic Tac Toe. however, mine does not take a turn. after player 1 input the tow and column the program eliminated. I want this program run until find a winner. also can somebody add function 1 player vs computer mode as well? Thanks! >>>>>>>>>>>>>Main program >>>>>>>>>>>>>>>>>>>>>>> #include "myheader.h" int main() { const int NUM_ROWS = 3; const int NUM_COLS = 3; // Variables bool again; bool won;...
*HOW DO I CHANGE THIS FROM A VOID FUNCTION TO A NON-VOID WITH PARAMETERS?* #include<iostream> #include<fstream> #include<string> using namespace std; void studentStats() { ifstream inputFile; inputFile.open("outFile.txt"); string studentData; string studentID; string ID, exam1, exam2, exam3; string header; cout << "Enter a Student ID: "; cin >> studentID; bool found =false; while (inputFile) { inputFile >> ID; inputFile >> exam1; inputFile >> exam2; inputFile >> exam3; if (ID.compare(studentID)==0) { cout << ID << " " << exam1 << " " <<...
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) { ...
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) {...