Answered step by step
Verified Expert Solution
Question
1 Approved Answer
I have the following code which is currently in one single cpp file but needs to be broken out to have three separate files and
I have the following code which is currently in one single cpp file but needs to be broken out to have three separate files and not sure how I extract from this to create the three. One should be booksreceived.h header file booksreceived.cpp class implementation file and booksdriver.cpp driver file The checklist I need to meet is attached as well.
#include
#include
#include
#include
using namespace std;
class BooksReceived
private:
string nameBookstore;
string dateShipped;
int numberHardbound;
int numberPaperback;
vector books;
public:
Constructors
BooksReceived : nameBookstore dateShipped numberHardbound numberPaperback
BooksReceivedstring name, string date, int hardbound, int paperback
: nameBookstorename dateShippeddate numberHardboundhardbound numberPaperbackpaperback
Setters
void setNameBookstorestring name nameBookstore name;
void setDateShippedstring date dateShipped date;
void setNumberHardboundint hardbound numberHardbound hardbound;
void setNumberPaperbackint paperback numberPaperback paperback;
Getters
string getNameBookstore const return nameBookstore;
string getDateShipped const return dateShipped;
int getNumberHardbound const return numberHardbound;
int getNumberPaperback const return numberPaperback;
Functions
void addBookstring book books.pushbackbook;
void sortBookList sortbooksbegin books.end;
int countBooksReceived const return books.size;
double calcHardboundPercentage const return numberHardbound countBooksReceived;
double calcPaperbackPercentage const return numberPaperback countBooksReceived;
void displayBooksReceivedInfo const
cout "Bookstore: nameBookstore endl;
cout "Date Shipped: dateShipped endl;
cout "Number of Hardbound Books: numberHardbound endl;
cout "Number of Paperback Books: numberPaperback endl;
cout
Book Titles:
;
for const string& book : books
cout book endl;
cout fixed setprecision;
cout "Percentage of Hardbound Books: calcHardboundPercentage endl;
cout "Percentage of Paperback Books: calcPaperbackPercentage endl;
;
NonClass Functions
void readDataFromFileBooksReceived& shipment, const string& fileName
ifstream filefileName;
if file.isopen
cerr "Error opening file: fileName endl;
exitEXITFAILURE;
string name;
string date;
int hardbound;
int paperback;
string bookTitle;
Read data from the file
getlinefile name;
getlinefile date;
file hardbound paperback;
file.ignore; Consume the newline character
shipment.setNameBookstorename;
shipment.setDateShippeddate;
shipment.setNumberHardboundhardbound;
shipment.setNumberPaperbackpaperback;
while getlinefile bookTitle
shipment.addBookbookTitle;
file.close;
int main
BooksReceived shipment;
Prompt the user for the file name
string fileName;
cout "Enter the file name: ;
getlinecin fileName;
Read data from the file
readDataFromFileshipment fileName;
Display the shipment information
shipment.displayBooksReceivedInfo;
return ;
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started