Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

C++ Program: You are to write a program for the Peoria network of public libraries to keep track of books available at each of the

C++ Program:

You are to write a program for the Peoria network of public libraries to keep track of books available at each of the branches. Each branch has one string as its name. Each branch keeps its books in a linked list in lexicographical order by author's name. Books of the same author are arranged in lexicographical order by title. There may be many copies of the same book in a library branch.

The data structure to be used should be an array of structures, with the structure containing a branch_name field (string) followed by a pointer field.

The pointer field should point to an ordered linked list of the books in that branch. Each node of the linked list corresponds to a book and is a structure with an author_name field, a book_title field, a num_copies field which indicates how many copies of that book are available for checkout, and a pointer field pointing to the next book in the branch.

When a book is checked out from a branch, it is deleted from the branch's linked list. When it is returned to a branch, it is inserted in the appropriate place in the ordered list. A book can be returned to a different branch than the one it was checked out from.

Customers can ask to find how many books of a specific author and title are available in a given branch.

Your program should be menu driven with the menu containing the following options:

1. Create a branch and insert its books. (for each branch, the user creates the list of all books contained in the branch by repeated choice of menu choice number 1, as shown below. S/he inputs the first and last name of author, followed by the title. If more than one copy, each copy has to be added individually. When all books have been inserted to the branch, the user is to type none none none, and go to insert books into the next branch. Only after the whole library database has been created for all branches, the user will venture into menu choices 2 and higher).

2. Give an author name (first, last), the title and a branch name, to CHECKOUT that book from the branch, (if there is at least one copy of the book available, otherwise print that the branch holds no such book).

3. Give an author name (first, last), the title and a branch name, to RETURN that book to the branch. (books can be returned to a different branch than the one they were checked out from)

4. Give an author name (first, last), the title and a branch name, to FIND the number of copies of that book that are available in that branch (returns zero if there are none).

5. Give a branch name, to PRINT the author name (first, last) and title of all books contained in that branch.

6. Give a branch name and an author name, to FIND the number of books by that author contained in the branch.

7. Give an author name (first, last), to FIND the number of books by that author contained in all the branches of the library system.

8. Give an author name (first, last), to PRINT in lexicographical order the titles of all books by that author contained in all the branches of the library system.

9. Exit the program.

------

When the user chooses menu choice 1, the following dialogue for input of data should ensue:

What is your menu choice?

1

What is the name of the branch?

ALPHA

What is author and title of book?

JOHN SMITH FREEDOM

What is author and title of book?

MICHAEL JONES LIFE ADVENTURES

What is author and title of book?

NONE NONE NONE

Thank you, I created branch ALPHA

...menu is displayed again...

What is your menu choice?

1

What is the name of the branch?

BETA

What is author and title of book?

NAJ GUPTA ALGORITHMS

What is author and title of book?

NAJ GUPTA ALGORITHMS

What is author and title of book?

LEV LAGOS GENIUS

What is author and title of book?

NONE NONE NONE

Thank you, I created branch BETA

...menu is displayed again...

What is your menu choice?

7

Give an author name (first, last), to FIND the number of books by that author contained in all the branches of the library system.

LEV LAGOS

There are 1 books in the library system by LEV LAGOS

What is your menu choice?

2

Give author, title and branch from which to checkout the book:

LEV LAGOS GENIUS BETA

Thank you! The book GENIUS by LEV LAGOS has been checked out from BETA

...menu is displayed again...

What is your menu choice?

7

Give an author name (first, last), to FIND the number of books by that author contained in all the branches of the library system.

LEV LAGOS

There are 0 books in the library system by LEV LAGOS

What is your menu choice?

4

Give an author name (first, last), a title and a branch name, to FIND the number of copies of that book that are available in that branch (returns zero if there are none).

LEV LAGOS GENIUS BETA

There are 0 books in the library branch BETA by LEV LAGOS titled GENIUS

What is your menu choice?

2

Give author, title and branch from which to check out the book:

MATTHEW JONES LIFE ADVENTURES ALPHA Thank you! The book LIFE ADVENTURES by MATTHEW JONES has been checked out from ALPHA

...menu is displayed again...

What is your menu choice?

3

Give author, title and branch to which book is to be returned:

LEV LAGOS GENIUS APLPHA

Thank you! The book GENIUS by LEV LAGOS has been returned to branch ALPHA

...menu is displayed again...

What is your menu choice?

2

Give author, title and branch from which to checkout the book:

JOE JONES LIFE ALPHA

Sorry! This book is not available at branch ALPHA

...menu is displayed again...

What is your menu choice?

4

Give an author name (first, last), a title and a branch name, to FIND the number of copies of that book that are available in that branch (returns zero if there are none).

LEV LAGOS GENIUS ALPHA

There are 1 books in the library branch ALPHA by LEV LAGOS titled GENIUS

...menu choice is displayed again...

what is your menu choice?

5

Give a branch name, to PRINT the author name (first, last) and title of all books contained in that branch.

BETA

The books in BETA are:

ALGORITHMS by NAJ GUPTA number of copies 2

...menu is displayed again...

What is your menu choice?

9

Thank you and goodbye. //End of Program

The setup is an array of "branch" structures, each branch structure has two fields, the name of the branch and a pointer which is the head of a linked list

of "book" structures/booknodeTypes. The "book" nodeType has 5 fields, first name of author, last name of author, title of book, number of copies, pointer to the next book in the branch.

So, here is a possible setup:

//GIVEN CODE

#ifndef LIBBRANCH_GUARD

#define LIBBRANCH_GUARD

#include

#include

#include

struct BookType //the structure for each book

{

std::string author_first_name;

std::string author_last_name;

std::string book_title;

int num_copies;

BookType * next = nullptr;

};

typedef BookType * NodePtr; //will point to the next book in the library

struct BranchType // an array of BranchTypes, has a pointer to the books

{

std::string branchname;

NodePtr ptrToBooksInBranch;

};

class LibBranch

{

public:

LibBranch();

void Insert(std::string branch, std::string author, std::string title);

bool Delete(std::string branch, std::string author, std::string title);

int Find(std::string branch, std::string author, std::string title);

void newBranch(std::string name);

std::string toString(std::string branch, LibBranch name);

std::string getBranchName(int i, LibBranch name);

private:

static BranchType branchArr[100];

static int numBranches; //the number of branches stored in the branchArr

};

#endif

If you have questions, please mention what you need specification for, as this is, at base, all the information given.

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_2

Step: 3

blur-text-image_3

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

SQL Server T-SQL Recipes

Authors: David Dye, Jason Brimhall

4th Edition

1484200616, 9781484200612

More Books

Students also viewed these Databases questions