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

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


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...
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...
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...
(a) Implement the following algorithm, which is given a duplicate-free array array as input, in C++....
(a) Implement the following algorithm, which is given a duplicate-free array array as input, in C++. whatDoIDo (array): 1) Build a heap from array (using buildHeap as explained in class), where the heap starts at position array[0]. 2) Starting from j = size of array - 1, as long as j>0: i. Swap the entries array[0] and array[j]. ii. Percolate down array[0], but only within the subarray array[0..j-1]. iii. Decrement j by 1. Provide three input/output examples for duplicate-free arrays...
Design and implement a Java program that creates a GUI that will allow a customer to...
Design and implement a Java program that creates a GUI that will allow a customer to order pizza and other items from a Pizza Paarlor. The customer should be able to order a variety of items which are listed below. The GUI should allow the customer (viaJavaFX UI Controls - text areas, buttons, checkbox, radio button, etc.) to input the following information: Name of the customer First Name Last Name Phone number of the customer Type of food being order...
Act 1: Class BooleanFunc Overview BooleanFunc will contain a truthTable (a dynamic array) which defines the...
Act 1: Class BooleanFunc Overview BooleanFunc will contain a truthTable (a dynamic array) which defines the boolean function being represented. You can load this truthTable using a mutator, setTruthTable() , and change the function it represents by calling setTruthTable() to give the table new values. You will not be able to change the size of the table (i..e. #inputs to the function) after an object is instantiated using a setTableSize-style method, but you can totally redefine the object using the...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT