Question

In: Computer Science

c++ A program that displays the status of an order. a) Program uses 2 functions (in...

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.

Solutions

Expert Solution

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:


Related Solutions

*****For C++ Program***** Overview For this assignment, write a program that uses functions to simulate a...
*****For C++ Program***** Overview For this assignment, write a program that uses functions to simulate a game of Craps. Craps is a game of chance where a player (the shooter) will roll 2 six-sided dice. The sum of the dice will determine whether the player (and anyone that has placed a bet) wins immediately, loses immediately, or if the game continues. If the sum of the first roll of the dice (known as the come-out roll) is equal to 7...
In C# A Tic Tac Toe program that uses functions and arrays. The program should start...
In C# A Tic Tac Toe program that uses functions and arrays. The program should start by asking the player one for their name and then player two for their name. Then should print the board and ask the user what column and then what row they would like to put their x (or o, depending on the player) . Use the clear function to make it look as though the board is never repeating.. Thanks!
C++ Overloaded Hospital Write a program that computes and displays the charges for a patient’s hospital...
C++ Overloaded Hospital Write a program that computes and displays the charges for a patient’s hospital stay. First, the program should ask if the patient was admitted as an in-patient or an out-patient. Please keep asking the user until the user enters the valid choice. Please refer to the test cases for more details. If the patient was an in-patient the following data should be entered: • The number of days spent in the hospital • The daily rate •...
Write a program in C++ that asks the user for his/her Taxable Income and displays the...
Write a program in C++ that asks the user for his/her Taxable Income and displays the Income Tax owed. Use the following table to calculate the Income Tax: Taxable Income Tax Rate $0 to $9,225 / 10% $9,226 to $37,450 / $922.50 plus 15% of the amount over $9,225 $37,451 to $90,750 / $5,156.25 plus 25% of the amount over $37,450 $90,751 to $189,300 / $18,481.25 plus 28% of the amount over $90,750 $189,301 to $411,500 / $46,075.25 plus 33%...
Write a C++ program that displays the numbers between 1000 and 9999, which are divisible by...
Write a C++ program that displays the numbers between 1000 and 9999, which are divisible by sum of the digits in them. For example, 2924 is divisible by (2+9+2+4 = 17). Your program should display all these possible numbers in the given range, and each number should be separated from the other by a space.
Complete Question 1a-c 1a) Write a C program that displays all the command line arguments that...
Complete Question 1a-c 1a) Write a C program that displays all the command line arguments that appear on the command line when the program is invoked. Use the file name cl.c for your c program. Test your program with cl hello goodbye and cl 1 2 3 4 5 6 7 8 and cl 1b) Write a C program that reads in a string from the keyboard. Use scanf with the conversion code %s. Recall that the 2nd arg in...
This phyton program takes in three integer parameters and displays them in ascending order. You can...
This phyton program takes in three integer parameters and displays them in ascending order. You can assume that the numbers entered are integers. You CAN'T use lists, min(), max(), or the sort utility. The point is to use if tests. sortThreeIntegers( 39, 2, 5 ) should display: The numbers in order are: 2 5 39 sortThreeIntegers( 14, -12, -1000 ) should display: The numbers in order are: -1000 -12 14 def sortThreeIntegers( x, y, z ): < your code goes...
Write a program in C++ that generates and displays the first N three digit odd numbers....
Write a program in C++ that generates and displays the first N three digit odd numbers. Whereas the number N is provided by the user.
Write a C Program that uses file handling operations of C language. The Program should perform...
Write a C Program that uses file handling operations of C language. The Program should perform following operations: 1. The program should accept student names and students’ assignment marks from the user. 2. Values accepted from the user should get saved in a .csv file (.csv files are “comma separated value” files, that can be opened with spreadsheet applications like MS-Excel and also with a normal text editor like Notepad). You should be able to open and view this file...
Overview For this assignment, write a program that uses functions to simulate a game of Craps....
Overview For this assignment, write a program that uses functions to simulate a game of Craps. Craps is a game of chance where a player (the shooter) will roll 2 six-sided dice. The sum of the dice will determine whether the player (and anyone that has placed a bet) wins immediately, loses immediately, or if the game continues. If the sum of the first roll of the dice (known as the come-out roll) is equal to 7 or 11, the...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT