Write a C program to aid the DeAnza Bookstore in estimating its business for nex
ID: 3631794 • 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 as 10 separate characters
- 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). Use one to 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: 31
Enter 'R' if required or 'S' if suggested: r
Enter 'N' if new or 'O' if not a new text: O
ISBN: 0-75-579865-2
Copies Needed: 20
Profit: $ 146.92
Explanation / Answer
#include<stdio.h>
#include<conio.h>
#include<string.h>
int calculateCopies(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;
printf("Enter book number");
for( i=0;i<10;i++)
scanf("%c",ISBN);
fflush(stdin);
printf("Enter price per copy");
scanf("%f",&price);
printf("Enter expected class enrollment");
scanf("%d",&enrollment);
fflush(stdin);
printf("Ennter 'R if required or 'S' is suggested");
scanf("%c",&RorS);
fflush(stdin);
printf("Ennter 'N' if required or 'O' is suggested");
scanf("%c",&NorO);
copies=calculateCopies( enrollment,RorS,NorO);
profit=calculateProfit(copies,price);
printResults(ISBN,copies,profit);
getch();
return 0;
}
void printResults(isbn[],float copies,float profit)
{
int i;
printf("ISBN");
for(i=0;i<10;i++)
printf("%c",isbn[i]);
printf(" copies %f",copies);
printf(" Profit %f",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;
}
int calculateCopies(int intenrollment, char RorS,char NorO)
{
int copies=intenrollment;
if(RorS=='R')
{
if(NorO=='N')
copies=(int)copies*0.90;
if(NorO=='O')
copies=(int)copies*0.65;
}
if(RorS=='S')
{
if(NorO=='N')
copies=(int)copies*0.40;
if(NorO=='O')
copies=(int)copies*0.20;
}
return copies;
}
Hope this would helpful to you
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.