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

a8 serendipity c++ Chapter 8 Searchine and Sorting Arrays Serendipity Bookseller

ID: 3748699 • Letter: A

Question

a8 serendipity
c++

Chapter 8 Searchine and Sorting Arrays Serendipity Booksellers Software Development Project- Part 8: A Problem-Solving Exercise For this chapter's assignment you will add scarching capabilities to the addBook, lookUpBook, editBook, and deleteBook functions 1. Create a global constant for the size of your database Create a global constant DBSIZE and set it equal to 20. This represents the number of book records that your arrays can handle. As you declare your local arrays in int main), use DBSIZE as part of decl zation statement 2. Modify the addBook function a. When a new book is added to the inventory, the program will check bookCount (which is a local variable within int main0 that has to be passed) bookCount represents exactly what the name implies, it keeps track of the number of books in our data base. This function is to determine if there is room in the parallel arrays for any additional books using bookCount. If there is room then store the new books' information within the parallel arrays at index[bookCount]. Since our arrays use 0 based indexing, the valid range of indexes is from 0 to 19. After adding the book to our inventory, we then increment bookCount by 1 b. Once its determined that there is space in database(arrays), the book's data may be stored in each of the other arrays by using the same subscript. For instance, if bookCount is (books are stored from index 0-6), then the title of the new book is stored in bookTitle[7], its ISBN number will be stored in isbn[7], its author's name will be stored in authorl7], its publisher's name will be stored in publisher[7], the date the book was added to the inventory will be stored in date Addedl7], the quantity of books on hand will be stored in qtyOnHandl71, the book's wholesale pricew be stored in wholesale[7], and the book's retail price will be stored in retail[7]. Remember to increase bookCount by 1 at this point. The addBook function is currently a stub function. Modify it so it performs the following steps: 1, First determine if there is room in the database as described earlier 2. If there is room, present the user with a menu that allows them to enter each item individually. I will demo this in class. We use this system so that if the user makes a mistake, they can go back and make the change prior to saving the record. 3. As part of this menu, display a header that details the current number of records in the inventory. Note that the wholesale cost and retail price is for a single copy of the hook. Also, remember that the date should be entered in the form MM-DDYYYY. where MM is the month, DD is the day, and YYYY is the year

Explanation / Answer

