Question

In: Computer Science

Implement in C++ Design a BookstoreManager class which creates a dynamic array of type Book (don’t...

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

Solutions

Expert Solution

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;
}

==================================

THANK YOU!! PLEASE VOTE


Related Solutions

Implement in C++ Design a BookstoreManager class which creates a dynamic array of type Book (don’t...
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...
IN C++ (THIS IS A REPOST) Design a class, Array, that encapsulates a fixed-size dynamic array...
IN C++ (THIS IS A REPOST) Design a class, Array, that encapsulates a fixed-size dynamic array of signed integers. Write a program that creates an Array container of size 100 and fills it with random numbers in the range [1..999]. (Use std::rand() with std::srand(1).) When building the array, if the random number is evenly divisible by 3 or 5, store it as a negative number. Within your main.cpp source code file, write a function for each of the following processes....
Implement a class Polynomial that uses a dynamic array of doubles to store the coefficients for...
Implement a class Polynomial that uses a dynamic array of doubles to store the coefficients for a polynomial. Much of this work can be modelled on the C++ dynamic array of ints List that we discussed in class. This class does not need the method the overloaded += operator. Your class should have the following methods: Write one constructor that takes an integer n for the degree of a term and a double coefficient c for the coefficient of the...
For this assignment you will implement a dynamic array. You are to build a class called...
For this assignment you will implement a dynamic array. You are to build a class called MyDynamicArray. Your dynamic array class should manage the storage of an array that can grow and shrink. The public methods of your class should be the following: MyDynamicArray(); Default Constructor. The array should be of size 2. MyDynamicArray(int s); For this constructor the array should be of size s. ~MyDynamicArray(); Destructor for the class. int& operator[](int i); Traditional [] operator. Should print a message...
1) Design and implement a method to double all elements of an array. Important: You don’t...
1) Design and implement a method to double all elements of an array. Important: You don’t need to test test method in main(). You don’t need to initialize the array. pubilc static void doubleElements(int [] arr) { } 2) Start with the code below and complete the getInt method. The method should prompt the user to enter an integer. Scan the input the user types. If the input is not an int, throw an IOException; otherwise, return the int. In...
TestLibrary.java Design and implement a class named Book. A book has a serial number, a title,...
TestLibrary.java Design and implement a class named Book. A book has a serial number, a title, an author, and a publisher. Create appropriate constructor(s) and accessor and mutator methods for the Book class. Add a static variable to the Book class and set its initial value to 100000000. When a new book is created, this static variable is automatically incremented by 1 and the new value is assigned as the serial number of the new book. Design and implement a...
Write a C++ class that implement two stacks using a single C++ array. That is, it...
Write a C++ class that implement two stacks using a single C++ array. That is, it should have functions pop_first(), pop_second(), push_first(…), push_second(…), size_first(), size_second(), …. When out of space, double the size of the array (similarly to what vector is doing). Notes: Complete all the functions in exercise_2.cpp, then submit this cpp file. pop_first() and pop_second() should throw std::out_of_range exception when stack is empty. CODE: #include <cstdio> #include <stdexcept> template <class T> class TwoStacks { public:   // Constructor, initialize...
A Bookstore Application C++ Design the class Book. Each object of the class Book can hold...
A Bookstore Application C++ Design the class Book. Each object of the class Book can hold the following information about a book: title, authors, publisher, ISBN Include the member functions to perform the various operations on the objects of Book. For example, the typical operations that can be performed on the title are to show the title, set the title. Add similar operations for the publisher, ISBN , and authors. Add the appropriate constructors and a destructor (if one is...
Write a code in c++ using dynamic array of structure and dynamic array list. Make a...
Write a code in c++ using dynamic array of structure and dynamic array list. Make a dummy list for a company which stores following information about its customers. Customer ID Customer Name Gender Total items purchased Item category 20% discount in percentage of total purchase amount. Use dynamic array to save at least 20 items by dividing them into 3 different categories. Make a dummy list of items that company sells by dividing them into two categorizes. Items has following...
Why do we need a dynamic stack and How to implement a dynamic array stack? (...
Why do we need a dynamic stack and How to implement a dynamic array stack? ( Please answer in Java)
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT