by
0
6
3,054
3
Top 1% !
Popular
Famous
Tagged
Specified
Refined
Popularity: 4674th place
Created
Modified May 9, 2013
This snippet is Public
BrowserIE
IE Version8.0
LanguageC++
LicenseMIT_X11
OSWindows
Windows VersionWindows7

Bilbo Draft #2

Main code - barebones
Copy Embed Code
<iframe id="embedFrame" style="width:600px; height:300px;"
src="https://www.snip2code.com/Embed/1040/Bilbo-Draft--2?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 : 09/05/2013 #include <iostream> #include <stdio.h> #include <string> #include <fstream> #include <windows.h> #include <input2010.h> //#define TXTFILE = "H:/timesheet.txt" const std::string TXTFILE = "H:/timesheet.txt"; using namespace std; //------------Struct------------- struct timesheet { char name[30]; int normHours, overHours, rateOfPay, depId; string wkEndDate; double empNo, pay, grossPay, natIns, tax, netPay; 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 display(timesheet timesheet[], int rows); void report(timesheet ts[], int rows); void search(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' || 'Q') { menu(choice); pick(choice,ts,rows); } quit(); } //----------------Menu & Choice------------------------------ void menu(char &choice) { clrscr(); std::cout << "\n\t\t\t------------Main Menu-----------"; std::cout << "\n\t\t\t| |"; std::cout << "\n\t\t\t| (I)Input data |"; // std::cout << "\n\t\t\t| (D)isplay data |"; std::cout << "\n\t\t\t| (R)eport data |"; std::cout << "\n\t\t\t| (S)earch data |"; std::cout << "\n\t\t\t| (Q)uit |"; std::cout << "\n\t\t\t| |"; std::cout << "\n\t\t\t| |"; std::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' : display(ts, rows); break; case 'r' | 'R' : report(ts, rows); break; case 's' | 'S' : search(ts, rows); break; case 'q' | 'Q' : quit(); break; default : "\n\tInvalid Input!"; } } //----------------InputData------------------ void input(timesheet ts[], int &rows) { int error = 0; clrscr(); std::cout << "Adding Employee to timesheet...\n"; std::cout<< "Employee Name : "; cin >> ts[rows].name; // std::cout<<"Invalid data type. Please enter text only, which is a valid Name"<< endl; //std::cout<< "Employee Number : "; //Input(ts[rows].empNo); do{ std::cout<< "Employee Number : "; cin >> ts[rows].empNo; if (cin.fail()) { std::cout << "Invalid data type!"<< endl; error =1; cin.clear(); cin.ignore(8, '\n'); std::cout<< "Employee Number : "; cin >> ts[rows].empNo; break; } } while(error == 1); error = 0; do{ std::cout<< "Department ID : "; cin >> ts[rows].depId; if (cin.fail()) { std::cout << "Invalid data type!"<< endl; error =2; cin.clear(); cin.ignore(8, '\n'); std::cout<< "Department ID : "; cin >> ts[rows].depId; break; } } while(error == 2); error = 0; do{ std::cout<< "Employee Working NORMAL Hours : "; cin >> ts[rows].normHours; //input nhours, false, in nhour, in ohours, false, normal if (ts[rows].normHours >= 37.5) { std::cout<< "Employee Working OVER Hours : " << endl; cin >> ts[rows].overHours; if (cin.fail()) { std::cout << "Invalid data type!"<< endl; error =3; cin.clear(); cin.ignore(8, '\n'); std::cout<< "Over Hours : "; cin >> ts[rows].overHours; break; } } else if (cin.fail()) { std::cout << "Invalid data type!"<< endl; error =3; cin.clear(); cin.ignore(8, '\n'); std::cout<< "Normal Hours : "; cin >> ts[rows].normHours; } } while(error ==3); error = 0; std::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 // std::cout<<"Invalid data type. Please enter numbers only, which are in the correct Working Rate of Pay format" << endl; std::cout<< "Weekend date DD|MM|YYYY : "; cin >> ts[rows].wkEndDate; string date = ts[rows].wkEndDate; if (date.length() != 52) { cout<<"Invalid data type. Please enter numbers only in the correct Date format" << endl; cout<<"Weekend date DD|MM|YYYY : "; cin >> ts[rows].wkEndDate; } ts[rows].deleted=false; double pay = ts[rows].normHours * ts[rows].rateOfPay; /*double payOne = ts[rows].normHours * ts[rows].rateOfPay * 12.75; payOne = ts[rows].tax; double payTwo = ts[rows].normHours * ts[rows].rateOfPay * 6.8; payTwo = ts[rows].natIns; cout << "Pay \t" << pay << "\nTax \t"<< payOne << " " << ts[rows].tax << "\nNI \t" << payTwo <<" "<< ts[rows].natIns << endl; */ //double pay; //ts[rows].wkEndDate * ts[rows].normHours + ts[rows].overHours = pay; //std::cout << "Employee pay: \t" << pay << endl; rows++; display(ts, rows); cout << "Pay: $\t" << pay << endl; std::cout << "Data Written to file" << endl; pressKey(); } void readFile(timesheet timesheets[], int &rows) { ifstream myfile(TXTFILE,ios::binary); if (!myfile.is_open()) std::cout << "Unable to open file: " << TXTFILE << endl; else { while ( !myfile.eof() ) { myfile.read((char *)&timesheets[rows], sizeof(timesheet)); rows++; std::cout << "Data read from File" << endl; } rows--; myfile.close(); } } void writeFile (timesheet timesheets[], int rows) { int r=0; ofstream myfile(TXTFILE,ios::binary); if (myfile.is_open()) { while ( r < rows ) { myfile.write((char *)&timesheets[r], sizeof(timesheet)); r++; std::cout << "Data written to File" << endl; } myfile.close(); std::cout << "Data written to " << TXTFILE << "\n"; } else std::cout << "Unable to open file: " << TXTFILE << endl; } //-----------------Display, Report and Search----------------------- void display(timesheet ts[], int rows) { std::cout << ts[0].name <<" " << ts[0].empNo << " " << ts[0].depId <<" " << ts[0].normHours << " " /*<< ts[0].overHours <<" " */<< ts[0].rateOfPay << " " << ts[0].wkEndDate << endl; pressKey(); } 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; char choice; // CLEAR SCREEN clrscr(); std::cout << "Please press 1 for DEP or\nPlease press 2 for EMPLOYEE" <<endl; Input(choice); if (choice = '1') { std::cout << "Please enter a searchable department ID:" << endl; cin >> dRep; for (int r=0;r<rows;r++) { if ( dRep == ts[r].depId ) { std::cout << ts[r].depId<< endl;; pressKey(); } } pressKey(); } else //(choice = '2') { std::cout << "Please enter the Employee name..." << endl; Input(eRep); std::cout << ts[0].name[eRep] << endl; //Show timesheet calculation totals pressKey(); } /*if(sChoice != "d") { std::cout << "Please enter a searchable name" << endl; Input(name,30); for(int i=0;i<rows;i++) { if ( strnicmp(name, "nme", strlen(name) ) == 0 ) { if ( ts[i].deleted == false ) { std::cout << ts[i].name << endl; 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; std::cout << "Please enter date 1" << endl; Input(date1); std::cout << "Please enter date 2" << endl; Input(date2); /* Get tax for date1 Get tax for date2 Calculate difference Print result */ } //-----------------Close the application----------------- void quit() { std::cout << "Program closing \t"; system("Pause"); exit(EXIT_FAILURE); }
If you want to be updated about similar snippets, Sign in and follow our Channels

blog comments powered by Disqus