In: Computer Science
c++
Write a program that displays the status of an
order.
a) Program uses 2 functions (in addition to main ()).
b) The first function asks the user for the data below and stores
the input values in reference parameters.
c) Input data from user: # of spools ordered, # of spools in stock,
any special shipping & handling charges over and above the $10
rate.
d) The second function receives as arguments any values needed to
compute and display the following information:
e) # of spools ready to ship from current stock, # of ordered
spools on backorder (if ordered > in stock),
f) Total sales price of portion ready to ship (# of spools ready to
ship X $100),
g) Total shipping and handling charges on the portion ready to
ship, Total of the order ready to ship.
h) Shipping & handling parameter in 2nd function should have a
default argument of $10.00.
I) Input validation: Do not accept numbers < 1 for spools
ordered,
J) Input validation: Do not accept numbers < 0 for spools in
stock or for shipping & handling charges.
#include <iostream>
using namespace std;
void takeInput(int &spoolsOrdered, int &spoolsInStock,
int &shippingAndHandlingCharges) {
do {
cout<<"Enter number of spools ordered: ";
cin>>spoolsOrdered;
} while(spoolsOrdered < 1);
do {
cout<<"Enter number of spools in stock: ";
cin>>spoolsInStock;
} while(spoolsInStock < 0);
do {
cout<<"Enter special shipping and haddling charges: ";
cin>>shippingAndHandlingCharges;
} while(shippingAndHandlingCharges < 0);
}
void displayInformation(int spoolsOrdered, int spoolsInStock,
int shippingAndHandlingCharges=10) {
int spoolsReadyToShip = spoolsOrdered;
int spoolsOnBackOrder = 0;
if (spoolsOrdered > spoolsInStock) {
spoolsReadyToShip = spoolsInStock;
spoolsOnBackOrder = spoolsOrdered - spoolsInStock;
}
int totalSalesPrice = spoolsReadyToShip * 100;
int totalShippingAndHandlingCharges = shippingAndHandlingCharges *
spoolsReadyToShip;
int totalPrice = totalSalesPrice +
totalShippingAndHandlingCharges;
cout<<"Spools ready to ship:
"<<spoolsReadyToShip<<endl;
cout<<"Spools on backorder:
"<<spoolsOnBackOrder<<endl;
cout<<"Total sales price:
$"<<totalSalesPrice<<endl;
cout<<"Total shipping and handling charges:
$"<<totalShippingAndHandlingCharges<<endl;
cout<<"Total price: $"<<totalPrice<<endl;
}
int main()
{
int spoolsOrdered, spoolsInStock, shippingAndHandlingCharges;
takeInput(spoolsOrdered, spoolsInStock,
shippingAndHandlingCharges);
shippingAndHandlingCharges+=10;
displayInformation(spoolsOrdered, spoolsInStock,
shippingAndHandlingCharges);
return 0;
}