Implemented Modified Source Code:-
-------------------------------
Main.cpp:-
=========
#include <iostream>
#include <string>
#include <fstream>
#include "bookTypeImp.cpp"
using namespace std;
void getBookData(bookType books[], int& noOfBooks);
void printBookData(bookType books[], int noOfBooks);
void searchBookData(bookType books[], int bookCount);
void searchBookDataByISBN(bookType books[], int bookCount, string ISBN,int& loc);
void searchBookDataByTitle(bookType books[], int bookCount, string title,int& loc);
void updateCopiesInStock(bookType books[], int bookCount);
void showMenu();
void subMenu();
int main()
{
bookType books[100];
int numberOfBooks = 0;
int choice;
int i;
getBookData(books, numberOfBooks);
showMenu();
cin>>choice;
while(choice != 9)
{
switch (choice)
{
case 1:
for(i=0;i<numberOfBooks;i++)
books[i].printbookTitle();
cout<<endl;
break;
case 2:
for(i=0;i<numberOfBooks;i++)
books[i].printbookTitleAndISBN();
cout << endl;
break;
case 3:
searchBookData(books, numberOfBooks);
break;
case 4:
updateCopiesInStock(books, numberOfBooks);
break;
case 5:
printBookData(books, numberOfBooks);
break;
default:
cout << "Invalid selection." << endl;
}
showMenu();
cin >> choice;
}
return 0;
}
void getBookData(bookType books[], int& noOfBooks)
{
string title;
string ISBN;
string Publisher;
int PublishYear;
string auth[4];
double cost;
int copies;
int authorCount;
int i, j;
ifstream infile;
char ch;
infile.open("bookData.txt");
if (!infile)
{
cout<<"Cannot open Input file"<<endl;
cout<<"Exit the program"<<endl;
return;
}
infile >> noOfBooks;
infile.get(ch);
for(i =0;i< noOfBooks;i++)
{
getline(infile, title);
getline(infile,ISBN);
getline(infile,Publisher);
infile >> PublishYear >> cost >> copies >> authorCount;
infile.get(ch);
for(j=0;j<authorCount;j++)
getline(infile, auth[j]);
books[i].setBookInfo(title, ISBN, Publisher,PublishYear, auth, cost, copies,authorCount);
}
}
void printBookData(bookType books[], int noOfBooks)
{
int i;
for (i = 0; i < noOfBooks; i++)
{
books[i].printInfo();
cout << endl << "---------------------------------" << endl;
}
}
void searchBookDataByISBN(bookType books[], int bookCount, string ISBN,int& loc)
{
int i;
loc = -1;
for (i = 0; i < bookCount; i++)
if (books[i].isISBN(ISBN))
{
loc = i;
break;
}
}
void searchBookDataByTitle(bookType books[], int bookCount, string title,int& loc)
{
int i;
loc = -1;
for (i = 0; i < bookCount; i++)
if (books[i].isTitle(title))
{
loc = i;
break;
}
}
void searchBookData(bookType books[], int bookCount)
{
int choice;
char ch;
int loc;
string str;
subMenu();
cin >> choice;
cin.get(ch);
switch(choice)
{
case 1:
cout << "Enter the ISBN of the book." << endl;
getline(cin, str);
searchBookDataByISBN(books, bookCount, str, loc);
if (loc != -1)
cout << "The store sells this book." << endl;
else
cout << "The store does not sell this book" << endl;
break;
case 2:
cout << "Enter the title of the book." << endl;
getline(cin, str);
searchBookDataByTitle(books, bookCount, str, loc);
if (loc != -1)
cout << "The store sells this book." << endl;
else
cout << "The store does not sell this book" << endl;
break;
default:
cout << "Invalid choice" << endl;
}
}
void updateCopiesInStock(bookType books[], int bookCount)
{
int choice;
int loc;
int count;
char ch;
string str;
subMenu();
cin >> choice;
cin.get(ch);
switch (choice)
{
case 1:
cout << "Enter the ISBN of the book." << endl;
getline(cin, str);
searchBookDataByISBN(books, bookCount, str, loc);
if (loc != -1)
{
cout << "Enter the number of books: " ;
cin >> count;
cout << endl;
books[loc].updateQuantity(count);
}
else
cout << "The store does not sell this book: " << endl;
break;
case 2:
cout << "Enter the title of the book." << endl;
getline(cin, str);
searchBookDataByTitle(books, bookCount, str, loc);
if (loc != -1)
{
cout << "Enter the number of books" ;
cin >> count;
cout << endl;
books[loc].updateQuantity(count);
}
else
cout << "The store does not sell this book" << endl;
break;
default:
cout << "Invalid choice" << endl;
}
}
void showMenu()
{
cout << "Welcome to Rock's Book Store" << endl;
cout << "To make a selection enter the number and press enter"<< endl;
cout << "1: Print a list of books" << endl;
cout << "2: Print a list of books and ISBN numbers" << endl;
cout << "3: To see if a book in store" << endl;
cout << "4: To update the number of copies of a book" << endl;
cout << "5: To print books data" << endl;
cout << "9: Exit the program." << endl;
}
void subMenu()
{
cout << "Enter" << endl;
cout << "1: To search the book by ISBN" << endl;
cout << "2: To search the book by title" << endl;
}



bookType.h:-
=============
#include <string>
using namespace std;
class bookType
{
public:
void setBookInfo(string title, string ISBN,string Publisher, int PublishYear,string auth[], double cost, int copies,int noAuthors);
void setBookTitle(string s);
void setBookISBN(string s);
void setBookPrice(double cost);
void setCopiesInStock(int noOfCopies);
void printInfo() const;
bool isISBN(string s) const;
bool isTitle(string s) const;
bool isAuthor(string s) const;
void getBookTitle(string& s) const;
void getBookISBN(string& s) const;
double getBookPrice() const;
bool isInStock() const;
void makeSale();
void printBookPrice() const;
void printbookTitle() const;
void printbookTitleAndISBN() const;
void showQuantityInStock() const;
void updateQuantity(int addBooks);
bookType();
private:
string bookTitle;
string bookISBN;
string bookPublisher;
int bookPublishYear;
string authors[4];
double price;
int quantity;
int noOfAuthors;
};

