1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142
|
#include<iostream>
#include <iomanip>
using namespace std;
//prototypes
void getCustomerInfo (int accountNum, int saleMonth, int saleDate, int saleYear, int countyCode);
void getItemInfo (float totalPrice, int totalWeight);
float calcDiscount (float price, int saleMonth);
int calcSalesTax (double price, char countyCode);
float calcShipping (int weight);
void outputInvoice (int accountNum, string county, int saleMonth, int saleDate, int saleYear, float price, float discount, float tax, float shipping);
int main()
{
char countyCode;
int saleMonth,saleDate, saleYear, accountNum, weight=0;
float price;
float totalPrice;
float totalWeight;
//what I'm getting from customers
getCustomerInfo(accountNum, saleMonth, saleDate, saleYear, countyCode);
getItemInfo (totalPrice,totalWeight);
//what I am calculating
float discount = calcDiscount (price, saleMonth);
float tax = calcSalesTax (price - discount, countyCode);
float shipping = calcShipping (weight);
string county;
if (countyCode == 'S')
{
county = "San Diego";
}
else if (countyCode == 'L')
{
county = "Los Angeles";
}
else if (countyCode == 'O')
{
county = "Orange";
}
outputInvoice (accountNum, county, saleMonth, saleDate, saleYear, price, discount, tax, shipping);
return 0;
}
void getCustomerInfo (int accountNum, int saleMonth,int saleDate, int saleYear, char countyCode)
{
cout << "Enter account number: ";
cin >> accountNum;
cout << "Date of sale (x/xx/xxxx): ";
cin >> saleMonth >> saleDate >> saleYear;
cout << "Enter the county code: ";
cin >> countyCode;
}
void getItemInfo (float totalPrice, int totalWeight)
{
char choice;
int weight;
float price;
totalPrice = 0;
totalWeight = 0;
cout << "\nDo you want to order an item? Enter Y or N: ";
cin >> choice;
while (choice == 'Y')
{
cout << "Enter a price: ";
cin >> price;
cout << "Enter a weight: ";
cin >> weight;
totalPrice += price;
totalWeight += weight;
cout << "Do you want to order another item? Enter Y or N: ";
cin >> choice;
}
}
float calcDiscount (float price, int saleMonth)
{
if (saleMonth >= 1 && saleMonth <= 5)
return price * 5/100;
if (saleMonth >= 6 && saleMonth <= 8)
return price * 10/100;
else
return price * 15/100;
}
int calcSalesTax (double price, char countyCode)
{
if (countyCode == 'C')
{
return price * 7.75/100;
}
else if (countyCode == 'O')
{
return price * 7.75/100;
}
else if (countyCode == 'L')
{
return price * 8.85/100;
}
}
float calcShipping (int weight)
{
if (weight <= 25)
return 5.00;
else if (weight <= 50)
{
float shipping = 5;
shipping += (weight * 1.0-25) * 10/100;
return shipping;
}
else if (weight >= 50)
{
float shipping = 7.5;
shipping += (weight *1.0-50)* 7/100;
return shipping;
}
}
void outputInvoice (int accountNum, char county, int saleMonth, int saleDate, int saleYear, float price, float discount, float tax, float shipping)
{
cout << "ACCOUNT NUMBER" << setw(20)<< "COUNTY"<< endl;
cout << accountNum << setw(30) << county << endl;
cout << "DATE OF SALE " << saleMonth << "/" << saleDate << "/" << saleYear << endl;
cout << setw(30) << std::left << "TOTAL SALE AMOUNT: " << "$" << price << endl;
cout << setw(30) << std::left << "DISCOUNT: " << "$ " << discount << endl;
cout << setw(30) << std::left <<"SALES TAX: " << "$ " << tax << endl;
cout << setw(30) << std::left << "SHIPPING: " << "$ " << shipping << endl;
cout << setw(30) << std::left << "TOTAL DUE: "<< "$ " << price+tax+shipping-discount<<endl;
}
|