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
|
using namespace std;
const double MO_SALES_TAX_RATE = 0.04316;
const double KS_SALES_TAX_RATE = 0.068;
double saleAmountCalc (int quantity, double price);
double salesTaxCalc (double totalSalesAmt, string stateCode);
void displaySalesData (string custName, double totalSalesAmt, double salesTaxAmt, string stateCode);
int main()
{
string custName;
string stateCode;
int quantity = 0;
double price = 0.00;
double totalSalesAmt = 0.00;
double salesTaxAmt = 0.00;
double salesTotal = 0.00;
double taxTotal = 0.00;
double moTax = 0.00;
double ksTax = 0.00;
char dollarSign = '$';
ifstream inputFile;
inputFile.open("SalesRegister.txt");
if (!inputFile)
{
cout << endl << "Input file not found." << endl << endl;
system("pause");
return -1;
}
cout << fixed << setprecision(2);
cout << "Customer Name: Total Sales Total Tax" << endl;
cout << "------------------------------------------------------------" << endl;
inputFile >> custName >> stateCode >> quantity >> price;
while (!inputFile.eof())
{
totalSalesAmt = saleAmountCalc(quantity, price);
salesTaxAmt = salesTaxCalc(totalSalesAmt, stateCode);
displaySalesData(custName, totalSalesAmt, salesTaxAmt, stateCode);
salesTotal += totalSalesAmt;
taxTotal += salesTaxAmt;
if (stateCode == "KS")
ksTax += salesTaxAmt;
else
moTax += salesTaxAmt;
inputFile >> custName >> stateCode >> quantity >> price;
}
cout << endl;
cout << setw(26) << dollarSign << setw(9) << salesTotal
<< setw(10) << dollarSign << setw(8) << taxTotal
<< " " << "Total" << endl << endl;
cout << setw(35) << "Sales Tax:" << setw(18) << moTax
<< " MO" << endl << endl;
cout << setw(53) << ksTax << " KS" << endl << endl;
inputFile.close();
system("pause");
return 0;
}
double saleAmountCalc (int quantity, double price)
{
double saleAmount;
saleAmount = quantity * price;
return saleAmount;
}
double salesTaxCalc (double totalSalesAmt, string stateCode)
{
double salesTaxAmt;
if (stateCode == "KS")
salesTaxAmt = totalSalesAmt * KS_SALES_TAX_RATE;
else
salesTaxAmt = totalSalesAmt * MO_SALES_TAX_RATE;
return salesTaxAmt;
}
void displaySalesData (string custName, double totalSalesAmt, double salesTaxAmt, string stateCode)
{
char dollarSign = '$';
cout << fixed << setprecision(2);
cout << left << setw(25) << custName << right << setw(1) << dollarSign
<< setw(9) << totalSalesAmt << setw(10) << dollarSign << setw(8)
<< salesTaxAmt << " " << stateCode << endl;
}
|