bookTypeImp.cpp:-
================
#include <iostream>
#include <string>
#include "bookType.h"
using namespace std;
void bookType::setBookInfo(string title, string ISBN,string Publisher, int PublishYear,string auth[], double cost, int copies,int authorCount)
{
int i;
bookTitle = title;
bookISBN = ISBN;
bookPublisher = Publisher;
bookPublishYear = PublishYear;
noOfAuthors = authorCount;
for (i = 0; i < noOfAuthors; i++)
authors[i] = auth[i];
price = cost;
quantity = copies;
}
void bookType::setBookTitle(string s)
{
bookTitle = s;
}
void bookType::setBookISBN(string s)
{
bookISBN = s;
}
void bookType::setBookPrice(double cost)
{
price = cost;
}
void bookType::setCopiesInStock(int noOfCopies)
{
quantity = noOfCopies;
}
void bookType::printInfo() const
{
int i;
cout << "Title: " << bookTitle << endl;
cout << "ISBN: " << bookISBN << endl;
cout << "Publisher: " << bookPublisher << endl;
cout << "Year of Publication: " << bookPublishYear << endl;
cout << "Number of Authors: " << noOfAuthors << endl;
cout << "Authors: ";
for (i = 0; i < noOfAuthors; i++)
cout << authors[i] << "; ";
cout << endl;
cout << "Price: " << price << endl;
cout << "Quantities in stock: " << quantity << endl;;
}
bool bookType::isISBN(string s) const
{
return (bookISBN == s);
}
bool bookType::isTitle(string s) const
{
return (bookTitle == s);
}
bool bookType::isAuthor(string s) const
{
bool found = false;
int i;
for (i = 0; i < noOfAuthors; i++)
if (authors[i] == s)
{
found = true;
break;
}
return found;
}
void bookType::getBookTitle(string& s) const
{
s = bookTitle;
}
void bookType::getBookISBN(string& s) const
{
s = bookISBN;
}
double bookType::getBookPrice() const
{
return price;
}
bool bookType::isInStock() const
{
return (quantity > 0);
}
void bookType::makeSale()
{
quantity--;
}
void bookType::printBookPrice() const
{
cout << "Price = " << price << endl;
}
void bookType::printbookTitle() const
{
cout << "Title: " << bookTitle << endl;
}
void bookType::printbookTitleAndISBN() const
{
cout << "Title: " << bookTitle << "; ISBN: " << bookISBN << endl;
}
void bookType::showQuantityInStock() const
{
cout << "Quantity: " << quantity << endl;
}
void bookType::updateQuantity(int addBooks)
{
quantity = quantity + addBooks;
}
bookType::bookType()
{
int i;
bookTitle = "";
bookISBN = "";
bookPublisher = "";
bookPublishYear = 1900;
noOfAuthors = 0;
for(i=0;i<4;i++)
authors[i] = "";
price = 0;
quantity = 0;
}



bookData.txt:-
=================
5
C++Programing: From Problem Analysis to Program Design
5-17-525281-3
ABC
2000
52.50
20
1
Malik, D.S.
Fuzzy Discrete Structures
3-7908-1335-4
Physica-Verlag
2000
89.00
10
2
Malik, Davender
Mordeson, John
Fuzzy Mathematic in Medicine
3-7908-1325-7
Physica-Verlag
2000
89.00
10
3
Mordeson, John
Malik, Davender
Cheng, Shih-Chung
Harry John and The Magician
0-239-23635-0
McArthur A. Devine Books
1999
19.95
10
3
Goof, Goofy
Pluto, Peter
Head, Mark
Dynamic InterWeb Programming
22-99521-453-1
GNet
1998
39.99
25
1
hope it helps.