In: Computer Science
c++
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.
Code:
#include<iostream>
using namespace std;
void fun1(int &spools_ordered, int &spools_stock, int
&special_charges)//function 1
{
while(1)
{
cout << "# of spools ordered:
";cin>>spools_ordered;
if(spools_ordered < 1)//input
validation
{
cout <<
"Enter proper input" <<endl;
}
else break;
}
while(1)
{
cout << "# of spools in
stock: ";cin>>spools_stock;
if( spools_stock < 0)//input
validation
{
cout <<
"Enter proper input" <<endl;
}
else break;
}
while(1)
{
cout << "special shipping
& handling charges over and above the $10 rate:
";cin>>special_charges;
if( special_charges < 0)//input
validation
{
cout <<
"Enter proper input" <<endl;
}
else break;
}
}
void fun2(int &spools_stock, int &spools_ordered, int
&spools_ready, int &spools_backorder, int &sales_ready,
int &total_ready, int &total_shipping, int
shipping_charges=10)//function2 with default argument
{
spools_ready = spools_stock;//since no of spools ready
to be shipped are those which are in the stock
spools_backorder = (spools_ordered > spools_stock ?
spools_ordered - spools_stock : 0);//if there is enough stock,
backdoor is 0 otherwise, it is the difference of spools ordered to
those in stock
sales_ready = spools_ready * 100;//sales is spools *
100
total_shipping = spools_ready *
shipping_charges;//product of no of spools and their shipping
charges
total_ready = sales_ready + total_shipping;//total is
sales + shipping for all the spools
}
int main()
{
int spools_ordered, spools_stock, special_charges,
spools_ready, spools_backorder, sales_ready, shipping_charges,
total_ready, total_shipping;
fun1(spools_ordered, spools_stock,
special_charges);
fun2(spools_stock, spools_ordered, spools_ready,
spools_backorder, sales_ready, total_ready, total_shipping,
special_charges);
cout << "# of spools ordered: " <<
spools_ordered << endl;
cout << "# of spools in stock: " <<
spools_stock << endl;
cout << "# of spools ready to ship from current
stock: " << spools_ready << endl;
cout << "# of ordered spools on backorder: "
<< spools_backorder << endl;
cout << "Total sales price of portion ready to
ship: " << sales_ready << endl;
cout << "Total shipping and handling charges on
the portion ready to ship: " << total_shipping <<
endl;
cout << "Total of the order ready to ship: "
<< total_ready << endl;
return 0;
}
Output: