Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include<fstream>
- #include<sstream>
- using namespace std;
- /*
- R.M. 2016 HC
- */
- struct payroll{
- string first_name;
- string last_name;
- float rate;
- float hours;
- float ot_rate;
- float ot_hours;
- float tax_rate;
- float gross_pay;
- float taxes;
- float net_pay;
- } data[150];
- int greet();
- int menu(int num);
- void new_file();
- void open_file();
- void rename_file();
- void delete_file();
- string space_this(string text, int space, int align);
- string space_this2(string text, int space, int align);
- int main(){
- greet();
- // system("pause");
- return 0;
- }
- int greet(){
- printf("Simple Payroll Program\t\tabc123\n\n");
- string username, password;
- cout<<"Username: ";cin>>username;
- cout<<"Password: ";cin>>password;
- cout<<endl;
- if(username=="abc" && password=="123"){menu(3);}
- }
- int menu(int num){
- char choice;
- if(num==1){cout<<"[n] New File\n[o] Open File\n[r] Rename File\n[d] Delete File\n[z] Exit\n\n";}
- else if(num==3){cout<<" [n] New File\n [o] Open File\n [r] Rename File\n [d] Delete File\n [z] Exit\n\n";}
- else{printf("[n] New File [o] Open File [r] Rename File [d] Delete File [z] Exit\n");}
- cin>>choice;
- switch(choice){
- case 'n':
- system("cls");
- new_file();
- break;
- case 'o':
- system("cls");
- open_file();
- break;
- case 'r':
- system("cls");
- rename_file();
- break;
- case 'd':
- system("cls");
- delete_file();
- break;
- case 'z':
- break;
- return 0;
- default:
- system("cls");
- menu(1);
- break;
- }
- }
- void new_file(){
- string filename;
- int entries=0;
- cout<<"Enter Filename: ";cin>>filename;cout<<"\n";
- cout<<"Enter Number Of Entries: ";cin>>entries;
- system("cls");
- float gross_total=0;
- float tax_total=0;
- float net_total=0;
- cout<<filename<<" "<<entries<<" entries\n\n";
- for(int i=0;i<entries;i++){
- cin.ignore();
- cout<<"#"<<i+1<<endl;
- cout<<"Enter First Name: ";getline(cin,data[i].first_name);
- cout<<"Enter Last Name: ";getline(cin,data[i].last_name);
- cout<<"Enter Rate: ";cin>>data[i].rate;
- cout<<"Enter Hours: ";cin>>data[i].hours;
- cout<<"Enter Overtime Rate: ";cin>>data[i].ot_rate;
- cout<<"Enter Overtime Hours: ";cin>>data[i].ot_hours;
- cout<<"Enter Tax Rate: ";cin>>data[i].tax_rate;
- data[i].gross_pay = data[i].rate*data[i].hours + data[i].ot_rate*data[i].ot_hours;
- data[i].taxes = (data[i].tax_rate/100)*data[i].gross_pay;
- data[i].net_pay = data[i].gross_pay-data[i].taxes;
- gross_total+=data[i].gross_pay;
- tax_total+=data[i].taxes;
- net_total+=data[i].net_pay;
- cout<<endl;
- }
- system("cls");
- cout<<filename<<"\n\n";
- ofstream payroll_file;
- payroll_file.open(filename.c_str());
- printf("%-20s|%-7s|%-4s|%-7s|%-4s|%-10s|%-9s|%-10s|\n","Employee","Rate","Hrs","OT","Hrs","Gross","Taxes","Net Pay");
- printf("%-20s|%-7s|%-4s|%-7s|%-4s|%-10s|%-9s|%-10s|\n","","","","","","","","");
- payroll_file<<space_this("Employee",20,1)<<space_this("Rate",7,1)<<space_this("Hrs",4,1)<<space_this("OT",7,1);
- payroll_file<<space_this("Hrs",4,1)<<space_this("Gross",10,1)<<space_this("Taxes",9,1)<<space_this("Net Pay",10,1)<<"\n";
- //convert int to string
- stringstream temp10, temp11, temp12;
- string gross_total_str, tax_total_str, net_total_str;
- temp10<<gross_total; temp10>>gross_total_str;
- temp11<<tax_total; temp11>>tax_total_str;
- temp12<<net_total; temp12>>net_total_str;
- for(int i=0;i<entries;i++){
- stringstream temp, temp2, temp3, temp4, temp5, temp6, temp7;
- string rate_str, rate_hrs_str, ot_rate_str, ot_hrs_str, gross_str, taxes_str, net_str;
- temp<<data[i].rate; temp>>rate_str; temp2<<data[i].hours; temp2>>rate_hrs_str;
- temp3<<data[i].ot_rate; temp3>>ot_rate_str; temp4<<data[i].ot_hours; temp4>>ot_hrs_str;
- temp5<<data[i].gross_pay; temp5>>gross_str; temp6<<data[i].taxes; temp6>>taxes_str;
- temp7<<data[i].net_pay; temp7>>net_str;
- cout<<space_this(data[i].first_name+" "+data[i].last_name,20,1);
- cout<<space_this(rate_str,7,2);
- cout<<space_this(rate_hrs_str,4,2);
- cout<<space_this(ot_rate_str,7,2);
- cout<<space_this(ot_hrs_str,4,2);
- cout<<space_this(gross_str,10,2);
- cout<<space_this(taxes_str,9,2);
- cout<<space_this(net_str,10,2);
- cout<<endl;
- payroll_file<<space_this(data[i].first_name+" "+data[i].last_name,20,1);
- payroll_file<<space_this(rate_str,7,2);
- payroll_file<<space_this(rate_hrs_str,4,2);
- payroll_file<<space_this(ot_rate_str,7,2);
- payroll_file<<space_this(ot_hrs_str,4,2);
- payroll_file<<space_this(gross_str,10,2);
- payroll_file<<space_this(taxes_str,9,2);
- payroll_file<<space_this(net_str,10,2);
- payroll_file<<"\n";
- }
- printf("%-20s|%-7s|%-4s|%-7s|%-4s|%-10s|%-9s|%-10s|\n\n","","","","","","","","");
- printf("%-20s %-7s %-4s %12s|%10.2f|%9.2f|%10.2f|\n","","","","Total: ",gross_total,tax_total,net_total);
- cout<<endl;
- payroll_file<<space_this2("",20,1)<<space_this2("",7,1)<<space_this2("",4,1)<<space_this("Total: ",12,2);
- payroll_file<<space_this(gross_total_str,10,2)<<space_this(tax_total_str,9,2)<<space_this(net_total_str,10,2)<<"\n";
- payroll_file.close();
- cout<<endl;
- menu(2);
- }
- void open_file(){
- string contents[125];
- int lines=0;
- string filename;
- cout<<"Enter Filename: ";cin>>filename;
- cout<<endl;
- if(!rename(filename.c_str(),filename.c_str())){
- string content;
- ifstream openfile (filename.c_str());
- if(openfile.is_open()){
- while(getline(openfile,content)){
- cout<<content<<endl;
- ++lines;
- }
- for(int i=0;i<lines;i++){
- getline(openfile,contents[i]);
- }
- for(int i=0;i<10;i++){cout<<contents[i];}
- }
- openfile.close();
- } else {cout<<"File Not Found\n\n";}
- cout<<endl;
- menu(2);
- }
- void rename_file(){
- string filename, new_filename;
- cout<<"Enter Filename: ";cin>>filename;
- cout<<"Enter New Filename: ";cin>>new_filename;
- if(!rename(filename.c_str(),new_filename.c_str())){
- cout<<"File Renamed\n\n";
- } else {cout<<"File Not Found\n\n";}
- menu(2);
- }
- void delete_file(){
- string filename;
- cout<<"Enter Filename: ";cin>>filename;
- if(!rename(filename.c_str(),filename.c_str())){
- remove(filename.c_str());
- cout<<"File Deleted\n\n";
- } else {cout<<"File Not Found\n\n";}
- menu(2);
- }
- string space_this(string text, int space, int align){
- string spaces="";
- for(int i=0;i<(space-text.length());i++){spaces+=" ";}
- if(align==1){return text+spaces+"|";} else {return spaces+text+"|";}
- }
- string space_this2(string text, int space, int align){
- string spaces="";
- for(int i=0;i<(space-text.length());i++){spaces+=" ";}
- if(align==1){return text+spaces+" ";} else {return spaces+text+" ";}
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement