#include #include #include #include #include "utile.h" #define PAY_SIZE 10 struct payroll { char name[50]; int rate; int hours; int overtime; int rpay; int opay; int gpay; int paycode; }; void DisplayHead(); void LoadPay(char* pay); void ConvertThePay(char* pay,payroll* payx); void AddPay(int index, char* line,payroll* payx); void DisplayPay(payroll* payx); // string manipulation void leftstr(char* buff, char* buff2, int index); void rightstr(char*, char* , int); void midstr(char*, char*, int, int); int instr(char*, char*); int instrback(char* buff, char* search); int main() { char payrollx[500]; payroll pay_roll[PAY_SIZE]; PrintTitle(); PrintDate(); DisplayHead(); LoadPay(payrollx); ConvertThePay(payrollx,(payroll*)&pay_roll); DisplayPay((payroll*)&pay_roll); return 0; } void DisplayHead() { cout <= 40) { int diff; diff = payx[index].hours - 40; payx[index].opay = diff * payx[index].paycode * (payx[index].paycode / 2); } else { payx[index].opay = 0; } payx[index].gpay = payx[index].opay + payx[index].rpay; } void DisplayPay(payroll* payx) { cout << "\n"; for(int i = 0; i < 5 ; i++) { cout << "\t" << payx[i].name << "\t" << payx[i].paycode << "\t" << payx[i].hours << "\t" << payx[i].rpay << "\t" << payx[i].opay << "\t" << payx[i].gpay << "\n"; } int thours = 0; int trpay = 0; int topay = 0; int tgpay = 0; int eo = 0; int emax = 0; for(i = 0; i < 5; i++) { thours = thours + payx[i].hours; trpay = trpay + payx[i].rpay; topay = topay + payx[i].opay; tgpay = tgpay + payx[i].gpay; if(payx[i].hours >= 40) { eo++; } } emax = i; cout <<"\n"; cout << "total hours: " << thours << "\n"; cout << "total regular pay: " << trpay << "\n"; cout << "total overtime pay: " << topay << "\n"; cout << "total gross pay: " << tgpay << "\n"; cout << "number of employes: " << emax << "\n"; cout << "number of employes with over time: " << eo << "\n"; } /* string manipulation algorithims to convert text data into its structure */ void leftstr(char* buff, char* buff2, int index) { strcpy(buff2, buff); buff2[index + 1] = 0; } void rightstr(char* buff, char* buff2, int index) { int i = 0; int len = strlen(buff); for(int x = index; x < len; x++) { buff2[i] = buff[x]; i++; } buff2[i] = 0; } void midstr(char* buff, char* buff2, int start, int stop) { int i = 0; for(int x = start; x < stop; x++) { buff2[i] = buff[x]; i++; } buff2[i] = 0; buff2[i+1] = '\0'; } int instr(char* buff, char* search) { int slen = strlen(search); int blen = strlen(buff); for(int x = 0; x < blen; x++) { if(buff[x] == search[0]) { int ss = x; bool start = true; for(int i = 0; i < slen; i++) { if(buff[x+i] == search[i]) { } else { start = false; } } if(start == true) { return ss; } } } return 0; } int instrback(char* buff, char* search) { int len; len = strlen(buff); for(int i = len; i > 0; i--) { if(buff[i] == search[0]) { int slen; slen = strlen(search); bool stest = false; for(int y = 0; y < slen; y++) { if(buff[i+y] == search[y]) { stest = true; } else { stest = false; } } if(stest == true) { return i; } } } return 0; }