Question

In: Computer Science

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 needed).

  • Write the definitions of the member functions of the class Book
  • Design a BookstoreManager class which creates a dynamic array of type Book (don’t use vectors), and provide implementation for the following operations on books in the array with the given time-complexity
  • A starter code and a sample output are provided.
  • As shown in the sample output, books are kept sorted by ISBN. Each time a new book is inserted, it’ll be inserted in the sorted order.
  • You are not allowed to use any existing sorting and searching functions.

The Functionalities available in BookstoreManager

Function Time-complexity
isEmpty() : returns true if the array is empty, otherwise false O(1)
isFull(): returns true if the array is full, otherwise false O(1)
listSize(): prints the number of books in the array O(1)
print(): prints the content of the array O(n)
insert(Book): asks user to enter new book info, and it adds the book to the array in sorted order. If array is full, it’ll double the size of the array O(n)
remove(Book): asks 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 search fails O(n)
removePublisher(string): asks user to enter publisher 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 search fails. O(n)
search(Book): asks user to enter ISBN or title, and prints the content of the book. Prints “Not Found”, if book is not found O(logn)

Sample Output:

user inputs are given in bold

true

Enter book title: C++: Programming Basics
Enter authors: Nathan Clark
Enter ISBN: 154296
Enter publisher: CreateSpace

Enter book title: Data Structures & Algorithm Analysis in C++
Enter authors: Mark Weiss
Enter ISBN: 132847
Enter publisher: Pearson

Enter book title: Introduction to Programming Using Python
Enter authors: Daniel Liang
Enter ISBN: 147231
Enter publisher: Pearson

Enter book title: Introduction to Algorithms
Enter authors: Thomas H. Cormen , Charles E. Leiserson
Enter ISBN: 189352
Enter publisher: MIT

Data Structures & Algorithm Analysis in C++
by Mark Weiss
132847
Pearson

Introduction to Programming Using Python
Daniel Liang
147231
Pearson

C++: Programming Basics
by Nathan Clark
154296
CreateSpace

Introduction to Algorithms
Thomas H. Cormen , Charles E. Leiserson
189352
MIT

Searching…
ISBN: 147231
Introduction to Programming Using Python
Daniel Liang
147231
Pearson

Removing…
ISBN: 154296

Data Structures & Algorithm Analysis in C++
by Mark Weiss
132847
Pearson

Introduction to Programming Using Python
Daniel Liang
147231
Pearson

Introduction to Algorithms
Thomas H. Cormen , Charles E. Leiserson
189352
MIT

Removing all books for a publisher
Publisher: Pearson

Introduction to Algorithms
Thomas H. Cormen , Charles E. Leiserson
189352
MIT
1

Starting Code:

int main() {
BookstoreManager bookstoreManager;
//prints true if the bookstore is empty
bookstoreManager.isEmpty();
//insert 4 books
string title, authors, publisher;
int isbn;
for(int i=0;i<4;i++){
cout<<"Enter book title:";
cin>>title;
cout<<"Enter authors:";
cin>>authors;
cout<<"Enter isbn:";
cin>>isbn;
cout<<"Enter publisher:";
cin>>publisher;
Book aBook(title, isbn, authors, publisher);
bookstoreManager.insert(aBook);
cout<<endl;
}
//print bookstoreB
bookstoreManager.print();
//search for books
cout<<"Searching…"<<endl;
cout<<"ISBN:";
cin>>isbn;
Book b2(isbn);
bookstoreManager.search(b2);
//remove a book
cout<<"Removing…"<<endl;
cout<<"ISBN:";
cin>>isbn;
Book b1(isbn);
bookstoreManager.remove(b1);
//print bookstore
bookstoreManager.print();
//remove books from a particular publisher
cout<<"Removing publisher"<<endl;
cout<<"Publisher:";
cin>>publisher;
bookstoreManager.removePublisher(publisher);
//print bookstore
bookstoreManager.print();
//prints the number of books
bookstoreManager.listSize();
}

Solutions

Expert Solution

See the code below.

#include<iostream>
#include<cstring>
using namespace std;
// a book class for the different variable.
class Book
{
public:
  string title;
  string authors;
  string publisher;
  int ISBN;
  
