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 143 144 145 146 147 148 149 150 151
|
#include <iostream>
#include <fstream>
#include <string>
#include <limits>
using namespace std;
int main()
{
char ch;
double gross;
string name;
cout << fixed;
cout.precision(2);
do
{
cout << "\nPlease enter the name of the employee: ";
getline(cin, name);
cout << "\nPlease enter the gross pay for the employee: ";
cin >> gross;
cout << "You entered: " << name << endl;
cout << "and: $" << gross << endl;
cout << "Is this correct? (y/n)";
(cin >> ch).get();
} while (ch == 'n' || ch == 'N');
cout << "\nThank you.\nThe following taxes will be applied\n.";
cout << "and the itemized list will be saved to the output\n";
cout << "file, \"taxes.txt\"" << endl;
//These matrices hold the names of each tax\deduction
//and the percentage, respectively
const char * tax_list[6] = { "Federal Income Tax", "State Tax", "Social Security Tax",
"Medicare/Medicaid", "Pension Plan", "Health Insurance" };
double tax_percent[6] = { 15, 3.5, 5.75, 2.75, 5, 75 };
//Loop to display the first five tax names, because....
for (int i = 0; i < 5; i++)
{
cout << left;
cout.fill(' ');
cout.width(20);
cout << tax_list[i] << ": ";
cout << right;
cout.fill('.');
cout.width(10);
cout << tax_percent[i] << "%\n";
}
//..."Health Insurance" is a set payment of $75.00
cout <<left;
cout.fill(' ');
cout.width(20);
cout << tax_list[5] << ": ";
cout << right;
cout.fill('.');
cout.width(9);
cout << "$" << tax_percent[5] << "\n";
//net tracks the reductions of gross as each tax is paid
double net = gross;
//taxes_paid hold the dollar amount of each deduction
double taxes_paid[6];
for ( int i = 0; i < 5; i++)
{
taxes_paid[i] = (tax_percent[i]/ 100) * gross;
net -= taxes_paid[i];
}
taxes_paid[5] = 75;
net -= taxes_paid[5];
ofstream fout;
fout.open("taxes.txt");
//prints the name the user entered
fout << left;
fout.fill(' ');
fout.width(20);
fout << "Name: ";
fout.fill('.');
fout << right;
fout.width(24);
fout << name << endl;
//prints the gross income the user entered
fout << left;
fout.fill(' ');
fout.width(20);
fout << "Gross Income: ";
fout.fill('.');
fout << right;
fout.width(7);
fout << fixed;
fout.precision(2);
fout << "$" << gross << endl;
//prints the dollar amount deducted for each tax, including
//"health insurance"
for ( int i = 0; i < 6; i++)
{
fout << left;
fout << tax_list[i] << ": ";
fout.width(20);
fout.fill('.');
fout << right;
fout << "$";
fout.fill(' ');
fout.width(7);
fout.precision(2);
fout << taxes_paid[i] << "\n";
}
//prints net income
fout << left;
fout.fill('.');
fout.width(20);
fout << "Net Income: ";
fout << right;
fout << "$";
fout.fill(' ');
fout.width(7);
fout.precision(2);
fout << net << endl;
fout.close();
cout << "\nData saved to file successfully." << endl;
cout << "\n\nAssignment: Example 3.6";
cout << "\nProgrammed by: Otto von Sturfenslager-Bleishtifter" << endl;
cout << "\n\nPress ENTER to close this window";
cin.ignore(numeric_limits<streamsize>::max(), '\n');
return 0;
}
|