In: Computer Science
Implement in C++ Design a BookstoreManager class which creates a dynamic array of type Book (don’t use vectors), and provide an implementation for the following operations on books in the array
1)isEmpty() returns true if the array is empty, otherwise false
2)isFull() returns true if the array is full, otherwise false
3)listSize() prints the number of books in the array
4)print() prints the content of the array
5)insert(Book) asks the user to enter new book info, and it adds the book to the array in sorted order if the array is full, it’ll double the size of the array
6)remove(Book) asks the user to enter ISBN info, and it removes the book from the array; shifts the other elements up in the array. Prints “Not Found” if the search fails.
7) removePublisher(string) asks the user to enter the publisher's name, and it removes all the books with the same publisher from the array; shifts the other elements up in the array. Prints “Not Found” if the search fails.
8) search(Book) asks the user to enter ISBN, and prints the content of the book prints “Not Found”, if the book is not found
Note :
I am developing the program, But I have some doubts while developing the program.
the parameter for the function remove(Book) is Book class.But, In the description its was mentioned that we have to prompt ISBN info Based on that we have to remove the book from the array.My doubt is what is the parameter for the remove function.
Also, for the search(Book) function what is the actual parameter...Could u plz clear that,So that i can develop the full code.
===================================
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <cstdlib>
using namespace std;
class Book
{
private :
string title;
string publisher;
string ISBN;
double price;
public :
Book(string title,string publisher,string ISBN,double
price)
{
this->title=title;
this->publisher=publisher;
this->ISBN=ISBN;
this->price=price;
}
public string getTitle() {
return title;
}
void setTitle(string title) {
this->title = title;
}
string getPublisher() {
return publisher;
}
void setPublisher(string publisher) {
this->publisher =
publisher;
}
string getISBN() {
return ISBN;
}
void setISBN(string iSBN) {
this->ISBN = iSBN;
}
double getPrice() {
return price;
}
void setPrice(double price) {
this->price = price;
}
/* toString() method is used to display
* the contents of an object inside it
*/
string toString()
{
stringstream ss;
ss<<"Title
:"<<title<<endl;
ss<<"Publisher
:"<<publisher<<endl;
ss<<"ISBN
:"<<ISBN<<endl;
ss<<"Price
:$"<<price<<endl;
return ss.str();
}
};
class BookstoreManager
{
private :
Book *books;
int size;
int count;
public :
BookstoreManager()
{
this->size=10;
this->count=0;
this->books = new Book[size];
}
bool isEmpty()
{
if(count==0)
return true;
else
return false;
}
bool isFull()
{
if(count==size)
return true;
else
return false;
}
int listSize()
{
return count;
}
void print()
{
for(int i=0;i<count;i++)
{
cout<<books[i]<<endl;
cout<<"-------------------------"<<endl;
}
}
void insert(Book b)
{
if(!isFull())
{
this->books[count]=b;
count++;
}
}
void remove(string ISBN)
{
int index=-1;
for(int i=0;i<count;i++)
{
if(books[i].getISBN().compare(ISBN)==0)
{
index=i;
break;
}
}
if(index==-1)
{
cout<<"Not
Found"<<endl;
}
else
{
// remove specific indexed element
in array
// left shift array
for(int i=index;i<count-1;i++)
{
books[i]=books[i+1];
}
count--;
}
}
void removePublisher(string name)
{
int index=-1;
for(int i=0;i<count;i++)
{
if(books[i].getPublisher().compare(name)==0)
{
index=i;
}
if(index!=-1)
{
// remove
specific indexed element in array
// left shift array
for(int i=index;i<count-1;i++)
{
books[i]=books[i+1];
}
count--;
}
}
if(index==-1)
{
cout<<"Not
Found"<<endl;
}
}
void search(string ISBN)
{
}
};
int main() {
return 0;
}
==================================