Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

implement unsorted lists using statics array. In this programming assignment, yo

ID: 3549619 • Letter: I

Question

implement unsorted lists using statics array.


In this programming assignment, you are about to write an object-oriented program to mimic a library. To simplify the implementation of the library, you can assume that the library keeps only books (excluding other materials). Each book is represented by a unique ISBN number. Librarians are able to search, add, and delete books from the library catalog.

Library patrons are able to search and print out the information of a book (in this case only ISBN).

1. You need to create a C++ class named Library and a class named Book. You have two options to implement Class Library: static or dynamic (dynamic is preferred and extra points for this).

_ Static: Define two private member variables: Book books[MAX] and int numOfBooks." Variable ooks" is an array of ISBN numbers and umOfBooks" stores the number of books the library currently has and should be no more than the capacity of the library (MAX=100 books). Class Book has an integer-valued member variable for ISBN and other public functions.

_ Dynamic: Define two private member variables: Book * books and int numOfBooks." Variable ooks" is a pointer to a Book object. In the constructor of Library, you need to use ew" operator to create a dynamic array and let variable ooks" point to the array. Also, you need to have a user-defined destructor for class Library to release the memory of the array dynamically created, because it is placed on heap memory and needs to be removed by programmer once the function where the array variable resides is returned.

2. The ISBN numbers are stored in an integer array. The array doesn't have to be sorted for this assignment.

3. The public functions defined class Library include a default constructor which creates a library with no books initially, search, insert, delete, and print functions.  

4. Your program accepts commands to make search, insertions, deletions, and print.

5. The functional requirements for each of the operations are given in the table below. The sample class declaration is below: Feel free to add additional functions you need.

Input: The program inputs commands from the user keyboard to search, insert, delete, print, and quit. You are free to implement the user interface part of the program as you wish, as long as it is easy to use.

Output: The results of each operation should be written to the screen. In addition, your program can print all the books at any time. The information should be neatly formatted and clearly labeled.

Commands: The program must be able to process the following commands:

Command Processing

S (SEARCH)    Prompt the user for the book's ISBN (an integer). Search if the book is in the list. Print a message to the screen about transaction information.

I (INSERT)     Prompt the user for the book's ISBN (an integer). Add entry for this book in the list. Print a message to the screen about transaction information.

D (DELETE)    Prompt the user for the ISBN of the book to delete. Search for the book to be deleted. If it is found, delete it. Print transaction information to the screen. If the book is not found, leave the list

unchanged, and print an error message.

P (PRINT)    Prompt the user to print all the books in the list. Print out the information about each book to the screen. Format this information clearly. If the list is empty, print an appropriate message.

Q (QUIT)    Prompt the user to verify that he or she wants to quit.

Explanation / Answer

//main.cpp


#include "Library.h"


int main()

{

Library lib;

int quitFlag=1;

do

{

int choice;

cout<<" Welcome to library ";

cout<<"Please select one option ";

cout<<"1)Search 2)Insert 3Delete 4)Print 5)quit ";

cout<<"your choice : ";

cin>>choice;

switch(choice)

{

case 1:

lib.search();

break;

case 2:

lib.insertion();

break;

case 3:

lib.deletion();

break;

case 4:

lib.print();

break;

case 5:

quitFlag = lib.quit();

break;

}

}while(quitFlag);

return 0;

}



//Library.cpp


#include "Library.h"


Library::Library()

{

numOfBooks = 0;

}

Library::~Library()

{

}

void Library::search()

{

int localIsbn;

cout<<"Enter Books ISBN : ";

cin>>localIsbn;

int i=0;

for(i=0;i<numOfBooks;i++)

{

if(books[i].ISBN==localIsbn)

break;

}

if(i==numOfBooks)

{

cout<<"This book is not in the system ";

}

else

{

cout<<"your book has been found ";

cout<<"Book ISBN: "<<books[i].ISBN<<endl;

}

}

void Library::insertion()

{

int localIsbn;

cout<<"Enter Books ISBN : ";

cin>>localIsbn;

if(numOfBooks==100)

{

cout<<"there is no more room for new books ";

}

else

{

Book temp;

temp.ISBN = localIsbn;

books[numOfBooks++]=temp;

cout<<"Book added in the system succesfully ";

}

}

void Library::deletion()

{

int localIsbn;

cout<<"Enter Books ISBN : ";

cin>>localIsbn;

if(numOfBooks==0)

{

cout<<"There are no books in the system ";

}

else

{

int i;

for(i=0;i<numOfBooks;i++)

{

if(books[i].ISBN==localIsbn)

break;

}

if(i==numOfBooks)

{

cout<<"This book is not availabe ";

}

else

{

while(i<numOfBooks-1)

{

books[i]=books[i+1];

}

numOfBooks--;

cout<<"Book has been deleted ";

}

}

}

void Library::print()

{

//print all books info

if (numOfBooks==0)

{

cout<<"There are no books in the system right now. ";

}

else

{

cout<<"List of available Books are: "<<setw(10)<<"ISBN"<<endl;

for(int i=0;i<numOfBooks;i++)

{

cout<<setw(10)<<books[i].ISBN<<endl;

}

cout<<"Toatl "<<numOfBooks<<"books"<<endl;

}

}

int Library::quit()

{

int choice;

cout<<"are you sure you want to quit(press 0 to quit)";

cin>>choice;

return choice;

}



//Library.h

#pragma once

#include<iostream>

#include<iomanip>

#define MAX 100

using namespace std;

class Book

{

public:

int ISBN;

};

class Library

{

private:

Book books[100];

int numOfBooks;

public:

Library();

~Library();

void search();

void insertion();

void deletion();

void print();

int quit();

};


Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Chat Now And Get Quote