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]
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...
In C++, Design and implement an ADT that represents a triangle. The data for the ADT...
In C++, Design and implement an ADT that represents a triangle. The data for the ADT should include the three sides of the triangle but could also include the triangle’s three angles. This data should be in the private section of the class that implements the ADT. Include at least two initialization operations: one that provides default values for the ADT’s data, and another that sets this data to client-supplied values. These operations are the class’s constructors. The ADT also...
The management of a tertiary institution in Ghana has contacted you to design and implement an...
The management of a tertiary institution in Ghana has contacted you to design and implement an ERP system for handling their internal workflows. Among other things the system should focus on student records, students’ fees management, students’ assessment, human resource functions, and payroll management. Following from this preamble, answer the question that follow. a. What is an ERP system? 2 Marks b. In not more than a page, describe how you would go about building the requested system focusing on...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT