Question: Didn't realize I wasn't supposed to use namespace std for Header file. Took That out. I'm supposed to be writing this program: Some of the
Didn't realize I wasn't supposed to use namespace std for Header file. Took That out.
I'm supposed to be writing this program:
Some of the characteristics of a book are the title, author(s), publisher, ISBN, price, and year of publication. Design a class bookType that defines the book as an ADT.
Each object of the class bookType can hold the following information about a book: title, up to four authors, publisher, ISBN, price, and number of copies in stock. To keep track of the number of authors, add another member variable.
Include the member functions to perform the various operations on objects of type bookType. For example, the usual operations that can be performed on the title are to show the title, set the title, and check whether a title is the same as the actual title of the book. Similarly, the typical operations that can be performed on the number of copies in stock are to show the number of copies in stock, set the number of copies in stock, update the number of copies in stock, and return the number of copies in stock. Add similar operations for the publisher, ISBN, book price, and authors. Add the appropriate constructors and a destructor (if one is needed).
Write the definitions of the member functions of the class bookType.
Utilize the attached main program file that is designed to make calls to the class elements and use the variables defined in the class. Make certain that you have a header file and an implementation file and that you submit those files. Use the attached bookData.txt file with sample data. The main program reads the data from the file.
This was in the data file:
#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("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;
}
Among other problems I'm facing with this. I'm trying to read the header file but according to the program it can't read it. Which I don't understand. I believe I am calling it right. I am not sure if I'm calling it correct at the moment. There is a class bookType that is defined that I need for the program that currently looks like this:
#include
#include
#ifndef BOOK_TYPE_H
#define BOOK_TYPE_H
class bookType
{
std::string t;
std::string author[4];
int numAuthors;
std::string p;
std::string isbn;
double price;
int pubYear;
int numCopies;
int n;
public:
//constructor
bookType();
//setting title of the book
void setTitle(std::string title);
//set author names of the book
void setAuthors(std::string a[], int n);
//set publisher of the book
void setPublisher(std::string p);
//set ISBN of the book
void setISBN(std::string isbn);
//set price of the book
void setPrice(double p);
//set publication year of the book
void setPubYear(int y);
//set number of copies available
void setNumCopies(int n);
//update number of copies available
void updateNumCopies(int n);
//return title of the book
std::string getTitle();
//return names authors of the book
std::string* getAuthors();
//get publisher of the book
std::string getPublisher();
//return ISBN of the book
std::string getISBN();
//return publication year of the book
int getPubYear();
////return number of copies of the book
int getNumCopies();
//return price of the book
double getPrice();
};
#endif
#pragma once
It still needs modification but as of right now the header file and the source file aren't talking to each other. The other source file is talking to both of them from what I can tell since its not giving me weird errors. But something about the header and the main program refuse to communicate.
Added the last bit of code for running the program. Again still lining things up:
bookType::bookType() {}
//setting title of the book
void bookType::setTitle(string title)
{
t = title;
}
//set publisher of the book
void bookType::setPublisher(string publisher)
{
p = publisher;
}
//set author names of the book
void bookType::setAuthors(string auth[], int authorCount)
{
n = authorCount;
for (int i = 0; i { author[i] = auth[i]; } } //set ISBN of the book void bookType::setISBN(string ISBN) { isbn = ISBN; } //set price of the book void bookType::setPrice(double cost) { price = cost; } //set publication year of the book void bookType::setPubYear(int PublishYear) { pubYear = PublishYear; } //set number of copies available void bookType::setNumCopies(int copies) { numCopies = copies; } //update number of copies available void bookType::updateNumCopies(int copies) { numCopies += copies; } //return title of the book string bookType::getTitle() { return t; } //get publisher of the book string bookType::getPublisher() { return p; } //return names authors of the book string* bookType::getAuthors() { return author; } //return ISBN of the book string bookType::getISBN() { return isbn; } //return publication year of the book int bookType::getPubYear() { return pubYear; } ////return number of copies of the book int bookType::getNumCopies() { return numCopies; } //return price of the book double bookType::getPrice() { return price; }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
