MCC - Marquez - CIS162AB - C++ Level I
P02_ex An Example Order Calculator
   cpp.gif

The purpose of this C++ programming example is to familiarize the student with the concept of variables, constants, arithmetic expressions, simple input/output operations, and flowcharts.

Description:
This program will be used by customers to determine what the cost of their order 
would be based on the price of the item and quantity ordered.

Constant variables are used to store the following values:

    SHIPPING = 10.00       TAX_RATE = 5% (0.05)  

The user is prompted for the price of the item and the quantity ordered. 
The program then calculates the total cost using the user input and constants.
In addition, the net price is calculated, so that customers know what the 
   cost of each item is after tax and shipping has been added on.
There is no sales tax on shipping.
The results are displayed aligned on the screen, with an appropriate 
    label preceding the values. 
The output displays the tax rate that was used to calculate the tax.
The output is formatted to two decimal points. 
The formulas used are:

    subtotal  = quantity * price;
    salesTax  = subtotal * TAX_RATE;
    total     = subtotal + salesTax + SHIPPING;
    netPrice  = total / quantity;


    
Sample Output:


P02_ex - Juan Marquez    TR 1:00pm

The price and quantity ordered are entered on
the same line, but separated by a space.
Press the enter key after entering both values.

Enter the price and quantity: 12.50 30

Price:          12.50
Quantity:       30
Subtotal:       375.00
Sales Tax:      18.75 at 0.05
Shipping:       10.00
Total Due:      403.75
Net Price:      13.46

Thank you!

Press any key to continue


Source:

//P02_ex Order Calculator - An Example  Juan Marquez   TR 1:00pm
/*
 This program is used by customers to determine what the cost
 of their order would be based on the price and quantity ordered.
*/

#include <iostream>
using namespace std;

void main()
{
//Declare constants using the const modifier.
//Constant variables make programs easier maintain and read.
//When the values change, they only need to be changed one place.
//Constants are named using all capital letters.
//There are two ways of assigning values; = and ()

    const double SHIPPING = 10.00, TAX_RATE (0.05);

//Declare variables
    int  quantity;
    double price, subtotal, salesTax, total, netPrice;

//Set the decimal point to 2 positions
    cout.setf(ios::fixed);
    cout.setf(ios::showpoint);
    cout.precision(2);

    cout << "P02_ex - Juan Marquez    TR 1:00pm \n\n";

//Display the input prompt
    cout << "The price and quantity ordered are entered on\n"
         << "the same line, but separated by a space.\n"
         << "Press the enter key after entering both values."
         << endl << endl
         << "Enter the price and quantity: ";

//Get the input values    
    cin >> price >> quantity;

//Perform the calculations 
    subtotal = quantity * price; 
    salesTax = subtotal * TAX_RATE;
    total    = subtotal + salesTax + SHIPPING;
    netPrice = total / quantity;

//Display the results and echo the input (price and quantity)
//Display the values stored in constants.
//Use the space bar between : and /t in labels instead of
//the tab key for accurate alignment.
    cout << endl
         << "Price:    \t" << price     << endl
         << "Quantity: \t" << quantity  << endl
         << "Subtotal: \t" << subtotal  << endl
         << "Sales Tax:\t" << salesTax  << " at " << TAX_RATE << endl
         << "Shipping: \t" << SHIPPING  << endl
         << "Total Due:\t" << total     << endl
         << "Net Price:\t" << netPrice  << endl << endl

         << "Thank you!\n\n";
}
//end of program


IPO Chart:
Input Process Output
Price
Quantity


Constants:
Shipping = 10.00
Tax Rate = .05
subtotal = quantity * price
salesTax = subtotal * TAX_RATE
total = subtotal + salesTax + SHIPPING
netPrice = total / quantity
Price
Quantity
Subtotal
Sales Tax
Sales Tax Rate
Shipping
Total Due
Net Price
Flowchart:


p02_ex_flowchart.gif

Revised: 08/15/2003 - www.mc.maricopa.edu/~marquez/cis162ab/p02_ex_order_calc.html