POSTS
Humility: Finding old programs
BlogDuring the move to our new apartment I came across a CD that had a bunch of old data files from my college days on it.
One of the files was called “C++ Programs”. This struck me as a bit funny as Lauren and I are taking C++ together at Austin Community College. For her, it is an introduction, for me it is a review.
Based on this old code I found, I definitely needed much more than a review. This, quite simply, is terrible.
Check this insanity out after the jump
//----------------------------------------------------------------------------
//What:
// Title...Homework Assignment 2
// Description:
// This program takes financial input, calculates wages, and outputs.
//
//Who:
// Author....Steven G. Harms
//
//When:
// Inception ...September 27, 1996
// Last changed September 28, 1996
// by............Steven G. Harms
//How:
// Input
// From User: Name, Social Security Number, Department, Hours,
// Sales, and Salry (if applicable).
// Public Variables:
// None
//
// Output:
// Prints out employee information to screen.
//
// Notes:
//---------------------------------------------------------------------------
#include <iostream.h>
#include <iomanip.h>
#include <conio.h>
#include <string.h>
#include <stdio.h>
//Function Prototypes
void PAK (void);
//Declaration of Global Constants
const float tax = .15; //Const est. govt. tax
const float fMKTrate = .20; //MKT commis rate
const float fFINrate = 0.00; //FIN " "
const float fISrate = .10; //IS " "
int main() { //BEGINNING OF MAIN!!!!!!!
//Variables for Main
clrscr(); //Clears for Input
char szEmpName1[11]; //Employee's first name
char szEmpName2[11]; // last name
char szSSN[12]; //Employee's Social Sec.
float fSalary; //Employee's salary
float fTaxLoss; //$ amount lost in tax
float fSales; //$ of sales
int iEmpDept; //Integer for menu of depts.
int iHours; //Time worked (non salaried)
float fNet; //Net pay
float WeeklyPay; //Pay from hours worked
float fDeptHrPay; //Pay rate for dept.
float fOvertime; //Pay rate for overtime
float fCommission; //Commission on sales
char szTrash[2];
float fWeekGross; //Commission and WklyPay
char szDept[20]; //Department name variable
char cContinue; //Test variable for loop
cout.precision(2); //Sets numbers
cout.setf (ios::fixed);
cout.setf (ios::showpoint);
cContinue ='Y';
while ((cContinue == 'Y') || (cContinue == 'y')) {
//INPUT FROM USER SECTION
cout << "Please enter an employee's first name\n";
cin.getline (szEmpName1,11);
cout << "\nPlease enter " << szEmpName1 //Gets first and last name
<< "'s last name.\n";
cin.getline (szEmpName2,11);
cout << "\nPlease enter the social security number for "
<< szEmpName1 << " " << szEmpName2 << "\n";
cin >> szSSN; //Gets Social Security No.
cout << "\nPlease enter " << szEmpName1 << "'s Department\n"
<< "\t1=Marketing\n" //Menu of Departments
<< "\t2=Finance\n" //Gets integer value for
<< "\t3=Information Systems\n"; //a department
cin >> iEmpDept;
cout << "\nPlease enter the salary for " //Gets salary for salried
<< szEmpName1 << "." //workers. Or 99 flags in
<< "\n" //decision proccess the wrkr
<< "If " << szEmpName1 //is paid by the hour.
<< " is paid hourly, enter 99.\n";
cin >> fSalary;
switch (iEmpDept) { //Based on department
case 1 : fDeptHrPay = 5.0; //provides variables
fOvertime = fDeptHrPay * 1.5; //for that depts pay
break; //Marketing //system.
case 2 : fDeptHrPay = 20.0;
fOvertime = fDeptHrPay * 1.5;
break; //Finance
case 3 : fDeptHrPay = 13.0;
fOvertime = fDeptHrPay * 1.5;
break; } //Information Systems
if (fSalary == 99){ //If flag for non-salaried is
cout << "\nHow many hours did " //up, number of hours is
<< szEmpName1 << " work?\n"; //requested.
cin >> iHours;}
cout << "\nPlease enter the amount of sales for "
<< szEmpName1 << "\n"; //Amount of sales requested
cin >> fSales; //for all employees.
cout << "\n\nInformation has been taken. Thank you\n";
//BEGIN CALCULATION SECTION HERE
PAK; //Pauses, prepares screen for
clrscr(); //output
if (fSalary == 99){
if (iHours > 40) //Calc. wkly pay for hourlies with 40+
WeeklyPay = ((40 * fDeptHrPay) + ((iHours - 40) * fOvertime));
if (iHours <= 40) //Calc. wkly pay for hourlies w/ 40 or less
WeeklyPay = iHours * fDeptHrPay;}
else
WeeklyPay = fSalary/52; //Calc. wkly pay for salaried employees
if (fSalary == 99){ //Flag splits salaried and hourly workers
if (fSales >= 10000){ //Insures hourlies' sales > $10,000
if (iEmpDept == 1) //If they are in Marketing....
fCommission = (fSales-10000) * fMKTrate;
if (iEmpDept == 2) //Or they are in Finance
fCommission = (fSales-10000) * fFINrate;
if (iEmpDept == 3) //Or they are in Info Sys
fCommission = (fSales-10000) * fISrate;
} //Yield's hourlies' commissions
}
if (fSalary != 99){ //That is, if they are salaried
if (iEmpDept == 1) //And in Marketing
fCommission = (fSales * fMKTrate);
if (iEmpDept == 2) //Finance
fCommission = (fSales * fFINrate);
if (iEmpDept == 3) //IS
fCommission = (fSales * fISrate);
} //Gets salarieds' commissions
if (fCommission >= 20000) //Insures Max Commission of $20,000
fCommission = 20000;
fWeekGross = fCommission + WeeklyPay; //Gets a gross weekly pay
fTaxLoss = fWeekGross * tax; //Takes Tax (ARRGGGH)
fNet = fWeekGross - fTaxLoss; //Takes tax from gross ==> net
if (iEmpDept == 1) //Translates menu value entered
strcpy (szDept, "Marketing"); //into a department name
if (iEmpDept == 2)
strcpy (szDept, "Finance");
if (iEmpDept == 3)
strcpy (szDept,"Information Systems");
//BEGIN OUTPUT SECTION HERE
cout << "NAME: " << szEmpName1 << " " << szEmpName2 << " "
<<" " << szSSN << "\n";
cout << "\nDEPARTMENTAL LOCATION: " << szDept;
cout << "\n\tWeekly Pay" << "..................................$"
<< WeeklyPay;
cout << "\n\tWeekly Commission...........................$"
<< fCommission;
cout << "\n\tWeekly Gross................................$"
<< fWeekGross;
cout << "\n\tEstimated Tax of 15%.......................-$"
<< fTaxLoss;
cout << "\n\tNET.........................................$"
<<fNet;
PAK();
clrscr();
cout << "Would you like to enter another employee's"
<< " information? (Y/N)";
cin >> cContinue;
cin.getline (szTrash,2);
PAK();
clrscr()fx;
}
clrscr();
return (0);
}//Close bracket for looping condition
void PAK (void) {
int x = wherex();
int y = wherey();
gotoxy (25,25);
cout << "Press any key when ready";
getch();
gotoxy(25,25);
cout << " ";
gotoxy (x,y);
return;
} //End of function PAK