Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Objectives: The main objective of this assignment is checking students ability to implement membership functions. After completing this assignment, students will be able to: implement

Objectives: The main objective of this assignment is checking students ability to implement membership functions. After completing this assignment, students will be able to:

implement member functions

convert a member function into a standalone function

convert a standalone function into a member function

call member functions

implement constructors

use structs for function overloading Problem description: In this assignment, we will revisit Assignment #1. Mary has now created a small commercial library and has managed to collect sales data. She wants to be able to print the books based on sales, and the list of authors based on their date of birth. This assignment needs the structs Book, Author, Date, and Library.

Processing inventory: She wants to display the books by popularity, thus the program must print the books based on sales, from highest to lowest. You will need to save the output into a text file named OrderedBooks.txt. Utilize the Book struct to implement the desired functionality.

Similarly, Mary is interested in displaying the authors by age, printing the oldest authors first. An output filed OrderedAuthors.txt should be created. Appropriate operations must be implemented inside the Author struct, and properly use the Data struct to compare author ages.

Finally, utilize the Library struct to store the lists of authors and books, and contain the functionality that the librarian requires.

You must use both member functions and non-member functions. One of the Book or Author sorting mechanisms must be implemented via member function (you can choose which) and the other with a non-member function.

You must use constructors to initialize all data variables in structs with default values at the beginning of the program. Use of global variables will incur a deduction of 10 points from your total points.

Assg1 code

#include  #include  #include  #include  #include  using namespace std; struct Date { int month; int day; int year; }; struct Author { string name; Date birth; string notable_work; string nationality; }; struct Book { string title; string author; int release_year; string language; string genre; }; void Menu(); void ReadBooks(ifstream& inFile, Book *books, int nun_books); void ReadAuthors(ifstream& inFile, Author *authors, int num_authors); void PrintBooks(Book *books, int size); void PrintAuthors(Author *authors, int size); void FindMatches(Book *books, Author *authors, int book_size, int author_size); string RemoveUnderScore(string word); int main() { Menu(); return 0; } void Menu() { ifstream inAuthors; ifstream inBooks; int input; redo: cout<>input; if(cin.fail() == true) { system("CLS"); cout<<"Invalid Input"<>num_books; Book books[num_books]; ReadBooks(inBooks, books, num_books); PrintBooks(books, num_books); inBooks.close(); } else if(input == 2) { system("CLS"); inAuthors.open("Authors.txt"); int num_authors; inAuthors>>num_authors; Author authors[num_authors]; ReadAuthors(inAuthors, authors, num_authors); PrintAuthors(authors, num_authors); inAuthors.close(); } else if(input == 3) { system("CLS"); inAuthors.open("Authors.txt"); inBooks.open("Books.txt"); int num_authors; inAuthors>>num_authors; Author authors[num_authors]; ReadAuthors(inAuthors, authors, num_authors); int num_books; inBooks>>num_books; Book books[num_books]; ReadBooks(inBooks, books, num_books); FindMatches(books, authors, num_books, num_authors); inBooks.close(); inAuthors.close(); } else goto end; goto redo; end: cout<>books[i].title; books[i].title= RemoveUnderScore(books[i].title); inFile>>books[i].author; books[i].author = RemoveUnderScore(books[i].author); inFile>>books[i].release_year; inFile>>books[i].language; inFile>>books[i].genre; } } void PrintBooks(Book *books, int size) { cout<>authors[i].name; authors[i].name = RemoveUnderScore(authors[i].name); inFile>>b_date; temp= b_date.substr(0,2); authors[i].birth.month=atoi(temp.c_str()); temp= b_date.substr(3,2); authors[i].birth.day=atoi(temp.c_str()); temp = b_date.substr(6,4); authors[i].birth.year=atoi(temp.c_str()); authors[i].nationality = "unknown"; inFile>>authors[i].notable_work; authors[i].notable_work = RemoveUnderScore(authors[i].notable_work); } } void PrintAuthors(Author *authors, int size) { cout< 

Books.txt

11 The_Name_of_the_Rose Umberto_Eco 1983 Italian Mystery 12000 Norwegian_Wood Haruki_Murakami 2000 Japanese Fiction 6000 The_Name_of_the_Wind Patrick_Rothfuss 2007 English Fantasy 4920 The_Girl_with_the_Dragon_Tattoo Stieg_Larsson 2005 Swedish Thriller 7049 The_Brothers_Karamazov Fyodor_Dostoevsky 1880 Russian Fiction 6948 Demonic_Males Richard_Wrangham 1997 English Non-Fiction 1209 War_and_Peace Leo_Tolstoy 1899 Russian Historical-Fiction 5890 Baudolino Umberto_Eco 2000 Italian Historical-Fiction 2134 The_Lies_of_Locke_Lamora Scott_Lynch 2006 English Fantasy 6676 The_Last_of_the_Wine Mary_Renault 1956 English Historical-Fiction 579 Brave_New_World Aldous_Huxley 1932 English Science-Fiction 4677

Authors.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

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

More Books

Students also viewed these Databases questions

Question

Which form of proof do you find least persuasive? Why?

Answered: 1 week ago