Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Programming Challenge 14: Order Status, Gaddis\' text: pages 370-371. Program Te

ID: 3829437 • Letter: P

Question

Programming Challenge 14: Order Status, Gaddis' text: pages 370-371.

Program Template:

/**
* Chapter 6, Programming Challenge 14: Order Status,
* Gaddis' text: pages 370-371
*/

// Author: Place your name here

#include <iostream>
#include <iomanip>
using namespace std;

// Function prototypes
void getStockInfo(int &, int &, double &);
void displayStatus(int, int, double = 10.00);

int main()
{
int ordered; // To hold the spools ordered
int inStock; // To hold the spools in stock
double specialShipping; // To hold any special shipping charges

// TODO: Call function getStockInfo - Get the order and stock information.

// TODO: Call function displayStatus
// Determine whether there are special charges and display the order status.

return 0;

}

//*********************************************************
// The getStockInfo function asks the user for the number *
// of spools ordered, the number of spools in stock, and *
// any special shipping charges. The values are validated *
// and stored in reference parameters. *
//*********************************************************

void getStockInfo(int &ordered, int &inStock, double &specialShipping)
{
char choice; // To hold 'y' or 'n'

// TODO: Get the number of spools ordered.

// TODO: Validate the number of spools ordered.

// TODO: Get the number of spools in stock.

// TODO: Validate the number of spools in stock.

// Get the special shipping charges, if any.
cout << "Are special shipping charges required? (y or n): ";
cin >> choice;

if (choice == 'Y' || choice == 'y')
{
cout << "Enter the amount of any special "
<< "shipping charges: ";
cin >> specialShipping;

// Validate the special shipping charges.
while (specialShipping < 0)
{
cout << "Special shipping charges "
<< "must be zero or more. "
<< "Enter the amount of any special "
<< "shipping charges: ";
cin >> specialShipping;
}
}
else
specialShipping = 0;
}

//*********************************************************
// The displayStatus function accepts as arguments the *
// number of spools ordered, the number in stock, and the *
// shipping charges per spool. *
//*********************************************************

void displayStatus(int ordered, int inStock, double specialShipping)
{
const double UNIT_SPOOL_COST = 100.00;

int available = ordered; // Number of spools available to ship
int backOrder = 0; // Number of spools back ordered

double spoolCost; // Charges for spools shipping now
double shipCharges; // Shipping charges for this shipment
double totalCharges; // Cost of shipped spools + shipping chgs

// Determine whether any spools are back ordered.
if (ordered > inStock)
{
available = inStock;
backOrder = ordered - inStock;
}

// TODO: Calculate the charges.

// Display the order summary.
cout << " Order Summary "
<< "================== "
<< " Items ordered: " << ordered
<< " Ready to ship: " << available;

if (available < ordered)
{
cout << " On backorder: " << backOrder;
}

cout << fixed << showpoint << setprecision(2)
<< endl
<< " Subtotal: $" << setw(8) << spoolCost
<< " Shipping: $" << setw(8) << shipCharges
<< " Total Due: $" << setw(8) << totalCharges
<< endl;
}

Explanation / Answer

#include <iostream>
#include <iomanip>
using namespace std;
// Function prototypes
void getStockInfo(int &, int &, double &);
void displayStatus(int, int, double = 10.00);
int main(){
   int ordered = 10; // To hold the spools ordered
   int inStock = 5; // To hold the spools in stock
   double specialShipping; // To hold any special shipping charges
  
   getStockInfo(ordered,inStock,specialShipping); // TODO: Call function getStockInfo - Get the order and stock information.
   displayStatus(ordered, inStock,specailCharges); // TODO: Call function displayStatus

   // Determine whether there are special charges and display the order status.

//this functionality already implemented in invidual methods
return 0;
}
//*********************************************************
// The getStockInfo function asks the user for the number *
// of spools ordered, the number of spools in stock, and *
// any special shipping charges. The values are validated *
// and stored in reference parameters. *
//*********************************************************
void getStockInfo(int &ordered, int &inStock, double &specialShipping){
   char choice; // To hold 'y' or 'n'
   // TODO: Get the number of spools ordered.
   // TODO: Validate the number of spools ordered.
   // TODO: Get the number of spools in stock.
   // TODO: Validate the number of spools in stock.
   // Get the special shipping charges, if any.
   cout << "Are special shipping charges required? (y or n): ";
   cin >> choice;
   if (choice == 'Y' || choice == 'y'){
       cout << "Enter the amount of any special "
       << "shipping charges: ";
       cin >> specialShipping;
       // Validate the special shipping charges.
       while (specialShipping < 0)
       {
           cout << "Special shipping charges "
           << "must be zero or more. "
           << "Enter the amount of any special "
           << "shipping charges: ";
           cin >> specialShipping;
       }
   }
   else
       specialShipping = 0;
   }  
//*********************************************************
// The displayStatus function accepts as arguments the *
// number of spools ordered, the number in stock, and the *
// shipping charges per spool. *
//*********************************************************
void displayStatus(int ordered, int inStock, double specialShipping)
{
   const double UNIT_SPOOL_COST = 100.00;
   int available = ordered; // Number of spools available to ship
   int backOrder = 0; // Number of spools back ordered
   double spoolCost; // Charges for spools shipping now
   double shipCharges; // Shipping charges for this shipment
   double totalCharges; // Cost of shipped spools + shipping chgs
   // Determine whether any spools are back ordered.
   if (ordered > inStock)
   {
       available = inStock;
       backOrder = ordered - inStock;
   }
   // TODO: Calculate the charges.
   // Display the order summary.
   cout << " Order Summary "
   << "================== "
   << " Items ordered: " << ordered
   << " Ready to ship: " << available;
   if (available < ordered)
   {
       cout << " On backorder: " << backOrder;
   }
   cout << fixed << showpoint << setprecision(2)
   << endl
   << " Subtotal: $" << setw(8) << spoolCost
   << " Shipping: $" << setw(8) << shipCharges
   << " Total Due: $" << setw(8) << totalCharges
   << endl;
}