Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

In C++ please You are designing and implementing a database for the Academy Award winners. R1/R2: You are to read in information from csv file.

In C++ please

You are designing and implementing a database for the Academy Award winners.

R1/R2: You are to read in information from csv file.

R1: You will read in actor-actress.csv which is formatted as a csv file (Ask the user for the file name). Then place the items in a Binary Search Tree, sorted by name.

Year,Award,Winner,Name,Film

The Winner field has a one if they won and a zero if they did not win.

R3/R4: Choose actor database and add a record

R5/R6: Choose actor database, search for a record, and modify the fields.

R7/R8: Choose actor database, search for a record and delete the fields.

R9/R10: Choose actor database and sort by any single (sortable) field

My code so far:

main.cpp

#include  #include  #include "Actor-Actress.h" #include "Movie.h" using namespace std; int main() { ActorBST actor ; MovieBST movie ; // menu variables int mainMenuInput; int userInputSearch; int userInputAdd; int userInputModify; int userInputDelete; int userInputExport; int userInputImport; do { /*********************Main Menu*******************/ cout << "Welcome to the Acadamy awards DataBase: " << endl; cout << "Please choose what you would like to do:" << endl; cout << "1. Search DataBase" << endl; cout << "2. Add Record to Database" << endl; cout << "3. Modify a Record of the Database" << endl; cout << "4, Delete a record from the database" << endl; cout << "5. Export Database to .CSV file" << endl; cout << "6. Import file from .CSV file"<< endl; cout << "7. Exit" << endl; cin >> mainMenuInput; if (mainMenuInput == 1) { cout << "Which DataBase would you like to Search" << endl; cout << "1. Actor-Actress Database" << endl; cout << "2. Movies Database" << endl; cin >> userInputSearch; if (userInputSearch == 1) { cout << "Search the Actor-Actress Database" << endl; string actorname; cout << "enter Actor-Actress name: "; cin >> actorname; actor.findActorNode(actorname); } else if (userInputSearch == 2) { cout << "Search the Movies DataBase" << endl; string moviename; cout <<"Enter Movie Title: "; cin >> moviename; movie.findMovieNode(moviename); } else { cout << "Please make a valid selection" << endl; cin >> userInputSearch; } } else if (mainMenuInput == 2) { cout << "Which Database would you like to add a record to: " << endl; cout << "1. Actor-Actress Database" << endl; cout << "2. Movies Database" << endl; cin >> userInputAdd; if (userInputAdd == 1) { cout << "Add record to Actor-Actress Database" << endl; //NodeActor *AddActor; //actor.addActorNode(); } else if (userInputAdd == 2) { cout << "Add record to Movies Database" << endl; //call function for MovieBST::addRecord } else { cout << "Please Make a Valid Selection" << endl; cin >> userInputAdd; } } else if (mainMenuInput == 3) { cout << "Which Database would you like to modify a record in:" << endl; cout << "1. Actor-Actress Database" << endl; cout << "2. Movies Database" << endl; cin >> userInputModify; if (userInputModify == 1) { cout << "Modify Record of the Actor-Actress Database " << endl; // call ActorBST::modifyRecord } else if (userInputModify == 2) { cout << "Modify Record of the Movie Database" << endl; // call MovieBST::modifyRecord } else { cout << "Please make a valid selection" << endl; cin >> userInputModify; } } else if (mainMenuInput == 4) { cout << "Which Database would you like to delete a record from" << endl; cout << "1. Actor-Actress Database" << endl; cout << "2. Movies Database" << endl; cin >> userInputDelete; if (userInputDelete == 1) { cout << "Delete a record from the Actor-Actress Database" << endl; //call ActorBST::deleteRecord function } else if (userInputDelete == 2) { cout << "Delete a record from the Movie Database" << endl; //call MovieBST::deleteRecord function } else { cout << "Please make a valid selection" << endl; cin >> userInputDelete; } } else if (mainMenuInput == 5) { cout << "Which Database would you like to Export to .CSV file " << endl; cout << "1. Actor-Actress Database" << endl; cout << "2. Movies Database" << endl; cin >> userInputExport; if (userInputExport == 1) { cout << "Export the Actor-Actress Database" << endl; // call file export } else if (userInputExport == 2) { cout << "Export the Movie Database" << endl; //call file export } } else if (mainMenuInput==6) { cout << "Which Database do you want to import"<< endl; cout << "1. Actor-Actress Database."<< endl; cout << "2. Movie Database."<< endl; cin >> userInputImport; if (userInputImport==1) { cout << "importing file "; actor.readInFile(); } else if (userInputImport==2) { cout << "importing file "<< endl; movie.readInFile(); } } else if (mainMenuInput == 7) { cout << "Exiting"; } else { cout << "Please make a valid Selection" << endl; cin >> mainMenuInput; } } while (mainMenuInput !=7); return 0; } 

