Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I need the following code ( C++) commented on, Ch10_Ex8_MainProgram.cpp, bookType.h, bookTypeImp.cpp. Please include a screenshot of the code running after being commented. Thank you!

I need the following code ( C++) commented on, Ch10_Ex8_MainProgram.cpp, bookType.h, bookTypeImp.cpp. Please include a screenshot of the code running after being commented. Thank you!

Ch10_Ex8_MainProgram.cpp

#include

#include

#include

#include "bookType.h"

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

books[i].printbookTitle();

cout << endl;

break;

case 2:

for (i = 0; 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("T://project/Project1/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;

}

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

bookType.h

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

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database And Expert Systems Applications 24th International Conference Dexa 2013 Prague Czech Republic August 2013 Proceedings Part 1 Lncs 8055

Authors: Hendrik Decker ,Lenka Lhotska ,Sebastian Link ,Josef Basl ,A Min Tjoa

2013 Edition

3642402844, 978-3642402845

More Books

Students also viewed these Databases questions

Question

2. Do you find change a. invigorating? b. stressful? _______

Answered: 1 week ago

Question

10. Are you a. a leader? b. a follower? _______

Answered: 1 week ago