Answered step by step
Verified Expert Solution
Question
1 Approved Answer
You have been contracted by a bookstore to create an application that will load a list of books received in a shipment and produce a
You have been contracted by a bookstore to create an application that will load a list of books received in a shipment and produce a report about the shipment.
Write a program client that uses the class by creating a BooksReceived object and prompting the user for a file name. The file is of the type txt Appropriate error checking is required to ensure the file exists and can be opened successfully. Also, the name of the file may contain a space; therefore, be sure to use getline instead of cin when you prompt the user to enter the name of the file. Note: File Name means the path and name of the file.
Class:
Name: BooksReceived
Purpose: To accept and store the data for a list of books that were in a shipment and to provide functions that will manipulate the data.
Constructor:
Zeroargument constructor that initializes the data members to or as appropriate.
Fourargument constructor that receives the name of the book store, the date shipped, the number of hardbound books, and the number of paperback books.
Data Members:
nameBookstore string
Cannot be blank.
dateShipped string
Cannot be blank.
numberHardbound int
Must be or greater.
numberPaperback int
Must be or greater.
books vector
Functions:
addBookstring void
Accepts a book value as a string and adds it to the vector.
sortBookList void
Sorts the vector that contains the list of books received.
countBooksReceived int
Determines the number of books in the vector and returns this.
Do not use a counter of books added.
calcHardboundPercentage void
Calculates the percentage of the hardbound books in the shipment.
calcPaperbackPercentage void
Calculates the percentage of the paperback books in the shipment.
displayBooksReceivedInfo void
Outputs the shipment information in a formatted manor
FYI: While it is not normally a good process to do user output from inside a Class, this is the shorted and simplest method for the time available for this Lab.
setNameBookstore void
Accepts a string containing the book store name value and updates the nameBookstore data member.
getNameBookstore string
Returns the value stored in the nameBookstore data member.
setDateShipped void
Accepts a string containing the date shipped value and updates the dateShipped data member.
getDateShipped string
Returns the value stored in the dateShipped data member.
setNumberHardbound void
Accepts an int value containing the number of hardboard books in the shipment and updates the numberHardbound data member.
getNumberHardbound int
Returns the value stored in the numberHardbound data member.
setNumberPaperback void
Accepts an int value containing the number of paperback books in the shipment and updates the numberPaperback data member.
getNumberPaperback int
Returns the value stored in the numberPaperback data member.
Note: Setters and Getters are required even if they are not used.
Formulas:
Need: Calculate the percentage of hardbound and paperback books against the total number of books in the shipment.
o For the percentage, always display only digit after the decimal point. Some percentages will not have anything after the decimal point. EG
o FYI: Some of the percentage values will have no decimal point, and others will have several digits after the decimal point. The information below will help you correctly display or digit after the decimal point.
o The formula for calculating the percentage is:
Number of Hardbound books Total Number of Books
Below is a code example for both the calculation and the display.
double x
is the number of books hardbound or paperback
is the total number of books in the shipment
Multiplying the integer or by converts it to a double.
cout "Hardbound: setprecision endl;
Multiplying the which is the calculated percentage, by transforms it into
The setprecision function above tells the compiler that the data value of is to be displayed with digits. This causes the final digit to be rounded up or down, and the output is
NonClass Functions:
displayBooksReceivedInfo void
Creates and displays the formatted output of the book shipment information.
Business Rules:
No blank lines allowed in the text file.
The value for the number of hardbound and paperback books in the shipment must be numeric.
The data elements in the text file must be in the exact order given in the instructions in below.
o Bookstore name
o Date of shipment
o Number of hardbound books in the shipment
o Number of paperback books in the shipment
o A list of book titles in the shipment.
Must be at least three titles in the list.
The list of book titles must not be in alphabetic order.
Book titles must not exceed characters in length.
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