I could really use some help with this program

I cant figure out why my program wont work. heres the assignment and my source code so far.

Program Description: Mary has found a collection of books (Books.txt) and a list of her favorite authors (Authors.txt).

Your goal is to write a program for Mary, that allows her to browse both the book list and her favorite author list. The program should also display books written by her favorite authors in addition to their nationality which she does not know.

The main() function should only contain the Menu() function, which must display the available options. The program must only terminate upon the user’s command (you can include this as an option). The rest of the functionality should be invoked through functions from within Menu().

There are two .txt files. Each line in a file corresponds to an entry. You should store all information on arrays dedicated to each file.

Do NOT use global variables. If you do so there will be a deduction of 10 points from your total points.

File Description:

Books.txt

Book title
Author name
Year of publication in English language
Language originally written in
Genre
Authors.txt

Name
Date of Birth
Most Notable Book
Task 1:

Mary wants to be able to read the file. Create a Book struct that will retain all information that is present in the file. Create an array that will contain such information. From the first menu option, allow Mary to print the list. The underscores in the title and author name should be removed.

Task 2:

Similarly, Mary wants to print her favorite author List. Create an Author struct. Also, create a Date struct which will be an attribute of the Author struct, representing the date of birth. Finally, add a nationality attribute which will not be filled when reading the file. Just like in Task 1, create an authors array of type struct. From the second menu option, print the authors; the date of birth should exclude the day even though it is included in the file(whether the Date struct will contain a “day” attribute is up to you). The underscore in the author’s name and most notable work should be removed.

Task 3:

Mary wants to find books by her favorite authors in the list. The third option in the menu, should print the author, his nationality (same as language book was originally written in), and the book title. There will only be one book matched for each author.

Hints:

When trying to remove the underscores, remember that a string is an array of characters, and that each character can be manipulated.

Use separate functions for print and for reading.

Books.txt

11
The_Name_of_the_Rose Umberto_Eco 1983 Italian Mystery
Norwegian_Wood Haruki_Murakami 2000 Japanese Fiction
The_Name_of_the_Wind Patrick_Rothfuss 2007 English Fantasy
The_Girl_with_the_Dragon_Tattoo Stieg_Larsson 2005 Swedish Thriller
The_Brothers_Karamazov Fyodor_Dostoevsky 1880 Russian Fiction
Demonic_Males Richard_Wrangham 1997 English Non-Fiction
War_and_Peace Leo_Tolstoy 1899 Russian Historical-Fiction
Baudolino Umberto_Eco 2000 Italian Historical-Fiction
The_Lies_of_Locke_Lamora Scott_Lynch 2006 English Fantasy
The_Last_of_the_Wine Mary_Renault 1956 English Historical-Fiction
Brave_New_World Aldous_Huxley 1932 English Science Fiction
Author.txt

7
Haruki_Murakami 01/12/1949 A_Wild_Sheep_Chase
Leo_Tolstoy 09/09/1828 War_and_Peace
Fyodor_Dostoevsky 11/11/1821 Crime_and_Punishment
Nikos_Kazantzakis 02/18/1883 The_Last_Temptation
Charles_Bukowski 08/16/1929 Post_Office
George_Orwell 06/25/1903 1984
John_Milton 12/09/1608 Paradise_Lost

MY CODE:

#include<iostream>
#include<string>
#include<fstream>
#include<iomanip>

using namespace std;

struct Book
{
string BookTitle;
string AuthorName;
int publicationYearInEnglish;
string OriginalLanguage;
string BookGenre;
};
struct Author
{
string AuthorName;
string DateOfBirth;
string NotableBook;
};

Book* readBooks(int &count)
{
ifstream inFile("Books.txt");
string BookTitle;
string AuthorName;
int publicationYearInEnglish;
string OriginalLanguage;
string BookGenre;

int size = 11;

inFile >> size;
count = size;
Book *book = new Book[size];
for(int i=0; i<size; i++)
{
inFile>>BookTitle;inFile>>AuthorName;inFile>>publicationYearInEnglish;inFile>>OriginalLanguage;inFile>>BookGenre;

book[i].BookTitle;
book[i].AuthorName;
book[i].publicationYearInEnglish;
book[i].OriginalLanguage;
book[i].BookGenre;
}

inFile.close();
}

Author* readAuthor(int &count)
{
ifstream inFile("Author.txt");
string AuthorName;
string DateOfBirth;
string NotableBook;

int size =7;
inFile >> size;
count = size;
Author *author = new Author[size];
for(int i=0;i<size;i++)
{
inFile>>AuthorName;
inFile>>DateOfBirth;
inFile>>NotableBook;

author[i].AuthorName;
author[i].DateOfBirth;
author[i].NotableBook;
}

inFile.close();

}
string removeUnderScore(string str)
{
for (int i = 0; i<str.length(); i++)
{
if (str[i] =='_')
str[i] = ' ';
}
}

void getBook(Book *book,int book_count)
{
string name;
cout << "Enter the author name: ";
cin.ignore();
getline(cin,name);
for (int i = 0; i < book_count; i++)
{
if (book[i].AuthorName == name)
{
cout << "Author name: " << name << "\t\t" << "Book Name: " << book[i].BookTitle << "\t\t" << "Nationality: " << book[i].OriginalLanguage << endl;
}
}
cout << name << " is not present in the collection!!" << endl;
}
void printBooks(Book *book, int book_count);
void printAuthors(Author* author, int author_count);
void menu()
{
int ch;
int book_count, author_count;

Book *book = readBooks(book_count);

Author *author = readAuthor(author_count);

while (1)
{
cout << " WELCOME TO MARY'S COLLECTION " << endl;
cout<<"1. Print Books"<<endl;
cout<<"2. Print Authors"<<endl;
cout<<"3. Print Matches"<<endl;
cout<<"4. Exit"<<endl;
cout <<"Enter Selection: ";
cin >> ch;

if(ch==1)
{
printBooks(book, book_count);
}

else if (ch==2)
{
printAuthors(author, author_count);
}

else if (ch==3)
{
getBook(book,book_count);
}
else if (ch==4)
{
break;
}
}
}

int main()
{
menu();
return 0;
}

void printBooks(Book *book, int book_count)
{
cout << fixed;
cout << " Book Title Author Published Year Language Genre\n" << endl;
for (int i = 0; i < book_count; i++)
{
cout <<setw(25)<<book[i].BookTitle<<"\t" << setw(20) << book[i].AuthorName << "\t" << setw(10) << book[i].publicationYearInEnglish << "\t" << setw(10) <<book[i].OriginalLanguage << "\t" << setw(10) <<book[i].BookGenre<< endl;
}
}

void printAuthors(Author* author, int author_count)
{
cout << fixed;
cout << " Author Name Date of Birth Notable Book\n" << endl;
for (int i = 0; i < author_count; i++)
{
cout << setw(20)<< author[i].AuthorName << "\t\t" << author[i].DateOfBirth << "\t\t" << author[i].NotableBook << endl;
}
} your question here.

Topic archived. No new replies allowed.