Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I need assistance creating a C++ code. I need you to help me create the input and output functions that will allow a user to

I need assistance creating a C++ code. I need you to help me create the input and output functions that will allow a user to enter a title of a book and the author with spaces in which you'll need to use the getline function for these. After you create these classes I need you to go to my library class. The library class allows:

1) The input of an additional book to be entered into the sytem.

2) Listing the current books in the order of which they are currently stored.

3) Outputs the number of books in the library.

4) Outputs the total number of pages in the library.

5) Sorts the books in the library by copyright date and outputting them to the screen. (Ascending order)

6) Sorts the books in the library by title and outputting them to the screen. (Ascending order)

7) Search for a particular book by title and outputting the information on that book (author, date, pages)

8) Search for a particular author and outputting all the books by that author and their information (title, date, pages)

9) Removal of a book.

The self.txt is a backup file for the library and will need a load and save function in which the system will be able to load all current information from as well as saving new information to. For example if there is a new book added in, it will be saved to the shelf.txt file. Please do not change the code inside the main.cc unless something does not work!!! Below is the code that I have so far:

main.cc

------------------------------------------------------------------------------

#include #include #include #include "book.h" #include "library.h"

int menu(); using namespace std; int main(){ Library mybooks; Book tmp; string tmpstring; int choice; ifstream ifs; ofstream ofs; ifs.open("shelf.txt"); if(!ifs.fail()){ mybooks.load(ifs); ifs.close(); } // start the user interaction menu do{ choice = menu(); switch(choice){ case 1: cin>>tmp; mybooks.addbook(tmp); break; case 2: mybooks.showall(cout); break; case 3: cout<<"Currently there are "; cout<

return 0; }

// The menu function which returns the user's choice int menu() { int choice; cout<<"Please chose from the following options: "; cout<<"1) Add a book to the library "; cout<<"2) See all your books "; cout<<"3) See how many books are in your library "; cout<<"4) See total number of pages in your library "; cout<<"5) Sort books by copyright date "; cout<<"6) Sort books by title "; cout<<"7) Find information about a book "; cout<<"8) See all books by a particular author "; cout<<"9) Remove a book by entering its title "; cout<<"0) Quit ";

cin>>choice; return choice; }

library.cc

----------------------------------------------------------------------

#include #include "book.h" using namespace std;

#ifndef LIBRARY_H #define LIBRARY_H

class Library { private: int numBooks; Book numBookss[500]; public: Library(); Library(int numBooks); void addbook() { //add a new book to the library }; void showall() { //show all current books in the library }; void size() { //Output the current number of books in the library }; void numpages() { //Output number of pages in the library }; void sort_by_date { //Sort all the books by copyright date. Ascending order }; void sort_by_title { //Sort all the books by title. Ascending order }; void find_title { //Search the library by title and output the information of that book }; void find_author { //Search the library by author and ouput the information for all books written by that author }; void remove { //remove a book from the library }; void save { //Saves the data in the library in the backup file "shelf.txt" }; }; #endif

book.cc

-----------------------------------------------------------------

#include #include "book.h" #include using namespace std; class Book{ private: std::string title; std::string author; int year; int pages; public: Book(){

} void input(std::istream& ins){

} void output(std::ostream& outs)const{

} string get_title()const{

} string get_author()const{

} int get_copyright()const{

} int get_pages()const{

} };

shelf.txt

-----------------------------------------------------------------------

The Hobbit Tolkien, JRR 1937 350 Catcher in the Rye Salinger, JD 1951 175 Dune Herbert, Frank 1965 420

Please let me know if you have any questions. Thank you

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

Database Development For Dummies

Authors: Allen G. Taylor

1st Edition

978-0764507526

More Books

Students also viewed these Databases questions

Question

Compute the derivative f(x)=(x-a)(x-b)

Answered: 1 week ago

Question

What are the Five Phases of SDLC? Explain each briefly.

Answered: 1 week ago

Question

How can Change Control Procedures manage Project Creep?

Answered: 1 week ago