Write a C++ program to aid the DeAnza Bookstore in estimating its business for n
ID: 641105 • Letter: W
Question
Write a C++ program to aid the DeAnza Bookstore in estimating its business for next quarter. Experience has shown that sales depend on whether a book is required or suggested, and on whether or not it has been used before. A new, required book will sell to 90% (.90) of expected enrollment, but if it has been used before only 65% of the expected enrollment will buy it. Similarly, 40% of the expected enrollment will buy a newly suggested book, but only 20% will purchase a previously suggested book.
INPUT
Your program is to prompt the user for:
- the book's 10 digit ISBN number (store as a string)
- the list price per copy
- the expected class enrollment
- code of 'R'for required text or code of 'S' for suggested text
- code of 'N' for a new text or code of 'O' for a text that has been used the previous quarter
CALCULATE
Calculate the number of copies needed and the profit if the store pays 80% of list (use global define for this). For the number of books to order, round up to the nearest whole book.Use one function to calculate number of books, one function to calculate the profit, and one function to output.
OUTPUT A sample run might look like this:
Enter book number: 0755798652
Enter price per copy: 34.98
Enter expected class enrollment: 35
Enter 'R' if required or 'S' if suggested: r
Enter 'N' if new or 'O' if not a new text: O
ISBN: 0755798652
Copies Needed: 23
Profit: $ 160.91
TEST DATA
0755798652,34.98,35,R,O
3453456784,23.95,100,R,N
5677655673,54.50,40,R,O
2462462464,5.95,40,S,O
8953647888, 65.99, 35, N, Y
Explanation / Answer
Program Code:
// DEAnzaBookStore.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include<iostream>
#include<string>
using namespace std;
int calculateNumCopies(int,char,char);
float calculateProfit(int ,float);
void printResults(char *,float,float);
#define payed 0.80
int main()
{
char isbn[10];
char RorS,NorO;
float price,profit,copies;
int i,enrollment;
int copy;
int count=0;
do{
cout<<" Enter the Details of the books: "<<endl;
cout<<"Enter book number: ";
cin>>isbn;
cout<<"Enter price per copy: ";
cin>>price;
cout<<"Enter expected class enrollment: ";
cin>>enrollment;
cout<<"Enter 'R' if required or 'S' is suggested: ";
cin>>RorS;
cout<<"Enter 'N' if required or 'O' is suggested: ";
cin>>NorO;
copies=calculateNumCopies( enrollment,RorS,NorO);
profit=calculateProfit(copies,price);
cout<<" The estimation for the next quarter is: ";
printResults(isbn,copies,profit);
count++;
}while(count<5);
system("pause");
return 0;
}
//print method to print the final results
void printResults(char *isbn,float copies,float profit)
{
cout<<" ISBN: "<<isbn;
cout<<" Copies: "<<copies;
cout<<" Profit: "<<profit;
}
//to calculate the profit
float calculateProfit(int copies,float price)
{
float paidToStore=0.0;
float totalAmount=0.0;
totalAmount=copies*price;
/*since 80 % is paid so remaining 20 % is profit*/
paidToStore=totalAmount*payed;
return totalAmount-paidToStore;
}
//to calculate the number of copies that are required
int calculateNumCopies(int intenrollment, char RorS,char NorO)
{
int copies=intenrollment;
if(RorS=='R'|| RorS=='r')
{
if(NorO=='N'|| NorO =='n')
copies=(int)copies*0.90;
if(NorO=='O'|| NorO=='o')
copies=(int)copies*0.65;
}
if(RorS=='S'|| RorS=='s')
{
if(NorO=='N'|| NorO =='n')
copies=(int)copies*0.40;
if(NorO=='O'|| NorO=='o')
copies=(int)copies*0.20;
}
return copies;
}
-------------------------------------------------------------------------------------------
Sample output:
Enter the Details of the books:
Enter book number: 3453456784
Enter price per copy: 23.95
Enter expected class enrollment: 100
Enter 'R' if required or 'S' is suggested: R
Enter 'N' if required or 'O' is suggested: N
The estimation for the next quarter is:
ISBN: 3453456784
Copies: 90
Profit: 431.1
Enter the Details of the books:
Enter book number: 5677655673
Enter price per copy: 54.50
Enter expected class enrollment: 40
Enter 'R' if required or 'S' is suggested: R
Enter 'N' if required or 'O' is suggested: O
The estimation for the next quarter is:
ISBN: 5677655673
Copies: 26
Profit: 283.4
Enter the Details of the books:
Enter book number: 2462462464
Enter price per copy: 5.95
Enter expected class enrollment: 40
Enter 'R' if required or 'S' is suggested: S
Enter 'N' if required or 'O' is suggested: O
The estimation for the next quarter is:
ISBN: 2462462464
Copies: 8
Profit: 9.52
Enter the Details of the books:
Enter book number: 8953647888
Enter price per copy: 65.99
Enter expected class enrollment: 35
Enter 'R' if required or 'S' is suggested: N
Enter 'N' if required or 'O' is suggested: Y
The estimation for the next quarter is:
ISBN: 8953647888
Copies: 35
Profit: 461.93
Enter the Details of the books:
Enter book number: 0755798652
Enter price per copy: 34.98
Enter expected class enrollment: 35
Enter 'R' if required or 'S' is suggested: R
Enter 'N' if required or 'O' is suggested: O
The estimation for the next quarter is:
ISBN: 0755798652
Copies: 22
Profit: 153.912Press any key to continue . . .
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.