Answered step by step
Verified Expert Solution
Link Copied!

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:
Zero-argument constructor that initializes the data members to 0 or as appropriate.
Four-argument 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 1 or greater.
numberPaperback int
Must be 1 or greater.
books vector
Functions:
addBook(string)- 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 1 digit after the decimal point. Some percentages will not have anything after the decimal point. E.G.,20%,27.3%
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 0 or 1 digit after the decimal point.
o The formula for calculating the percentage is:
Number of Hardbound books / Total Number of Books *100
Below is a code example for both the calculation and the display.
double x =(3*1.0)/(11*1.0)
3 is the number of books (hardbound or paperback)
11 is the total number of books in the shipment
Multiplying the integer 3 or 11 by 1.0 converts it to a double.
cout << "Hardbound: "<< setprecision(3)<<(0.2727*100.0)<<"%"<< endl;
Multiplying the 0.2727, which is the calculated percentage, by 100.0 transforms it into 27.27.
The setprecision(3) function above tells the compiler that the data value of 27.27 is to be displayed with 3 digits. This causes the final digit to be rounded up or down, and the output is 27.3.
Non-Class 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 35 characters in length.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

The Accidental Data Scientist

Authors: Amy Affelt

1st Edition

1573877077, 9781573877077

More Books

Students also viewed these Databases questions

Question

How will you deal with them?

Answered: 1 week ago