In: Computer Science
Today BandN book stores is currently running a deal on e-books. Customers will receive a 15% discount off their entire order. Customers who buy 20 or more e-books will receive 20% off instead. Each book costs a flat $8.99. Write a C++ program that will calculate the final cost of your order, using functions. Global variables are not allowed unless they are constant. Information should be passed with parameters. Your main function should not do any of the tasks in the list below. The program will print a set of instructions for the user and give a brief explanation of the purpose. It will ask the user for the number of books you wish to download. It will display the number of books to be downloaded, the subtotal for the books, the discount earned and the total cost for the books. You should write a user-defined function to perform each of the following tasks: • print the instructions • prompt and read the number of books to be downloaded • calculate the sub total for those books • calculate the discount for your order • calculate the total cost for the downloaded books • print the results in a neat and well-labeled form
#include<bits/stdc++.h>
using namespace std;
const double discount1 = 0.15;
const double discount2 = 0.20;
const double book_price_per_peice = 8.99;
void print_the_instructions(){
cout<<"Welcome to BandN book store\n"<<
"1. Each book cost $8.99\n"<<
"2. 15\% discount on entire order\n"
"3. 20\% discount on if you buy 20 or more books\n";
}
void number_of_book_to_be_downloaded(int& n){
cout<<"How many books will be downloaded?: ";
cin>>n;
cout<<endl;
}
void calculate_subtotal(int n,double& total){
total = n*book_price_per_peice;
}
void discount20(int n,double& total){
if(n>=20)
total += n*discount2;
}
void discount15(int n,double& total){
if(n<20)
total += n*discount1;
}
void print_result(int n,double total){
cout<<"Total cost = "<<total<<endl<<
"Total books puchased = "<<n<<endl<<
"Discount applied = "<<(n>=20?20:15)<<endl;
}
int main(){
print_the_instructions();
int n;
double total = 0;
number_of_book_to_be_downloaded(n);
calculate_subtotal(n,total);
discount15(n,total);
discount20(n,total);
print_result(n,total);
}