Question

In: Computer Science

C++ Question The aim of this assignment is to design and implement a computerized “Library Management...

C++ Question

The aim of this assignment is to design and implement a computerized “Library Management System”. The system will be used in the back-office to manage the books in the library catalog and to keep track of the various users (borrowers) of the library. The system provides the following key functionalities:

Books are characterized by a call number, a title, and a flag that indicates whether the book is currently ‘on-shelf’ (in the library) or ‘on-loan’.

-Adding and removing books to and from the catalog.

-Add 10 books to the library

Solutions

Expert Solution

#include <iostream>

#include <vector>

#define ON_SHELF 1

#define ON_LOAN 2

using namespace std;

class Book

{

private:

int callNumber;

string title;

int flag;

public:

Book()

{

this->callNumber = 0;

this->title = "";

this->flag = 0;

}

Book(int callNumber, string title)

{

this->callNumber = callNumber;

this->title = title;

this->flag = ON_SHELF;

}

int getCallNumber(){return this->callNumber;}

string getTitle(){return this->title;}

int getFlag(){return this->flag;}

void setFlag(int flag)

{

this->flag = flag;

}

string getStatus()

{

if(getFlag() == ON_SHELF)

return "On Shelf";

else

return "Borrowed";

}

};

void printMenu();

void addBook(vector<Book> );

void borrowBook(vector<Book> );

void removeBook(vector<Book> );

void listAllBooks(vector<Book> );

int main()

{

int choice;

vector<Book> books;

// initially 8 books are added

books.push_back(Book(190, "A Clokwork Orange"));

books.push_back(Book(456, "The Elephant Tree"));

books.push_back(Book(110, "3 Mistakes Of My Life"));

books.push_back(Book(167, "The Zombie Room"));

books.push_back(Book(971, "Requiem for a Dream"));

books.push_back(Book(23, "A Splendid Thousand Suns"));

books.push_back(Book(846, "And There Were None"));

books.push_back(Book(287, "The Grapes Of Wrath"));

cout << endl << "<< WELCOME TO THE LIBRARY MANAGEMENT SYSTEM >>\n----------------------------------------------" << endl;

do

{

printMenu();

cin >> choice;

switch(choice)

{

case 1:

{

addBook(books);

break;

}

case 2:

{

borrowBook(books);

break;

}

case 3:

{

removeBook(books);

break;

}

case 4:

{

listAllBooks(books);

break;

}

case 5:

{

cout << endl << "Thank you!\nGood Bye.\n";

exit(0);

}

default:

cout << endl << "Invalid choice" << endl;

}

}while(choice != 5);

}

void printMenu()

{

cout << "1. Add a book\n2. Borrow a book\n3. Remove a book\n4. List all books\n5. Exit\n\nEnter choice: ";

}

void addBook(vector<Book> books)

{

int callNum;

string title;

cout << "Enter call number: ";

cin >> callNum;

cin.ignore();

bool found = false;

for(Book book : books)

{

if(book.getCallNumber() == callNum)

{

found = true;

break;

}

}

if(found)

cout << endl << "Book with the same call number already exists!" << endl << endl;

else

{

cout << "Enter title: ";

getline(cin, title);

books.push_back(Book(callNum, title));

cout << endl << "Book with title " << title << " is added successfully!" << endl << endl;

listAllBooks(books);

}

}

void borrowBook(vector<Book> books)

{

int callNum;

cout << "Enter the call number of the book: ";

cin >> callNum;

bool found = false;

int index = 0;

for(int i = 0; i < books.size(); i++)

{

if(books[i].getCallNumber() == callNum)

{

found = true;

index = i;

break;

}

}

books[index].setFlag(ON_LOAN);

if(!found)

cout << endl << "No books found for call number: " << callNum << endl;

else

{

cout << endl << "Book borrowed:" << endl << "Title: " << books[index].getTitle() << ", Status: " << books[index].getStatus() << endl << endl;

listAllBooks(books);

}

}

void removeBook(vector<Book> books)

{

int callNum;

cout << "Enter the call number of the book: ";

cin >> callNum;

bool found = false;

int index = 0;

for(int i = 0; i < books.size(); i++)

{

if(books[i].getCallNumber() == callNum)

{

found = true;

index = i;

break;

}

}

if(!found)

cout << endl << "No books found for call number: " << callNum << endl << endl;

else

{

Book book = books[index];

books.erase(books.begin() + index);

cout << endl << "Book deleted successfully:" << endl << "Title: " << book.getTitle() << endl << endl;

listAllBooks(books);

}

}