  // i have used different constructor base on the input.
     Book(string ttle,string author,string pub,int IS )
     {
         title = ttle;
         authors = author;
         publisher = pub;
         ISBN = IS;

     }
     Book(Book b)
     {
        title = b.title;
        authors = b.authors;
        publisher = b.publisher;
        ISBN = b.ISBN;
     }
     // when only isbn is entered.
     Book(int b)
     {
      title = " ";
      authors = " ";
      publisher = " ";
      ISBN = b.ISBN;
     }
};
class BookstoreManager
{
Book *Bookarray;
// capacity denote full capacity 
int idx;
// size if no of element present
int size;
int capacity;
public:
// Constructor
BookstoreManager()
{
  idx=0;
  size = 0;
  // in the starting capacity is 1.
  capacity =1;   
  Bookarray = new Book[capacity];
  

}
void print()
{
    // using renge base for loop came in c++11
    for(auto x:Bookarray)
      cout<<x.title<<endl<<x.authors<<endl<<x.publisher<<endl<<x.ISBN<<endl;
}
bool isEmpty()
{
 if(size==0)
   return 1;
 else
   return 0;
}
int listSize()
{
    return size;
}
bool isFull()
{
    if(size== capacity)
        return 1;
    else  
         return 0;
}

void insert(Book book)
{  

    // first checking the capacity of the array.
   if(size == capacity)
   {
       // double the size of the array.
       Book* temp = new Book[2*capacity];
       capacity = 2*capacity;
       Book* t = Bookarray;
       // copying the data from previous array to new array.
       for(int i=0;i<=idx;i++)
         temp[i]= Bookarray[i];
      Bookarray = temp;
     // delete the previous array.
      delete [] t;

   }
       // inserting the data in sorted array is it just like insertion sort.
       for(int i=size;i>=0;i--)
         {
          if(Bookarray[i].ISBN>book.ISBN)
          {
              Bookarray[i+1] = Bookarray[i];
          }
           else
             {
                 size++;
                 idx++;
                 Bookarray[i]=book;
                 break;
             }

         }

}
void remove(book b)
{
     int i=0;
     int flag =0;
     // searching the data present or not.
     for(i=0;i<=idx;i++)
      {
          if(Bookarray[i].ISBN==b.ISBN)
          {
              flag =1;
              break;
          } 
 

      }
      if(flag ==0)
      {
          cout<<"Not Found"<<endl;
      }
      else{
      for(int j=i;j<=idx-1;j++)
         Bookarray[j]=Bookarray[j+1];
      
      idx--;
      size--;
      }

}
void removePublisher(string publisher)
{
    int i=0;
     int flag =0;
     for(i=0;i<=idx;i++)
      {
          if(Bookarray[i].publisher==publisher)
          {
         for(int j=i;j<=idx-1;j++)
         // shifting the data left side.
         Bookarray[j]=Bookarray[j+1];
         
          idx--;
          size--;
          flag =1;
          }
         } 
      if(flag ==0)
      {
          cout<<"Not Found"<<endl;
      }
      
  return ;
}
void search(book b)
{
  for(int i=0;i<=size;i++)
  {
      if(Bookarray[i]==b.ISBN)
      {
          cout<<"ISBN:"<<Bookarray[i].ISBN<<endl;
          cout<<Bookarray[i].title<<endl;
          cout<<Bookarray[i].authors<<endl;
          return;
      }
  }
cout<<"Not found"<<endl;
return ;
}

};
int main() {
BookstoreManager bookstoreManager;
//prints true if the bookstore is empty
bookstoreManager.isEmpty();
//insert 4 books
string title, authors, publisher;
int isbn;
for(int i=0;i<4;i++){
cout<<"Enter book title:";
cin>>title;
cout<<"Enter authors:";
cin>>authors;
cout<<"Enter isbn:";
cin>>isbn;
cout<<"Enter publisher:";
cin>>publisher;
Book aBook(title, isbn, authors, publisher);
bookstoreManager.insert(aBook);
cout<<endl;
}
//print bookstoreB
bookstoreManager.print();
//search for books
cout<<"Searching…"<<endl;
cout<<"ISBN:";
cin>>isbn;
Book b2(isbn);
bookstoreManager.search(b2);
//remove a book
cout<<"Removing…"<<endl;
cout<<"ISBN:";
cin>>isbn;
Book b1(isbn);
bookstoreManager.remove(b1);
//print bookstore
bookstoreManager.print();
//remove books from a particular publisher
cout<<"Removing publisher"<<endl;
cout<<"Publisher:";
cin>>publisher;
bookstoreManager.removePublisher(publisher);
//print bookstore
bookstoreManager.print();
//prints the number of books
bookstoreManager.listSize();
return 0;
}

