Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Note: Assignment must use a member function, non member function, and four structs Objectives: The main objective of this assignment is checking students ability to

Note: Assignment must use a member function, non member function, and four structs 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 Assignment 1 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< Please and thank you!

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered 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

Students also viewed these Databases questions