Answered step by step
Verified Expert Solution
Question
1 Approved Answer
This assignment utilizes a class in an application that might be useful in the real world. It requires sorting and computation with data stored in
This assignment utilizes a class in an application that might be useful in the real world. It
requires sorting and computation with data stored in a vector inside a class. In this assignment,
you will design an ObjectOriented program and manipulate data using a vector within the class.
REMINDER
Do not put each class code into a single file.
Review the checklist at the end of the instructions before submitting the assignment.
INSTRUCTIONS
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.
Note: The number of hardbound and paperback books does not have match the number in
the text file.
CSIS Lab
Page of
numberPaperback int
Must be or greater.
books vectorstring
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 double
Calculates the percentage of the hardbound books in the shipment.
calcPaperbackPercentage double
Calculates the percentage of the paperback books in the shipment.
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.
displayBooksReceivedInfo void
Creates and displays the formatted output of the book shipment information.
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.
CSIS Lab
Page of
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
Business Rules:
No blank lines are allowed in the text file.
The value for the number of hardbound and paperback books in the shipment mus
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