Question
I have an assignment where I have to store the following for a library: - Title of book - Author - ISBN number - Status
I have an assignment where I have to store the following for a library:
- Title of book
- Author
- ISBN number
- Status of the book (if it's checked out)
- Person who checked it out
Here are the instructions:
A local library needs a program that stores information about their books. The information that they need stored is as followed:The title of the book.The books author.The ISBN number (note: for this program, we will just use a random 5-digit number).The status of the book (i.e., whether it is checked out).The name of the person that has it currently checked the book out.The program should, in addition, support the following commands: 1.Search the library of books by ISBN. 2.Checkout a book. 3.Return a book. 4.Quit Program.
To implement this program, we are going to create a class called Book, which will allow us to create objects that store the required information for a given book. Below is a UML diagram that describes what members the Book class should have:
-title:string
-author:string
-ISBN:int
-status:bool
-checkedOutBy:string
Book(p_title:string, p_author:string, p_ISBN:string)
Getters and Setters:
+getTitle():string
+getAuthor():string
+getISBN():string
+getStatus():bool
+setTitle(new_title:string):none
+setAuthor(new_author:string): none
+setISBN(new_ISBN:int): noneUtility Methods
+checkOutBook(name:string): bool
+returnBook():void
+outputBook():void
Descriptions of Notable Methods
1.checkOutBookThis method changes the status of the book to true and sets the checkedOutBy attribute to the name of the person that has checked out the book. This method should NOTupdate the status/checkedOutBy attributes if the book is already checked out. The method returns true if the book was successfully checked out and false if the book is already checked out.
2.returnBookThis method sets the status attribute to false and checkedOutBy attribute to the empty string (i.e., empty set of quotes). This method should return nothing.
3.outputBookThis method outputs the books information in the following format:
by
ISBN:
Checked out by:
If the book is NOT checked out, do NOT output the Checked out by message.
Main file(netID_prog3_TestBookClass.cpp)There is a partially completed definition of the main function, as well as functions for creating the book library (i.e., an array of 5 book objects) and the ISBN lookup function. You goal for this file is to finish the definition of the main function by writing the code for each of the menu commands listed above. Below is a breakdown of how to write each command:Search the library of books by ISBNcall the ISBN lookup function. If the function returns -1, then output an error message, otherwise, output the book at the returned index.Checkout a book.Call the ISBN lookup function. If the function returns -1, then output an error message. Otherwise, check to see if the book is currently checked out. If it is, output an appropriate error message. If not, then ask the user for the name of the person checking out the book and call the appropriate method for checking out the book.Note: Before inputting the string (which will require getline), use the statement cin.ignore() above the getlinestatement to ensure that your program doesnt skip the input for the name.Return a book.Call the ISBN lookup function. If the function returns -1, then output an error message. Otherwise, check to see if the book is currently checked out. If it is, call the appropriate method for checking out the book. If not, then output an appropriate error message.Quit Program.Simply return 0; to exit the program.
Hints: 1.Start by creating the class definition first. Implement the methods in the class definition before working on the .cpp file.
2.Test each method individually in the main function before writing the code for the menu. Create a dummy book object to work with and enter information for a random book. Call the methods and observe how they behave to test the book class.
3.Once you feel confident the Book class works, begin working on the menu code. You may use either an if/else if statement or switch statement to decide what menu item is chosen.
4.Test one of the books randomly. Do not just test the first book.
Here's the CPP file that I forgot to include:
using std::cin;
using std::getline;
void populateBookArray(Book library[]);
int lookupByISBN(Book library[]);
const int SIZE = 5;
int main(){
//Create an array of Book objects to store our library in.Book library[SIZE];
//Populate our library with sample books.populateBookArray(library);
/*
*************************************
Complete the rest of main here....
*************************************
*/return 0;
}
//Note: This function assumes that there are 5 elements in this array.
//Function populates our library with popular novels.
//ISBN numbers are just random 5 digit numbers.
//You can assume for the rest of your functions that the library
//array is always 5 elements.
void populateBookArray(Book library[])
{
library[0].setAuthor("JK Rowling");
library[0].setTitle("Harry Potter and the Sorcerers Stone");
library[0].setISBN(98346);
library[1].setAuthor("C.S. Lewis");
library[1].setTitle("The Lion, the Witch, and the Wardrobe");
library[1].setISBN(45336);
library[2].setAuthor("E. B. White");
library[2].setTitle("Charlotte's Web");
library[2].setISBN(98346);
library[3].setAuthor("F. Scott Fitzgerald");
library[3].setTitle("The Great Gasby");
library[3].setISBN(11934);
library[4].setAuthor("S. E. Hinton");
library[4].setTitle("The Outsiders");
library[4].setISBN(72331);
}
//Asks the user for the ISBN number of the book
//and searches the library for that book.
//If found, returns the book element's index
//if not found, returns -1.
int lookupByISBN(Book library[])
{
int ISBN;
cout << "Enter the ISBN: ";
cin >> ISBN;
for (int i = 0; i < SIZE; i++)
{
if (ISBN == library[i].getISBN())
return i;
}
return -1;
}
Thank you!
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started