VB Mail Order Chapter 4 Visual Basic Calculate the amount due for an order. For
ID: 3755327 • Letter: V
Question
VB Mail Order Chapter 4 Visual Basic
Calculate the amount due for an order. For each order, the user should enter the following information into text boxes: customer name, address, city, state (two letter abbreviation), and ZIP code. An order may consist of multiple items. For each item, the user will enter the product description, quantity, weight, and price into text boxes.
You will need buttons for Add This Item, Update, Summary, Clear,Print, and Exit. For the Add This Itembutton, validate the quantity, weight, and price. Each must be present and numeric.
For any bad data, display a message box. Calculate the charge for the current item and add the charge and weight into the appropriate totals, but do not display the summary until the user clicks the Update Summarybutton. Do not calculate shipping and handling on individual items; rather, calculate shipping and handling on the entire order.
When the user clicks Add This Itemfor a new order, the customer information should be disabled so that the state cannot be changed until the next customer.
When the Update Summarybutton is clicked, calculate the sales tax, shipping and handling, and the total amount due for the order. Sales tax is 8 percent of the total charge and is charged only for shipments to a California address. Do not charge sales tax on the shipping and handling charges. The shipping and handling should be calculated only for a complete order.
Optional: Disable the Add This Itembutton when the Summarybutton is pressed.
The Clearbutton clears the data and totals for the current customer.
The shipping and handling charges depend on the weight of the products. Calculate the shipping charge as $.25 per pound and add that amount to the handling charge (taken from the following table).
Display the entire amount of the bill in controls titled Dollar amount due, Sales tax, Shipping and handling, and Total amount due.
Weight Handling Less than 10 pounds $1.00 10 to 100 pounds $3.00 Over 100 pounds $5.00Explanation / Answer
//program to read data and calculating the due for order.
//header section
#include < iostream >
#include < string >
using namespace std;
//structure for customer information
struct Customer
{
string name;
string address;
string city;
char state[2];
string zipcode;
};
//structure for item information
struct Item
{
string productName;
int quantity;
double price;
};
//setting up of function prototypes
int validateQuantity(int);
double validatePrice(double);
double calculateShipping(double);
//main function
int main()
{
//declaration
double subTotal=0,total;
double groundShipping;
struct Customer c;
struct Item i;
char ch;
int items=0;
//prompting user to enter customer details
cout<<"Enter Customer Details"<<endl;
cout<<"Name:";
cin>>c.name;
cout<<"Address";
cin>>c.address;
cout<<"City";
cin>>c.city;
cout<<"State";
cin>>c.state;
cout<<"Zip Code";
cin>>c.zipcode;
//inputting items data
do
{
cout<<"Enter Item Name";
cin>>i.productName;
cout<<"Quantity:";
cin>>i.quantity;
//validating quantity
i.quantity=validateQuantity(i.quantity);
cout<<"Price:";
cin>>i.price;
//validating price
i.price=validatePrice(i.price);
subTotal=subTotal+(i.price*i.quantity);
//ask user to continue or not
cout<<"Do you want to enter another item (Y/N):";
cin>>ch;
ch=toupper(ch);
items=items+i.quantity;
}while(ch=='Y');
//calculating shipping
groundShipping=calculateShipping(subTotal);
cout<<endl;
//display data as output
cout<<"Data Output"<<endl;
cout<<c.name<<endl;
cout<<c.address<<endl;
cout<<c.city<<","<<c.state<<" "<<c.zipcode<<endl;
cout<<"Items Ordered "<<items<<endl;
cout<<"Sub Total :$"<<subTotal<<endl;
cout<<"Shipping :$"<<groundShipping<<endl;
cout<<"Total :$"<<subTotal+groundShipping<<endl;
system("pause");
}//end of main
//definition to calculateShipping
double calculateShipping(double t)
{
//return the appropriate value
if(t<15)
return(4.95);
else if(t>=15&&t<50)
return(6.95);
else if(t>=50&&t<100)
return(8.95);
else if(t>=100&&t<200)
return(10.95);
else
return(12.95);
}
//validating quantity
int validateQuantity(int q)
{
int qty;
if(q>0)
return q;
else
do
{
cout<<"You haveentered the wrong info, Please re-enter again";
cin>>qty;
}while(qty>0);
return qty;
}
//validating price
double validatePrice(double p)
{
double price;
if(p>0)
return p;
else
do
{
cout<<"You haveentered the wrong info, Please re-enter again";
cin>>price;
}while(price>0);
return price;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.