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
|
#include <iostream>
#include <fstream>
#include <iomanip>
using namespace std;
//=============================================================================
// Function prototypes
void openFile(ifstream &fp);
char Shipment();
double Discount(double);
double Tax(double, double);
double Total_Bill(double, double, double, double);
void Bill(double, double, double, double, double);
//=============================================================================
// Main function executes all other functions
int main()
{
ifstream fp;
string name;
openFile(fp);
char D;
double tax;
double discount;
double ship;
double TotalBill;
double num;
double total_sum = 0;
char val;
bool flag = false;
while (fp>>num)
{
// cout << "Enter the file you want to open: ";
//cin >> name;
// Loop controls repetition of program
//put forloop here
double value, sum;
for (int counter=1; counter <=num; counter++)
{
fp>>D;
fp>>value;
sum+=value;
}
return sum;
if(num > 0)
{
cout << "===================================================" <<endl;
//D=Shipment();
if (D == 'S')
ship = 4.99;
else if (D == 'E')
ship = 12.99;
discount = Discount(total_sum);
tax = Tax(total_sum, discount);
TotalBill = Total_Bill(total_sum, discount, tax, ship);
Bill(total_sum, tax, discount, ship, TotalBill);
}
else
{
cout << "\nExit from program." << endl;
}
total_sum = 0;
}
fp.close();
return 0;
}
//=============================================================================
// Gets order data from file - NEW ADDITION
void openFile(ifstream &fp)
{
string name;
cout << "Enter file name: ";
cin >> name;
fp.open(name.c_str());
}
//=============================================================================
// Asks for shipment method (Standard=S, Expedited=E)
char Shipment()
{
char D;
cout << "Enter S for standard or E for Expedited delivery: ";
cin >> D;
return D;
}
//=============================================================================
// Executes calculations for discounts
double Discount(double sum)
{
double discount;
if (sum < 50)
discount = 0;
else if (sum >= 50 && sum <=100)
discount = (sum * .1);
else if (sum > 100)
discount = (sum * .15);
return discount;
}
// Executes calculations for tax
double Tax(double sum, double discount)
{
double tax;
return tax = ((sum - discount) * .05);
}
// Executes calculation for grand total
double Total_Bill(double sum, double discount, double tax, double ship)
{
double Total;
return Total = ((sum - discount) + tax + ship);
}
//=============================================================================
// Displays subtotal, sales tax, discounts, shipping, and grand total
void Bill(double sum, double tax, double discount, double ship, double Total)
{
cout << setprecision(2) << fixed;
cout << left << endl;
cout << setw(19) << "Subtotal: " << "$" << sum << endl;
cout << setw(19) << "Sales Tax: " << "$" << tax << endl;
cout << setw(19) << "Discount: " << "$" << discount << endl;
cout << setw(19) << "Shipping: " << "$" << ship << endl;
cout << setw(19) << "Total: " << "$" << Total << endl << endl;
}
|