C++ Project on Payroll Management System

January 4, 2017 | Author: raj18021997 | Category: N/A
Share Embed Donate


Short Description

project on c++ cbse class 12...

Description

//Payroll Management System #include #include #include #include //graphics functions #include #include #include //for file handling #include struct date_rec //record to get data { int dd; int mm; int yyyy; }current_date; //this class defines data related to monthly pay file class payfile //base class { private: int emp_num; char emp_name[25]; char emp_designation[20]; int days_worked,dw; float basic_pay; float DA; float HRA; float CCA; float con_veyance; float gross_pay; float PF; float income_tax; float other_deductions; float net_pay; public: payfile() //no arguments constructor { days_worked=0; basic_pay=DA=HRA=CCA=con_veyance=gross_pay=0.0; PF=income_tax=other_deductions=net_pay=0.0; } void get_pay(); //this function reads the private members of payfile void update_pay_file();/*this function calls get_pay() and generates monthly pay file on disk*/ void reports(); /*this function reads the monthly pay file from disk and generates salary statements*/ /*when a new employee is registered,this function writes its record using payfile()constructor on disk to make a entry in monthly payfile*/ void add_pay_object(int code,char name[25],char desig[10],float basic); /*when an employee leaves the company,this function deletes the entry from monthly pay file*/ void del_pay_object(int code); /*this function modifies designation of an employee in monthly pay file*/ void modify_pay_object(int code,char desig[20]); /*this function modifies the basic in pay file*/ void modify_basic(int code,float basic); }pay; void payfile::modify_basic(int code,float basic) {

fstream file; file.open("payfile.dat",ios::in|ios::out);//opening file file.seekg(0,ios::beg);//set pointer to the begining file.read((char*)&pay,sizeof(pay));//read first record int n=file.tellg(); while(!file.eof()) { if(code==pay.emp_num) { pay.basic_pay=basic; pay.gross_pay=pay.basic_pay+pay.DA+pay.HRA+pay.CCA+pay.con_veyance; pay.net_pay=pay.gross_pay-(pay.PF+pay.income_tax+pay.other_deductions); file.seekg(n-sizeof(pay)); file.write((char*)&pay,sizeof(pay)); file.flush(); file.seekg(0,ios::end); } file.read((char*)&pay,sizeof(pay)); n=file.tellg(); } file.close(); } void payfile::add_pay_object(int code,char name[25],char desig[20], float basic) { fstream outfile; pay.emp_num=code; pay.basic_pay=basic; strcpy(pay.emp_name,name); strcpy(pay.emp_designation,desig); outfile.open("payfile.dat",ios::app);//open fees file in append mode outfile.write((char*)&pay,sizeof(pay));//make entry in fees file outfile.flush(); outfile.close();//close fees file } void payfile::del_pay_object(int code) { fstream outfile,infile; outfile.open("tempfile.dat",ios::app); //open temporary file infile.open("payfile.dat",ios::in);//open pay file for reading infile.seekg(0,ios::beg);//set file pointer to the begining of the file infile.read((char*)&pay,sizeof(pay));//read the first record while(!infile.eof()) { if(pay.emp_num!=code)//if this record is not to be deleted //write in the temporary outfile.write((char*)&pay,sizeof(pay)); infile.read((char*)&pay,sizeof(pay));//read next record } infile.close();//close pay file outfile.close();//close temporary file remove("payfile.dat");//delete old monthly pay file rename("tempfile.dat","payfile.dat");//temporary file becomes new pay file } void payfile::modify_pay_object(int code,char desig[20]) { fstream file; file.open("payfile.dat",ios::in|ios::out);//open file for reading/writing file.seekg(0,ios::beg);//set file pointer to the begining of the file file.read((char*)&pay,sizeof(pay));//read first record int n=file.tellg();//tell where we are

while(!file.eof()) { if(code==pay.emp_num) //record found { strcpy(pay.emp_designation,desig); file.seekg(n-sizeof(pay)); //set fili pointer to the record to be changed file.write((char*)&pay,sizeof(pay)); //update record file.flush(); file.seekg(0,ios::end);/*if record found set file pointer to end of file to stop further searching*/ } file.read((char*)&pay,sizeof(pay)); //if record not found read next record n=file.tellg();//tell where we are } file.close(); } void payfile::get_pay()//this function reads the private members of payfile { char ch,month[9]; int mon; cout< >mon; switch(mon) { //get month name case 1 : strcpy(month,"JANUARY"); break; case 2 : strcpy(month,"FEBRUARY"); break; case 3 : strcpy(month,"MARCH"); break; case 4 : strcpy(month,"APRIL"); break; case 5 : strcpy(month,"MAY"); break; case 6 : strcpy(month,"JUNE"); break; case 7 : strcpy(month,"JULY"); break; case 8 : strcpy(month,"AUGUST"); break; case 9 : strcpy(month,"SEPTEMBER"); break; case 10 :strcpy(month,"OCTOBER"); break; case 11 :strcpy(month,"NOVEMBER"); break; case 12 :strcpy(month,"DECEMBER"); break; } int n; if(mon==1||mon==3||mon==5||mon==7||mon==8||mon==10||mon==12) { n=31; } else if(mon==2) { n=28; } else {

n=30; } cout< >days_worked; if(days_worked<23) { dw=23-days_worked; days_worked=n-dw; } else { days_worked=n; dw=0; } cout< >date_birth.dd>>ch>>date_birth.mm>>ch>>date_birth.yyyy; cout< >basic_salary; } //this function displays data void employee::show_data() { clrscr(); cout<
View more...

Comments

Copyright ©2017 KUPDF Inc.
SUPPORT KUPDF