void listAllBooks(vector<Book> books)

{

cout << endl << "*** ALL BOOKS ***\n------------------" << endl;

for(Book book : books)

{

cout << "Title: " << book.getCallNumber() << ", Title: " << book.getTitle() << ", Status: " << book.getStatus() << endl;

}

cout << endl;

}

***************************************************************** SCREENSHOT **********************************************************


Related Solutions

Car Rental Management System in C++ The aim of this project is to design and implement...
Car Rental Management System in C++ The aim of this project is to design and implement a computerized Car Rental Management System for a company called COEN244Cars. The company rents two types of cars: standard and luxury cars. A car is identified by a car identification number (int), a type (string), and a flag that indicates whether the car is currently available or not. The company distinguishes between three types of customers: regular customers, corporate customers, and VIPs (Very Important...
Matrix Multiplication with Threads - C/C++ In this assignment you will use the Pthreads library to...
Matrix Multiplication with Threads - C/C++ In this assignment you will use the Pthreads library to write a program that multiplies two square arrays and compare the difference between the imperative and parallel implementations of this algorithm. Use the matrix mulltiplication algorithm. Write a program that contains three functions: (1) A function that has an integer as a parameter and returns a pointer to square array of integers (i.e. both dimensions should be equal). The function should allocate storage from...
Overview For this assignment, design and implement the methods for a class that can be used...
Overview For this assignment, design and implement the methods for a class that can be used to represent a quadratic equation. int main() has already been written for this assignment. It is available for download from Blackboard or by using the following link: http://faculty.cs.niu.edu/~byrnes/csci240/pgms/240pgm8.cpp All that needs to be done for this assignment is to add the class definition and method implementation to the above CPP file. The Quadratic class Data Members The class contains three data members: an integer...
C++ HW Aim of the assignment is to write classes. Create a class called Student. This...
C++ HW Aim of the assignment is to write classes. Create a class called Student. This class should contain information of a single student. last name, first name, credits, gpa, date of birth, matriculation date, ** you need accessor and mutator functions. You need a constructor that initializes a student by accepting all parameters. You need a default constructor that initializes everything to default values. write the entire program.
IN C++ LANGUAGE PLEASE::: Distance calc. This question is fairly straightforward. Design (pseudocode) and implement (source...
IN C++ LANGUAGE PLEASE::: Distance calc. This question is fairly straightforward. Design (pseudocode) and implement (source code) a program to compute the distance between 2 points. The program prompts the user to enter 2 points (X1, Y1) and (X2, Y2). The distance between 2 points formula is: Square_Root [(X2 – X1)^2 + (Y2 – Y1)^2]
C++ question: Design and implement your own linked list class to hold a sorted list of...
C++ question: Design and implement your own linked list class to hold a sorted list of integers in ascending order. The class should have member functions for inserting an item in the list, deleting an item from the list, and searching the list for an item. Note: the search function should return the position of the item in the list (first item at position 0) and -1 if not found. In addition, it should have member functions to display the...
For this computer assignment, you are to write a C++ program to implement a class for...
For this computer assignment, you are to write a C++ program to implement a class for binary trees. To deal with variety of data types, implement this class as a template. Most of the public member functions of the BinaryTree class call private member functions of the class (with the same name). These private member functions can be implemented as either recursive or non-recursive, but clearly, recursive versions of these functions are preferable because of their short and simple implementations...
In C++ In this assignment, we will implement a square root approximater and then an nth...
In C++ In this assignment, we will implement a square root approximater and then an nth root approximater. Recall that the nth root of x is the number when raised to the power n gives x. We can use the concepts of binary search to approximate the square root of a number, and we can continue this logic to approximate the nth square root. We're going to use the concepts of binary search to try and approximate ending the square...
For this computer assignment, you are to write a C++ program to implement a class for...
For this computer assignment, you are to write a C++ program to implement a class for binary trees. To deal with variety of data types, implement this class as a template. Most of the public member functions of the BinaryTree class call private member functions of the class (with the same name). These private member functions can be implemented as either recursive or non-recursive, but clearly, recursive versions of these functions are preferable because of their short and simple implementations...
A Library Management System is designed to carry out the management of library books in the...
A Library Management System is designed to carry out the management of library books in the library. In order to carry out the receipt and issuance of books, the library management information system must store, organize, share, and retrieve information. Part 1: Describe Your Library Management Information System: Part 2: Draw a Use Case Diagram for Your System: *Use case descriptions are optional Part 3: Draw a Class Diagram for Your System: Part 4: Draw a Sequence Diagram for Your...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT