Your college book store needs your help in estimating its business for next year
ID: 3776873 • Letter: Y
Question
Your college book store needs your help in estimating its business for next year. Experience has shown that sales depend greatly on whether a book is required for a course or just optional, and whether or not it has been used in the class before. A new, required textbook will sell to 90% of prospective enrollment, but if it has been used in the class before, only 65% will buy. Similarly, 40% of prospective enrollment will buy a new, optional textbook, but if it has been used in the class before only 20% will buy. (Note that "used" here does not mean second-hand books.)
Write a C++ program that accepts as input a series of books (until the user enters a sentinel).
For each book ask for:
a code for the book,
the single copy cost for the book,
the current number of books on hand,
the prospective class enrollment,
and data that indicates if the book is required/optional, new/used in past.
As output, show all the input information in a nicely formatted screen along with how many books must be ordered (if any, note that only new books are ordered), the total cost of each order.
Then, after all input is complete, show the total cost of all book orders, and the expected profit if the store pays 80% of list price. Process one book at a time and show the output screen for that book.
Then, when the user has finished entering all the data, your program should output the total and profit values.
Before you start writing code, take some time to think about design of this program. Remember you need to include a BookStore class and it should be decomposed into a set of functions that perform only one task. The main function should be used to call the many functions of the Bookstore.
Here is sample output:
Please enter the book code: 1221
single copy price: 69.95
number on hand: 30
prospective enrollment: 150
1 for reqd/0 for optional: 1
1 for new/0 for used: 0
Book: 1221
Price: $69.95
Inventory: 30
Enrollment: 150
This book is required and used.
Need to order: 67
Total Cost: $4686.65
Enter 1 to do another book, 0 to stop. 0
Total for all orders: $4686.65
Profit: $937.33
Explanation / Answer
Here is the code for you:
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
int anotherBook = 1, bookCode, numOnHand, enrollments, required, needToOrder, newOrUsed;
double copyPrice, totalOrders = 0;
while(anotherBook)
{
cout<<"Please enter the book code: ";
cin>>bookCode;
cout<<"single copy price: ";
cin>>copyPrice;
cout<<"number on hand: ";
cin>>numOnHand;
cout<<"prospective enrollment: ";
cin>>enrollments;
cout<<"1 for reqd/0 for optional: ";
cin>>required;
cout<<"1 for new/0 for used: ";
cin>>newOrUsed;
if(newOrUsed == 1 && required == 1)
needToOrder = enrollments * 0.9 - numOnHand;
else if(newOrUsed == 0 && required == 1)
needToOrder = enrollments * 0.65 - numOnHand;
else if(newOrUsed == 1 && required == 0)
needToOrder = enrollments * 0.4 - numOnHand;
else
needToOrder = enrollments * 0.2 - numOnHand;
cout<<"Book: "<<bookCode<<endl;
cout<<"Price: $"<<fixed<<setprecision(2)<<copyPrice<<endl;
cout<<"Inventory: "<<numOnHand<<endl;
cout<<"Enrollment: "<<enrollments<<endl;
cout<<"This book is ";
if(required == 0)
cout<<"optional and ";
else
cout<<"required and ";
if(newOrUsed == 0)
cout<<"used."<<endl;
else
cout<<"new."<<endl;
cout<<"Need to order: "<<needToOrder<<endl;
cout<<"Total Cost: $"<<fixed<<setprecision(2)<<needToOrder * copyPrice<<endl;
totalOrders += needToOrder * copyPrice;
cout<<"Enter 1 to do another book, 0 to stop. ";
cin>>anotherBook;
}
cout<<"Total for all orders: $"<<fixed<<setprecision(2)<<totalOrders<<endl;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.