by
0
4
2,383
0
Top 1% !
Popular
Famous
Specified
Popularity: 7103rd place
Created
Modified May 18, 2013
This snippet is Public
No tags for this snippet yet.
BrowserChrome
Chrome Version26.0.1410.64
LicenseMIT_X11
OSWindows
Windows VersionWindows7

CODE ~ BAREBONES

THIS IS THE FINAL *WORKING* PROJECT
Copy Embed Code
<iframe id="embedFrame" style="width:600px; height:300px;"
src="https://www.snip2code.com/Embed/1116/CODE---BAREBONES?startLine=0"></iframe>
Click on the embed code to copy it into your clipboard Width Height
Leave empty to retrieve all the content Start End
// Program : Bilbo Project Draft #2 // Name : Barebone Function Example // Author : Jonah McLachlan // Date : Date Started 24/04/2013 // Change Log : 16/05/2013 //----------Declarations---------- #include <iostream> #include <input2010.h> #define myTextFile "C:/Users/Jonah/Documents/timesheet.txt" //------------Struct------------- struct timesheet { char name[30]; int depId; float normHours, overHours, rateOfPay; double empNo, grossPay, natIns, tax, netPay, wkEndDate; bool deleted; }; //-------------Prototypes------------- void menu(char &choice); void pick( char &choice, timesheet ts[], int &rows); void input(timesheet ts[], int &rows); void readFile(timesheet timesheets[], int &rows); void writeFile ( timesheet timesheets[], int rows); void calculate(timesheet ts[], int &rows); void displayAll(timesheet timesheet[], int rows); void report(timesheet ts[], int rows); void search(timesheet ts[], int rows); void del(timesheet ts[], int rows); void quit(); //-----------------Main------------------- void main() { char choice = 'x'; timesheet ts[99]; int rows = 0; char close = ' '; system("Color 0A"); readFile(ts,rows); while (choice != 'q' && choice != 'Q') { menu(choice); pick(choice,ts,rows); } writeFile(ts, rows); quit(); } //----------------Menu & Choice---------- void menu(char &choice) { clrscr(); cout << "\n\t\t\t------------Main Menu-----------"; cout << "\n\t\t\t| |"; cout << "\n\t\t\t| (I)Input data |"; // cout << "\n\t\t\t| (D)isplay data |"; cout << "\n\t\t\t| (R)eport data |"; cout << "\n\t\t\t| (S)earch data |"; cout << "\n\t\t\t| (C)lear data |"; cout << "\n\t\t\t| (Q)uit |"; cout << "\n\t\t\t| |"; cout << "\n\t\t\t| |"; cout << "\n\t\t\t---------------------------------" << "\n\n>>>" ; Input(choice); } void pick(char &choice, timesheet ts[], int &rows) { switch(choice) { case 'i' | 'I' : input(ts, rows); break; case 'd' | 'D' : displayAll(ts, rows); break; case 'r' | 'R' : report(ts, rows); break; case 's' | 'S' : search(ts, rows); break; case 'c' | 'C' : del(ts, rows); break; case 'q' | 'Q' : quit(); break; default : "\n\tInvalid Input!"; } } //----------------InputData------------------ void input(timesheet ts[], int &rows) { ts[rows].normHours = 0; ts[rows].rateOfPay = 0; ts[rows].depId = 0; ts[rows].empNo = 0;ts[rows].grossPay = 0; ts[rows].natIns = 0; ts[rows].tax = 0; ts[rows].netPay =0; int error = 0; clrscr(); cout << "Adding Employee to timesheet...\n"; cout<< "Employee Name : "; cin >> ts[rows].name; // cout<<"Invalid data type. Please enter text only, which is a valid Name"<< endl; //cout<< "Employee Number : "; //Input(ts[rows].empNo); do{ cout<< "Employee Number : "; cin >> ts[rows].empNo; if (cin.fail()) { cout << "Invalid data type!"<< endl; error =1; cin.clear(); cin.ignore(8, '\n'); cout<< "Employee Number : "; cin >> ts[rows].empNo; break; } } while(error == 1); error = 0; do{ cout<< "Department ID : "; cin >> ts[rows].depId; if (cin.fail()) { cout << "Invalid data type!"<< endl; error =2; cin.clear(); cin.ignore(8, '\n'); cout<< "Department ID : "; cin >> ts[rows].depId; break; } } while(error == 2); error = 0; cout<< "Normal Working Hours : "; cin >> ts[rows].normHours; //input nhours, false, in nhour, in ohours, false, normal if (ts[rows].normHours >= 37.4) { cout<< "Employee Working OVER Hours : " << endl; cin >> ts[rows].overHours; } cout<< "Employee Rate of Pay : "; do { cin >> ts[rows].rateOfPay; if (cin.fail()) { cout << "Invalid Data Type!" << endl; error = 4; cin.clear(); cin.ignore(50, '\n'); cout << "Employee Rate of Pay" << endl; cin >> ts[rows].rateOfPay; break; } } while (error == 4); //Need to add in data validation //else // cout<<"Invalid data type. Please enter numbers only, which are in the correct Working Rate of Pay format" << endl; cout<< "Weekend date DD/MM/YYYY/ : "; cin >> ts[rows].wkEndDate; //string date = ts[rows].wkEndDate; ts[rows].deleted=false; //Gross ts[rows].grossPay= ts[rows].normHours * ts[rows].rateOfPay; cout << "Gross Pay: \t" << ts[rows].grossPay << endl; //Tax ts[rows].tax = ts[rows].grossPay * 12.75; cout << "Pay After Tax: \t" << ts[rows].tax << endl; //NI ts[rows].natIns = ts[rows].grossPay * 6.8; cout <<"Pay After NI:\t" << ts[rows].natIns << endl; //NET ts[rows].netPay = ts[rows].grossPay - ts[rows].natIns - ts[rows].tax; cout <<"Net Pay: \t" << ts[rows].netPay << endl; //Display Employee cout <<"\n\n Name: "<< ts[rows].name << "\n Emp No: \t" << ts[rows].empNo << "\n Dep ID: \t" << ts[rows].depId <<"\n Norm Hrs: \t" << ts[rows].normHours << endl; if (ts[rows].normHours < 37.4) { cout << " Over Hrs: \t0" <<"\n Payrate: \t" << ts[rows].rateOfPay << "\n Wkd Date: \t"<< ts[rows].wkEndDate << "\n Net Pay: \t" << ts[rows].netPay << endl; } else if (ts[rows].normHours = 37.5) { cout << " Over Hrs: \t"<< ts[rows].overHours <<"\n Payrate: \t" << ts[rows].rateOfPay << "\n Wkd Date: \t"<< ts[rows].wkEndDate << "\n Net Pay: \t" << ts[rows].netPay << endl; } rows++; //clrscr(); pressKey(); } void readFile(timesheet ts[], int &rows) { ifstream myfile(myTextFile,ios::binary); if (!myfile.is_open()) cout << "Unable to open file: " << myTextFile << endl; else { while ( !myfile.eof() ) { myfile.read((char *)&ts[rows], sizeof(timesheet)); rows++; } rows--; myfile.close(); } pressKey(); } // WRITE OUT 1 RECORD AT A TIME void writeFile (timesheet ts[], int rows) { int r=0; ofstream myfile(myTextFile,ios::binary); if (myfile.is_open()) { while ( r < rows ) { myfile.write((char *)&ts[r], sizeof(timesheet)); r++; } myfile.close(); cout << "Data written to " << myTextFile << "\n"; } else cout << "Unable to open file: " << myTextFile << endl; } //-----------------Display, Report and Search----------------------- void displayAll(timesheet ts[], int rows) { for (int r=0;r<rows;r++) { if (ts[r].deleted == false) { cout <<"\n\n Name: "<< ts[r].name << "\n Emp No: \t" << ts[r].empNo << "\n Dep ID: \t" << ts[r].depId <<"\n Norm Hrs: \t" << ts[r].normHours << endl; if (ts[r].normHours < 37.4) { cout << " Over Hrs: \t0" <<"\n Payrate: \t" << ts[r].rateOfPay << "\n Wkd Date: \t"<< ts[r].wkEndDate << "\n Net Pay: \t" << ts[r].netPay << endl; } else if (ts[r].normHours = 37.5) { cout << " Over Hrs: \t"<< ts[r].overHours <<"\n Payrate: \t" << ts[r].rateOfPay << "\n Wkd Date: \t"<< ts[r].wkEndDate << "\n netPay: \t" << ts[r].netPay << endl; } } } system("Pause"); //display in a loop } void report(timesheet ts[], int rows) { //This function is supposed to recieve an input for either a Department or an Employee Number to show the TOTALS for each. int dRep; char eRep[21]; char choice; clrscr(); cout << "Please press 1 for DEP or\nPlease press 2 for EMPLOYEE" <<endl; Input(choice); if (choice == '1') { cout << "Please enter a searchable department ID:" << endl; cin >> dRep; for (int r=0;r<rows;r++) { if ( dRep == ts[r].depId ) { cout << "[ " << ts[r].depId << " ]" << "\t" << ts[r].name<< "\nTotals for Deparment: \t" << ts[r].netPay << endl; } } pressKey(); } else if(choice == '2') { cout << "Please enter an Employee name" << endl; cin >> eRep; for(int i=0;i<rows;i++) { if (_strnicmp(eRep, ts[i].name, strlen(eRep) ) == 0 ) { if ( ts[i].deleted == false ) { cout << ts[i].name << "\nTotal Pay Amount: \t" << ts[i].netPay << endl; pressKey(); } } } } pressKey(); //Input Check //if report1 != name or department //DISPLAY "ERROR: Invalid Data Type!" //ENDIF //Calculate report1 and report2 //Print Result //Return to main menu*/ } void search(timesheet ts[], int rows) { double date1; double date2; double taxDate; cout << "Please enter date 1" << endl; Input(date1); cout << "Please enter date 2" << endl; Input(date2); for (int r=0;r<rows;r++) if (ts[r].deleted == false){ { if ( date1 == ts[r].wkEndDate) { cout << ts[r].name << "\t" << ts[r].depId<< "\nTotals for weekend: \t" << ts[r].netPay << endl << endl; pressKey(); } } for (int r=0;r<rows;r++) { if ( date2 == ts[r].wkEndDate) { cout << ts[r].name << "\t" << ts[r].depId<< "\nTotals for weekend: \t" << ts[r].netPay << endl << endl;; cout << "Press any key to calculate the tax total for the above 2 dates" << endl; pressKey(); } } } taxDate = date2 - date1; cout << "The tax total between these two dates are: \t" << taxDate << endl; pressKey(); /* Get tax for date1 Get tax for date2 Calculate difference Print result */ } void del(timesheet ts[] ,int rows) { clrscr(); cout << "this is Delete\n"; char yesno; char name[21]; cout << "Enter Emp Name : "; Input(name,20); for (int r=0;r<rows;r++) { if ( _strnicmp(name, ts[r].name, strlen(name) ) == 0 ) { clrscr(); cout << ts[r].name <<endl; cout << ts[r].empNo <<endl; cout << ts[r].normHours<<endl; //cout << ts[r].wkEndDate <<endl; cout << "Delete this employee (y/n)? : "; Input(yesno); yesno = tolower(yesno); if ( yesno == 'y' ) { ts[r].deleted = true; } pressKey(); } } pressKey(); } //-----------------Close the application----------------- void quit() { cout << "Program closing \t"; }
If you want to be updated about similar snippets, Sign in and follow our Channels

blog comments powered by Disqus