Hi there!
I'm working on this program that reads in info from a file containing, title, author (up to 4), publisher, isbn, price and the number of copies. This gets stored in an array of class type Book_Type.
After storing the info in the array and sorting it, a series of transactions takes place via input from another file.
An example of a transaction would be:
'P' which would call for the array to be printed
I have been able to get all of the needed transactions to work except one. The transaction I am having trouble with is 'W' which in the input file is followed by an author's name. I need to be able to search the entire array of books for books written by that specific author.
What is tripping me up is that some of the books have more than 1 author (I have the authors stored in an string array). I thought I had accounted for this but my search is only working for the books with 1 author.
I've tried a few different approaches but am at a total loss. Could someone please help me with this? I know the format is messy, but I'm not completely done writing the program yet so that is not the part I need help on. I am also not concerned with different approaches to the parts of the program I already have completed. I am only wondering about how to fix the issue I am having.
Thank you in advance!
this is what I have in main:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
|
case 'W':
{
infile.get(ch);
getline(infile, author);
found = false;
for (int x = 0; x < i; x++)
{
if (author == books[x].get_auth())
{
copies = books[x].numb_copies();
title = books[x].get_title();
found = true;
break;
}
}
if (found)
{
cout << title << " was written by " << author << endl
<< "There are " << copies << " available copies"
<< endl << endl;
}
else
{
cout << "No books by " << author << " could not be found"
<< endl << endl;
}
break;
}
|
This is what I currently have for my class function:
1 2 3 4 5 6 7
|
string Book_Type::get_auth()
{
for (int i = 0; i < 4; i++)
{
return authors[i];
}
}
|
The output I'm getting for case 'W' is below (and I know that there is a book by Cotton-tail, however this is one of the books with more than 1 author):
No books by Frank Abagnale could not be found
No books by Cotton-tail could not be found
Babies and Other Hazards of Sex was written by David Barry
There are 101 available copies