This is what i have so far https://drive.google.com/open?id=0ByAEvzVVOjkbNGFHbjJ
ID: 3698080 • Letter: T
Question
This is what i have so far https://drive.google.com/open?id=0ByAEvzVVOjkbNGFHbjJZWXJQZDQ
instructions:
1. Convert the BookData Structure to a Class.
The program currently keeps data about books in a structure called BookData. Convert the structure declaration to a class declaration. The existing member variables should be made private.
2. Convert Functions to Member Functions.
The member variables of the BookData structure are accessed or manipulated by the following functions:
setTitle
setISBN
setAuthor
setPub
setDateAdded
setQty
setWholesale
setRetail
isEmpty
removeBook
Because the structure is now a class, and the member variables are private, you will need to convert these functions to member functions of the BookData class.
3. Add New Accessor Functions for Retrieving Data from the BookData Class.
Because the BookData member variables are now private, you will need to add member functions to retrieve their values. Add the following functions to BookData:
getTitle: Will be used to get the contents of the bookTitle array.
getISBN: Will be used to get the contents of the isbn array.
getAuthor: Will be used to get the contents of the author array.
getPub: Will be used to get the contents of the publisher array.
getDateAdded: Will be used to get the contents of the dateAdded array.
getQty: Will return the contents of the qtyOnHand member.
setWholesale: Will return the contents of the wholesale member.
getRetail: Will return the contents of the retail member.
4. Convert the Remainder of the Program to Use the Class.
Now that BookData is a class with private member variables, the addBook, lookUpBook, deleteBook, removeBook, and cashier functions must be modified. Instead of accessing the private member variables directly, these functions must use the classs member functions you created in step 2.
5. Add the bookMatch Member Function to the BookData Class
Currently the functions lookUpBook, editBook, and deleteBook search the book database for titles that match, or partially match, a search string. Add a member function named bookMatch to the BookData class. The function should accept a string as its argument and return true if the string is found in the book title. If the string is not found in the book title, bookMatch should return false.
6. Modify lookUpBook, editBook, and DeleteBook
Currently the lookUpBook, editBook, and deleteBook functions have their own method of comparing book titles with search strings. Modify them so they use the bookMatch function you added to the BookData class in Step 1.
7. Modify the Report Module
The reporting capabilities you added in Lab1 must now be modified to work with the BookData class.
8. Add Other Classes to the Program
Analyze the program for other ways to implement classes. Here are some suggestions:
Consider whether the various menus could be managed by class objects.
Could a class be constructed to hand the program's user interface?
Analyze the file I/O performed by the program.
Could a class be constructed to handle all the file operations?
Determine if input validation could be performed by a class object.
Explanation / Answer
#include <iostream>
#include <string>
#include <iomanip>
using namespace std;
#include "BookData.h"
void bookInfo(BookData);
void readBook(BookData& book1);
int main()
{
BookData book1;
cout << " Enter the data for the book: ";
readBook(book1);
cout << " Display the data for the book: ";
bookInfo(book1);
system("pause");
return 0;
}
void bookInfo(BookData book)
{
string temp;
cout << left;
cout << " " << setw(22) << "ISBN:" << book.getIsbn() << endl;
cout << " " << setw(22) << "Title:" << book.getTitle() << endl;
cout << " " << setw(22) << "Author:" << book.getAuthor() << endl;
cout << " " << setw(22) << "Publisher:" << book.getPub() << endl;
cout << " " << setw(22) << "Date Added:" << book.getDateAdded() << endl;
cout << " " << setw(22) << "Quantity-On-Hand:" << book.getQty() << endl;
cout << " " << setw(22) << "Wholesale:" << "$" << fixed << setprecision(2) << book.getWholeSale() << endl;
cout << " " << setw(22) << "Retail Price:" << "$" << book.getRetail() << endl;
temp = book.isEmpty()?"yes":"No";
cout << " " << setw(22) << "Empty?" << temp << endl;
}
void readBook(BookData& book1)
{
string tempS;
int tempI;
double tempD;
cout << "Enter the Title: ";
cin >> tempS;
book1.setTitle(tempS);
cout << "Enter the ISBN: ";
cin >> tempS;
book1.setIsbn(tempS);
cout << "Enter the Author: ";
cin >> tempS;
book1.setAuthor(tempS);
cout << "Enter the Publisher: ";
cin >> tempS;
book1.setPub(tempS);
cout << "Enter Date Added: " ;
cin >> tempS;
book1.setDateAdded(tempS);
cout << "Enter Quantity on Hand: ";
cin >> tempI;
book1.setQty(tempI);
cout << "Enter Wholsale Price: " ;
cin >> tempD;
book1.setWholesale(tempD);
cout << "Enter Retail Price: " ;
cin >> tempD;
book1.setRetail(tempD);
cout << "Enter 1 to insert the book or 0 to remove: ";
cin >> tempI;
while (tempI > 1 || tempI < 0)
{
cout << "Wrong entry. Try again: ";
cin >> tempI;
}
if (tempI == 0)
book1.insertBook();
else
book1.removeBook();
}
BookData.cpp
#include <string>
class BookData
{
private:
string bookTitle;
string isbn;
string author;
string publisher;
string dateAdded;
int qtyOnHand;
double wholesale;
double retail;
bool empty;
public:
BookData();
void setTitle(string object);
void setIsbn(string code);
void setAuthor(string auth);
void setPub(string pub);
void setDateAdded(string dateAdd);
void setQty(int quant);
void setWholesale(double price);
void setRetail(double temp);
bool isEmpty();
void insertBook();
void removeBook();
string getTitle();
string getIsbn();
string getAuthor();
string getPub();
string getDateAdded();
int getQty();
double getWholeSale();
double getRetail();
};
BookData::BookData()
{
qtyOnHand = 0;
wholesale = 0;
retail = 0;
empty = true;
bookTitle = isbn = author = publisher = dateAdded = "";
}
void BookData::setTitle(string object)
{
bookTitle = object;
}
void BookData::setIsbn(string code)
{
isbn = code;
}
void BookData::setAuthor(string auth)
{
author = auth;
}
void BookData::setPub(string pub)
{
publisher = pub;
}
void BookData::setDateAdded(string dateAdd)
{
dateAdded = dateAdd;
}
void BookData::setQty(int quant)
{
qtyOnHand = quant;
}
void BookData::setWholesale(double price)
{
wholesale = price;
}
void BookData::setRetail(double temp)
{
retail = temp;
}
bool BookData::isEmpty()
{
return empty;
}
void BookData::insertBook()
{
empty = false;
}
void BookData::removeBook()
{
empty = true;
}
string BookData::getTitle()
{
return bookTitle;
}
string BookData::getIsbn()
{
return isbn;
}
string BookData::getAuthor()
{
return author;
}
string BookData::getPub()
{
return publisher;
}
string BookData::getDateAdded()
{
return dateAdded;
}
int BookData::getQty()
{
return qtyOnHand;
}
double BookData::getWholeSale()
{
return wholesale;
}
double BookData::getRetail()
{
return retail;
}
}
DataBook.h :
#ifndef BOOKDATA_H
#define BOOKDATA_H
#include <string>
class BookData
{
private:
string bookTitle;
string isbn;
string author;
string publisher;
string dateAdded;
int qtyOnHand;
double wholesale;
double retail;
bool empty;
public:
BookData();
void setTitle(string object);
void setIsbn(string code);
void setAuthor(string auth);
void setPub(string pub);
void setDateAdded(string dateAdd);
void setQty(int quant);
void setWholesale(double price);
void setRetail(double temp);
bool isEmpty();
void insertBook();
void removeBook();
string getTitle();
string getIsbn();
string getAuthor();
string getPub();
string getDateAdded();
int getQty();
double getWholeSale();
double getRetail();
};
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.