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
|
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;
double totalSalesAmt = 0;
double salesTaxAmt = 0;
ifstream inputFile;
inputFile.open("SalesRegister.txt");
if (!inputFile)
{
cout << endl << "Input file not found." << endl << endl;
system("pause");
return -1;
}
inputFile >> custName >> stateCode >> quantity >> price;
double saleAmountCalc (int quantity, double price);
double salesTaxCalc (double totalSalesAmt, string stateCode);
void displaySalesData (string custName, double totalSalesAmt, double salesTaxAmt, string stateCode);
inputFile >> custName >> stateCode >> quantity >> price;
while (!inputFile.eof())
{
totalSalesAmt = saleAmountCalc(quantity, price);
salesTaxAmt = salesTaxCalc(totalSalesAmt, stateCode);
totalSalesAmt += salesTaxAmt;
inputFile >> custName >> stateCode >> quantity >> price;
}
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;
string KS;
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)
{
cout << fixed << setprecision(2);
cout << left << setw(22) << custName << right << setw(1) << "$"
<< setw(10) << totalSalesAmt << setw(3) << "$" << setw(8)
<< salesTaxAmt << " " << stateCode << endl;
}
|