Actor-Actress.h

#ifndef CODE_ACTOR_ACTRESS_H #define CODE_ACTOR_ACTRESS_H #include  #include  #include  using namespace std; struct NodeActor { // Actor variables string year; string award; string winner; string name; string film; //pointers NodeActor* parentNode; NodeActor* leftNode; NodeActor* rightNode; NodeActor(){}; NodeActor(string _year, string _award, string _winner, string _name, string _film) { year=_year; award=_award; winner=_winner; name=_name; film=_film; parentNode = NULL; leftNode = NULL; rightNode = NULL; } }; class ActorBST { public: ActorBST(); virtual ~ActorBST(); void printActor(); int countActorNode(); void deleteActorNode(string name); void addActorNode(string year, string award, string winner, string name, string film); void findActorNode(string name); bool isValid(); void readInFile(); private: void DeleteTree(NodeActor *node); void PrintActor(NodeActor *node); /* void FixAfterAdd(NodeMovie *node); void DeleteMovieNode(NodeMovie *del); void FixAfterDelete(NodeMovie *node); int isValid(NodeMovie *node); */ NodeActor* search(string name); NodeActor* searchActorBSTRecursive(NodeActor* node, string name); NodeActor* treeMinimum(NodeActor* node); NodeActor* root; NodeActor* null; }; 

Actor-Actress.cpp

#include #include  #include  #include  #include  #include "Actor-Actress.h" using namespace std; ActorBST :: ActorBST() { root = nullptr; } ActorBST ::~ActorBST() { DeleteTree(root); } void ActorBST::printActor() { PrintActor(root); } void ActorBST::deleteActorNode(string name) { auto node = search(name); if (!node) { cout << "Actor not found." << endl; return; } if (!node->leftNode && !node->rightNode) { //check if parent is avaliable if (node->parentNode) { if (node->parentNode->leftNode == node) { node->parentNode->leftNode = nullptr; } else { node->parentNode->rightNode = nullptr; } delete node; return; } } // node has only 1 child if (node->leftNode && !node->rightNode) { node->leftNode->parentNode = node->parentNode; //check if there is a parent node if (node->parentNode) { //check where the node is present relative to the child node if (node->parentNode->leftNode == node) { node->parentNode->leftNode = node->leftNode; } else { node->parentNode->rightNode = node->leftNode; } } else { root = root->leftNode; } delete node; return; } if(!node->leftNode && node->rightNode) { node->rightNode->parentNode=node->parentNode; //check if there is a parentNode if (node->parentNode) { if (node->parentNode->leftNode==node) { node->parentNode->leftNode=node->rightNode; } else { node->parentNode->rightNode=node->rightNode; } } else { root=root->rightNode; } delete node; return; } //node has both left and right node auto minNode = treeMinimum(node->rightNode); //copy values from node to minNode and delete minNode node->year=minNode->year; node->award=minNode->award; node->winner=minNode->winner; node->name=minNode->name; node->film=minNode->film; if (minNode->rightNode) { minNode->parentNode->rightNode=minNode->parentNode; } if (node->rightNode==minNode) { node->rightNode=minNode->rightNode; delete minNode; return; } minNode->parentNode->leftNode=minNode->rightNode; delete minNode; } void ActorBST::addActorNode(string year, string award, string winner, string name, string film) { auto node = new NodeActor(year, award, winner, name, film); if(!root) { //no root root=node; return; } //string comparison auto *temp= root; NodeActor* parentNode= nullptr; while(temp) { parentNode=temp; if (name > temp->name) { temp=temp->rightNode; } else { temp=temp->leftNode; } } node->parentNode=parentNode; if (name > parentNode->name) { parentNode->rightNode=node; } else { parentNode->leftNode=node; } } void ActorBST::findActorNode(string name) { auto foundActor=search(name); if (!foundActor) { cout << "Actor wasn't found"<< endl; } else { cout << "Actor Info: "<<endl; cout << "Year: "<< foundActor->year<<endl; cout << "Award: "<< foundActor->award<<endl; cout << "Winner: "<< foundActor->winner<< endl; cout << "Name: "<< foundActor->name<<endl; cout << "Film: "<< foundActor->film<< endl; } } void ActorBST::DeleteTree(NodeActor *node) { if (!node) { return; } DeleteTree(node->leftNode); DeleteTree(node->rightNode); //for all movies in tree cout << "Deleting: "<< node->name <<endl; delete node; node= nullptr; } void ActorBST::PrintActor(NodeActor *node) { if (!node) { return; } PrintActor(node->leftNode); cout << "Actor: "<< node->name<< endl; PrintActor(node->rightNode); } NodeActor* ActorBST::search(string name) { return searchActorBSTRecursive(root, name); } NodeActor* ActorBST::searchActorBSTRecursive(NodeActor *node, string value) { if (!node) { return nullptr; } if (node->name==value) { return node; } if (value >node->name) { return searchActorBSTRecursive(node->rightNode, value); } else { return searchActorBSTRecursive(node->leftNode, value); } } NodeActor* ActorBST::treeMinimum(NodeActor *node) { if (!node) { return nullptr; } while(node->leftNode) { node=node->leftNode; } return node; } void ActorBST::readInFile() { string filename; cout <<"what is the file name: "; cin >> filename; ifstream infile(filename); string header, year, award, winner, name, film; getline(infile, header); // cout << header< if (!infile) { cout << "file didnt open "; return; } while (getline(infile, year, ',')) { getline(infile, award, ','); getline(infile, winner, ','); getline(infile, name, ','); getline(infile, film); //make node and add to node NodeActor *actor = new NodeActor(year, award, winner, film, name); addActorNode(year, award, winner, film, name); } PrintActor(root); } Movie.h #ifndef CODE_MOVIE_H #define CODE_MOVIE_H #include #include using namespace std; struct NodeMovie { // movie variables string name; string year; string nominations; string rating; string duration; string genre1; string genre2; string release; string metacritic; string synopsis; bool isRead; //pointers NodeMovie* parentNode; NodeMovie* leftNode; NodeMovie* rightNode; NodeMovie(){}; NodeMovie(string _name, string _year, string _nominations, string _rating, string _duration, string _genre1, string _genre2, string _release, string _metacritic,string _synopsis) { name = _name; year = _year; nominations = _nominations; rating = _rating; duration = _duration; genre1 = _genre1; genre2 = _genre2; release = _release; metacritic = _metacritic; synopsis = _synopsis; parentNode = NULL; leftNode = NULL; rightNode = NULL; isRead = true; } }; class MovieBST { public: MovieBST(); virtual ~MovieBST(); void printMovie(); void deleteMovieNode(string name); void addMovieNode(string name, string year, string nominations, string rating, string duration, string genre1, string genre2, string release, string metacritic,string synopsis ); void findMovieNode(string name); bool isValid(); void readInFile(); private: void DeleteTree(NodeMovie *node); void PrintMovie(NodeMovie *node); NodeMovie* search(string name); NodeMovie* searchMovieBSTRecursive(NodeMovie* node, string name); NodeMovie* treeMinimum(NodeMovie* node); NodeMovie* root; NodeMovie* null; }; #endif //CODE_MOVIE_H Movie.cpp #include #include  #include  #include "Movie.h" using namespace std; MovieBST :: MovieBST() { root = nullptr; } MovieBST ::~MovieBST() { DeleteTree(root); } void MovieBST::printMovie() { PrintMovie(root); } void MovieBST::deleteMovieNode(string name) { auto node = search(name); if (!node) { cout << "Movie not found." << endl; return; } if (!node->leftNode && !node->rightNode) { //check if parent is avaliable if (node->parentNode) { if (node->parentNode->leftNode == node) { node->parentNode->leftNode = nullptr; } else { node->parentNode->rightNode = nullptr; } delete node; return; } } // node has only 1 child if (node->leftNode && !node->rightNode) { node->leftNode->parentNode = node->parentNode; //check if there is a parent node if (node->parentNode) { //check where the node is present relative to the child node if (node->parentNode->leftNode == node) { node->parentNode->leftNode = node->leftNode; } else { node->parentNode->rightNode = node->leftNode; } } else { root = root->leftNode; } delete node; return; } if(!node->leftNode && node->rightNode) { node->rightNode->parentNode=node->parentNode; //check if there is a parentNode if (node->parentNode) { if (node->parentNode->leftNode==node) { node->parentNode->leftNode=node->rightNode; } else { node->parentNode->rightNode=node->rightNode; } } else { root=root->rightNode; } delete node; return; } //node has both left and right node auto minNode = treeMinimum(node->rightNode); //copy values from node to minNode and delete minNode node->name=minNode->name; node->year=minNode->year; node->nominations=minNode->nominations; node->rating=minNode->rating; node->duration=minNode->duration; node->genre1=minNode->genre1; node->genre2=minNode->genre2; node->release=minNode->release; node->metacritic=minNode->metacritic; node->synopsis=minNode->synopsis; if (minNode->rightNode) { minNode->parentNode->rightNode=minNode->parentNode; } if (node->rightNode==minNode) { node->rightNode=minNode->rightNode; delete minNode; return; } minNode->parentNode->leftNode=minNode->rightNode; delete minNode; } void MovieBST::addMovieNode(string name, string year, string nominations, string rating, string duration, string genre1,string genre2, string release, string metacritic, string synopsis) { auto node = new NodeMovie(name, year,nominations,rating,duration,genre1,genre2,release,metacritic,synopsis ); if(!root) { //no root root=node; return; } //string comparison auto *temp= root; NodeMovie* parentNode= nullptr; while(temp) { parentNode=temp; if (name > temp->name) { temp=temp->rightNode; } else { temp=temp->leftNode; } } node->parentNode=parentNode; if (name > parentNode->name) { parentNode->rightNode=node; } else { parentNode->leftNode=node; } } void MovieBST::findMovieNode(string name) { auto foundMovie=search(name); if (!foundMovie) { cout << "Movie wasnt found"<< endl; } else { cout << "Movie Info: "<name<year<nominations<rating<< endl; cout << "Duration(in Mins): "<< foundMovie->duration<< endl; cout << "Genre1: "<< foundMovie->genre1<< endl; cout << "Genre2: "<< foundMovie->genre2<< endl; cout << "Release Month: "<< foundMovie->release<< endl; cout << "Synopsis: "<< foundMovie->synopsis<< endl; } } void MovieBST::DeleteTree(NodeMovie *node) { if (!node) { return; } DeleteTree(node->leftNode); DeleteTree(node->rightNode); //for all movies in tree cout << "Deleting: "<< node->name <leftNode); cout << "Movie: "<< node->name<< endl; PrintMovie(node->rightNode); } NodeMovie* MovieBST::search(string name) { return searchMovieBSTRecursive(root, name); } NodeMovie* MovieBST::searchMovieBSTRecursive(NodeMovie *node, string value) { if (!node) { return nullptr; } if (node->name==value) { return node; } if (value >node->name) { return searchMovieBSTRecursive(node->rightNode, value); } else { return searchMovieBSTRecursive(node->leftNode, value); } } NodeMovie* MovieBST::treeMinimum(NodeMovie *node) { if (!node) { return nullptr; } while(node->leftNode) { node=node->leftNode; } return node; } void MovieBST::readInFile() { string filename; cout <<"what is the file name: "; cin >> filename; ifstream infile(filename); string header,name, year, nominations, rating, duration, genre1, genre2, release, metacritic, synopsis; getline(infile, header); // cout << header<

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Financial management theory and practice

Authors: Eugene F. Brigham and Michael C. Ehrhardt

12th Edition

978-0030243998, 30243998, 324422695, 978-0324422696

Students also viewed these Programming questions