/*DEFINITIONS FOR EMPLP0YEE*/ #include #include #include #include "Employee.h" using namespace std; using namespace std; Employee::Employee() { } Employee::Employee(double salary) { annual_salary = salary; } void Employee::compute_salary() { if(annual_salary < 100000.00) { netpay = annual_salary - (annual_salary * 0.3); } else if(annual_salary >= 100000.00)//40% tax for the rich { netpay = annual_salary - (annual_salary * 0.4); } monthly_salary = ( netpay / 12); } istream& operator >>(istream& ins, Employee& the_object) { /* outs.setf(ios::showpoint); outs.setf(ios::fixed); outs.precision(2);<---does not work in istream function*/ char buffer[13]; int i; int flag = 0;//page629-635 //Beginning of questions [ inputs from user ] //SSN.input do { cout << "Please enter your SOCIAL SECURITY NUMBER." << endl; /* user to input numbers and stops before "\n" new line character*/ ins.get(buffer, 13, '\n'); ins.ignore(80, '\n');//max 80 /* if the user entered 11 characters allowing the extra two are dashes*/ if(strlen(buffer) == 11) { for(i = 0; i < strlen(buffer); i++) { if((i == 3) || (i == 6)) //position 3 & 6 should be dashes only. Rest muste be #. { if(buffer[i] == '-') { flag = 0; } else { cout << "Incorrect input! Please enter it like this 111-11-1111 or 123456789 ONLY!" << endl; flag = 1; break;//stop if good } } else if(isdigit(buffer[i])) //if at position of dashes are not on 3 or 6. Repeat. { flag = 0; } else //if dashes are are the wrong spots repeat. { cout << "Incorrect input! Please enter it like this 111-11-1111 or 123456789 ONLY!" << endl; flag = 1; break;//stop if good } } } /* if the user inputed 9 characters NO DASHES*/ else if(strlen(buffer) == 9) { for(i = 0; i < strlen(buffer); i++) { if(isdigit(buffer[i])) { flag = 0; } else { cout << "Incorrect input! Please enter it like this 111-11-1111 or 123456789 ONLY!" << endl; flag = 1; break;//stop if good } } } else //if user entered anything other than 9 or 11 characters { cout << "Incorrect input! Please enter it like this 111-11-1111 or 123456789 ONLY!" << endl; flag = 1; } } while ( flag ); strcpy(the_object.ssn, buffer);//copies buffer to the_object.ssn //ID.input /* */ do { cout << "Please enter your IDENTIFICATION NUMBER. It should be 001 to 999 ONLY." << endl; ins.get(buffer, 5, '\n'); ins.ignore(80, '\n'); for(i = 0; i < strlen(buffer); i++) { if(strlen(buffer) == 3) //if user entered 3 characters { if(isdigit(buffer[i])) //checks if input are DIGITS { flag = 0; } else// if user inputs less than 3 or more than 3 digits { cout << "Incorrect input!Please choose a number between 001 - 999." << endl; flag = 1; break; } } else //if user entered length other than 3 { cout << "Incorrect input!Please choose a number between 001 - 999." << endl; flag = 1; break; } } } while ( flag ); strcpy(the_object.id, buffer);/// buffer to the_object.id //SALARY.input /* "<< endl; ins >> the_object.annual_salary; ins.ignore(80, '\n'); } while(the_object.annual_salary < 0);//salary cannot be negative or will be looped the_object.compute_salary(); return ( ins ) ; } ostream& operator <<(ostream& outs, const Employee& emp) { outs.setf(ios::showpoint); outs.setf(ios::fixed); outs.precision(2); outs << "Your SOCIAL SECURITY NUMBER is: " << emp.ssn << '.' << endl; outs << "Your ID # is : " << emp.id << '.' << endl; outs << "Your Annual Salary: " << emp.annual_salary << '.' << endl; outs << "Your pay after taxes is$ " << emp.netpay << '.' << endl; outs << "Your monthly salary is $ " << emp.monthly_salary << '.' << endl; return ( outs ) ; } //END OF DEFINITIONS FINALLY....weee8:48pm