I was commissioned to create a program that searches for more than 400 films (linked to each other using a linked list) by name, genre, year, rating, lead actor, etc.
There is a catch, but we only allow the ONE search function to pre-search through the linked list. In addition, within this search function, we are allowed only one thing, and the loop - I assume that in my case it will be something like ...
while (moviePtr != NULL)
Obviously, there will be many different copies of them, if this is a search for an actor or a search for a genre. In the case of an actor, genre, rating, year, sub-genre and supporting actor, he must output each individual copy. (for example, if Kevin Bacon was in x-men and a laptop, he should output not only one of them (the output file is not a screen)).
I was completely immersed in these restrictions that we were given. How does my search function handle different types of data? (year and rating must be declared as integers). How does he know what exactly I'm looking for? If I am looking for an actor, I do not want him to look for the name either.
Any suggestions on how to get started and get started are greatly appreciated.
EDIT: Hi everyone, I thought I was updating you guys what I did. I have 3 different search functions. One for numerical values (year and rating), 1 for genre and actors, and finally one for name.
Here is the code for all three. First of all, the title.
void TitleSearched(MovieNode*head,
string titleSearched,
ofstream& outFile)
{
MovieNode* moviePtr;
bool found;
moviePtr = head;
found = false;
while (moviePtr !=NULL & !found)
{
if (moviePtr-> title == titleSearched)
{
found = true;
}
else
{
moviePtr = moviePtr -> next;
}
}
if (found)
{
cout << endl << titleSearched << " has been found!\n";
TitleOutput (moviePtr,outFile);
}
else
{
cout << endl << titleSearched << " was not found.\n";
}
}
now search by year / rating.
int NumSearched(MovieNode* head, int numSearched)
{
int instances;
MovieNode* moviePtr;
ofstream outFile;
moviePtr = head;
instances = 0;
while (moviePtr !=NULL)
{
if (moviePtr-> year == numSearched)
{
instances = instances +1;
NumOutList(moviePtr,outFile,"year",numSearched,instances);
moviePtr = moviePtr -> next;
}
else if (moviePtr->rating == numSearched)
{
instances = instances +1;
NumOutList(moviePtr,outFile,"rating",numSearched,instances);
moviePtr = moviePtr -> next;
}
else
{
moviePtr = moviePtr ->next;
}
}
return instances;
}
Finally, search for the genre / actors.
int ItemSearch (MovieNode* head,string itemSearched, ofstream& outFile)
{
int instances;
MovieNode* moviePtr;
moviePtr = head;
instances = 0;
while (moviePtr !=NULL)
{
if (moviePtr-> genre == itemSearched || moviePtr ->subGenre == itemSearched)
{
instances = instances +1;
OutList(moviePtr,outFile,"Genre",itemSearched,instances);
moviePtr = moviePtr -> next;
}
else if (moviePtr->leadActor == itemSearched || moviePtr->supportActor == itemSearched)
{
instances = instances +1;
OutList(moviePtr,outFile,"Actor",itemSearched,instances);
moviePtr = moviePtr -> next;
}
else
{
moviePtr = moviePtr ->next;
}
}
return instances;
}
I wanted to remind you what my task is. 1. Combine these three search functions into one 2. there is only ONE, and the loop in the search 3. only one return in any given function (however, id assumes that this will be the void function when combined)
My main problem I beileve is my ints and strings. I am not allowed to declare a rating or year as strings. And only the code format when combing all three as a whole causes me a headache.