// Please use prople flag for running this program on different c++ compiler. (c++11 etc)

// Here i have explained the code .

// you can modified the code according the your need.

// Please upvote if it is helpful.


Related Solutions

Write a c++ class definition for an abstract data type describing a bookstore inventory. Each book...
Write a c++ class definition for an abstract data type describing a bookstore inventory. Each book has the following attributes: Book Title (character string); Book Author (character string); Book Price (Floating point number having two decimal places); Count of books on hand (int); The member functions are as follows: A constructor that is used to initialize all four elements of the structure to values inputted by the user; A function that displays in a readable tabular form the contents of...
In object C Define a class called XYPoint that will hold a Cartesian coordinate (x, y),...
In object C Define a class called XYPoint that will hold a Cartesian coordinate (x, y), where x and y are integers. Define methods to individually set the x and y coordinates of your new point and retrieve their values. Write an Objective-C program to implement your new class and test it (main section of the file). Your test program needs to create two instances of your class. Make sure your program test prints out the values that you have...
Design an Inventory class that can hold information for an item in a retail store’s inventory.
C++! Becareful following the test case.7. Inventory ClassDesign an Inventory class that can hold information for an item in a retail store’s inventory.The class should have the following private member variables.Variable Name   DescriptionitemNumber   An int that holds the item’s number.quantity               An int that holds the quantity of the item on hand.cost    A double that holds the wholesale per-unit cost of the itemThe class should have the following public member functionsMember Function               Descriptiondefault constructor             Sets all the member variables...
Create a C# Application. Create a class object called “Employee” which includes the following private variables:...
Create a C# Application. Create a class object called “Employee” which includes the following private variables: firstN lastN idNum wage: holds how much the person makes per hour weekHrsWkd: holds how many total hours the person worked each week regHrsAmt: initialize to a fixed amount of 40 using constructor. regPay otPay After going over the regular hours, the employee gets 1.5x the wage for each additional hour worked. Methods: constructor properties CalcPay(): Calculate the regular pay and overtime pay. Create...
Create the logic for an application that instantiates an object of the ATM class. Prompt the...
Create the logic for an application that instantiates an object of the ATM class. Prompt the user for the ATM object data to display the user’s bank balance PROGRAMMING LOGIC AND DESIGN QUESTION JAVA LANGUAGE
Develop a C++ "doubly" linked list class of your own that can hold a series of...
Develop a C++ "doubly" linked list class of your own that can hold a series of signed shorts Develop the following functionality: Develop a linked list node struct/class You can use it as a subclass like in the book (Class contained inside a class) You can use it as its own separate class Your choice Maintain a private pointer to a node class pointer (head) Constructor Initialize head pointer to null Destructor Make sure to properly delete every node in...
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...
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...
: Design and implement class Radio to represent a radio object. The class defines the following...
: Design and implement class Radio to represent a radio object. The class defines the following attributes (variables) and methods: Assume that the station and volume settings range from 1 to 10. A private variable of type int named station to represent a station number. Set to A private variable of type int named volume to represent the volume setting. Set to 1. A private variable of type boolean named on to represent the radio on or off. Set to...
Design a C++ program An address book is a book or a database used for saving...
Design a C++ program An address book is a book or a database used for saving and storing contacts which may usually consists of a few standard fields (for example: first name, last name, company name, address, telephone number, e-mail address, fax number, mobile phone number). Design an online address book to keep track of the details of family members, close friends and certain business associates. Details which your designed address book will keep should be like names (first name,...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT