Advertisement
mikhun

payroll system

May 22nd, 2019
173
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.63 KB | None | 0 0
  1. #include<iostream.h>
  2. #include<conio.h>
  3. #include<process.h>
  4. #include<string.h>
  5. #include<fstream.h>
  6. #include<stdlib.h>
  7. #include<iomanip.h>
  8. #include<stdio.h>
  9. #include<ctype.h>
  10. class employee
  11. {
  12. char name[30],designation[30],address[30],email[30],sex;
  13. char mobno[20];
  14. int empid;
  15. char egrade,ehouse,econv;
  16. float eloan,ebasic;
  17. public:
  18. void mainmenu();
  19. void biomenu();
  20. void bio();
  21. void display();
  22. void modify();
  23. void modify1();
  24. void salary();
  25. void dispsal();
  26. void slip();
  27. void display1();
  28. int retempid()
  29. {
  30. return empid;
  31. }
  32. int found_code(int);
  33. void id(int);
  34. };
  35. void employee::id(int eid)
  36. { employee e;
  37. fstream file;
  38. file.open("employ.dat",ios::in|ios::binary);
  39. file.seekg(0,ios::beg);
  40. while(file.read((char*)&e,sizeof(e)))
  41. { if(eid==e.retempid())
  42. { cout<<"\nEmployee Id Already Exists!!!!";
  43. getch();
  44. cout<<"\nEnter New Id:";
  45. cin>>empid;
  46. }
  47. }
  48. file.close();
  49. }
  50. void intro()
  51. {
  52. cout<<"\n\n\n\n\n\n\n\n\n\b\t\t*******************************************\n";
  53. cout<<"\t\t\tPayroll Mangement System\n";
  54. cout<<"\t\t*******************************************";
  55. getch();
  56. }
  57. int login()
  58. {
  59. char name[20]="michael",password[20]="mike12";
  60. char username[20],pass[20]={0},prev[20]={0};
  61. cout<<"\n\t\t\tLOGIN";
  62. cout<<"\n\t\t**********************";
  63. cout<<"\n\t\tEnter Username:";
  64. gets(username);
  65. if(strcmp(name,username)==0)
  66. {
  67. cout<<"\n\t\tEnter Password:";
  68. for(int i=0;i<20;i++)
  69. { pass[i]=getch();
  70. putch('*');
  71. while(pass[i]!=13)
  72. { prev[i]=pass[i];
  73. break;
  74. }
  75. if(pass[i]==13)
  76. break;
  77. }
  78. //gets(pass);
  79. if(strcmp(password,prev)==0)
  80. { cout<<"\n\t\tLogin successfully";
  81. cout<<"\n\t\t\t\tPress ENTER To Continue";
  82. getch();
  83. }
  84. else
  85. { cout<<"\nWrong password!!";
  86. getch();
  87. return -1; }
  88. }
  89. else
  90. {cout<<"\nWrong username!!";
  91. getch();
  92. return -1; }
  93. return 0;
  94. }
  95. int employee::found_code(int ecode)
  96. { fstream file; employee e;
  97. file.open("employ.dat",ios::in|ios::binary) ;
  98. file.seekg(0,ios::beg);
  99. int found=0;
  100. while(file.read((char*)&e,sizeof(e)))
  101. { if(ecode==e.retempid())
  102. {
  103. found =1;
  104. break;
  105. }
  106. } file.close();
  107. return found;
  108. }
  109. void employee::slip(void)
  110. { employee e;
  111. clrscr();
  112. int t2,ecode,valid,days,hours;
  113. cout<<"<0>=EXIT";
  114. gotoxy(5,5);
  115. cout<<"\nEnter The Code Of The Employee:";
  116. cin>>ecode;
  117. if(ecode==0)
  118. return;
  119. clrscr();
  120. if(!found_code(ecode))
  121. {
  122. gotoxy(5,5);
  123. cout<<"\nRecord Not Found!!";
  124. getch();
  125. return;
  126. }
  127. fstream file;
  128. file.open("employ.dat",ios::in);
  129. file.seekg(0,ios::beg);
  130. while(file.read((char *)&e,sizeof(e)))
  131. {
  132. if(empid==e.retempid())
  133. // found=0;
  134. break;
  135. // else
  136. //found=0;
  137.  
  138. }
  139. file.close();
  140. /* if(found==1)
  141. {
  142. cout<<"\nRECORD NOT FOUND!!";
  143. // getch();
  144.  
  145. } */
  146. clrscr();
  147. cout<<"\nEnter the no. of days worked in a month:";
  148. cin>>days;
  149. cout<<"\nEnter the hours worked over time:";
  150. cin>>hours;
  151.  
  152. clrscr();
  153. gotoxy(31,2);
  154. cout<<" CA TECHNOLOGY";
  155. gotoxy(34,4);
  156. cout<<"SALARY SLIP";
  157. gotoxy(60,4);
  158. cout<<"YEAR:2010";
  159. gotoxy(34,5);
  160. gotoxy(6,7);
  161. cout<<"EMPLOYEE NAME:"<<name;
  162. gotoxy(6,8);
  163. cout<<"DEGIGNATION:"<<designation;
  164. cout<<"GRADE:"<<egrade;
  165. gotoxy(10, 10);
  166. cout << "Basic Salary : Birr.";
  167. gotoxy(10, 12);
  168. cout << "ALLOWANCE";
  169. if (egrade != 'E')
  170. {
  171. gotoxy(12, 13);
  172. cout << "HRA : Birr.";
  173. gotoxy(12, 14);
  174. cout << "CA : Birr.";
  175. gotoxy(12, 15);
  176. cout << "DA : Birr.";
  177. }
  178. else
  179. {
  180. gotoxy(12, 13);
  181. cout << "OT : Birr.";
  182. }
  183. gotoxy(10, 17);
  184. cout << "DEDUCTIONS";
  185. gotoxy(12, 18);
  186. cout << "LD : Birr.";
  187. if (egrade != 'E')
  188. {
  189. gotoxy(12, 19);
  190. cout << "PF : Birr.";
  191. }
  192. gotoxy(10, 21);
  193. cout << "NET SALARY : Birr.";
  194. float HRA = 0.0, CA = 0.0, DA = 0.0, PF = 0.0, LD = 0.0, OT = 0.0, allowance, deduction, netsalary;
  195. if (egrade != 'E')
  196. {
  197. if (ehouse == 'Y')
  198. HRA = (5 * ebasic) / 100;
  199. if (econv == 'Y')
  200. CA = (2 * ebasic) / 100;
  201. DA = (5 * ebasic) / 100;
  202. PF = (2 * ebasic) / 100;
  203. LD = (10 * eloan) / 100;
  204. allowance = HRA + CA + DA;
  205. deduction = PF + LD;
  206. }
  207. else
  208. {
  209. ebasic = days * 30;
  210. LD = (10 * eloan) / 100;
  211. OT = hours * 10;
  212. allowance = OT;
  213. deduction = LD;
  214. }
  215. netsalary = (ebasic + allowance + OT) - deduction;
  216. gotoxy(36, 10);
  217. cout << ebasic;
  218. if (egrade != 'E')
  219. {
  220. gotoxy(22, 13);
  221. cout << HRA;
  222. gotoxy(22, 14);
  223. cout << CA;
  224. gotoxy(22, 15);
  225. cout << DA;
  226. gotoxy(22, 19);
  227. cout << PF;
  228. }
  229. else
  230. {
  231. gotoxy(22, 13);
  232. cout << OT;
  233. }
  234. gotoxy(22, 18);
  235. cout << LD;
  236. gotoxy(33, 15);
  237. cout << "Birr." << allowance;
  238. gotoxy(33, 19);
  239. cout << "Birr." << deduction;
  240. gotoxy(36, 21);
  241. cout << netsalary;
  242. gotoxy(2, 1);
  243. getch();
  244. clrscr();
  245. }
  246. void employee::salary()
  247. {
  248. cout<<"\nEnter the grade of the employee(A,B,C,D,E):";
  249. egrade=getche();
  250. egrade=toupper(egrade);
  251. if(egrade!='E')
  252. { cout<<"\nENTER IF HOUSE ALLOWANCE IS ALLOTED TO EMPLOYEE OR NOT:";
  253. ehouse=getche();
  254. ehouse=toupper(ehouse);
  255. cout<<"\nENTER IF CONVENCE ALLOWANCE IS ALLOTED TO EMPLOYEE OR NOT:" ;
  256. econv=getche();
  257. econv=toupper(econv);
  258. cout<<"\nENTER LOAN AMOUNT IF ISSUED:";
  259. cin>>eloan;
  260. cout<<"\nENTER THE BASIC SALARY OF THE EMPLOYEE:";
  261. cin>>ebasic;
  262. }
  263. }
  264. void employee::dispsal()
  265. {
  266. cout<<"\n\tLOAN AMOUNT"<<"\t\tBASIC SALARY";
  267. cout<<"\n\t"<<eloan<<"\t\t"<<ebasic;
  268. }
  269. void employee::modify()
  270. { cout<<"\nEmployee Id Number:"<<empid;
  271. cout<<"\n___________________________________";
  272. cout<<"\nName="<<name;
  273. cout<<"\n_________________________";
  274. cout<<"\nDesignation="<<designation;
  275. cout<<"\n_________________________";
  276. cout<<"\nEmail="<<email;
  277. cout<<"\n_________________________";
  278. cout<<"\nAddress="<<address;
  279. cout<<"\n_________________________";
  280. cout<<"\nSex="<<sex;
  281. cout<<"\n_________________________";
  282. cout<<"\nPhoneno="<<mobno;
  283. cout<<"\n_________________________";
  284. cout<<"\nEnter new details:";
  285. char n[30],ad[30],desig[30],em[30];
  286. int eid,sal;
  287. char p[20],se;
  288. cout<<"\nEnter new employee id no.('0' for old):-";
  289. cin>>eid;
  290. cout<<"\nEnter new name(Enter '.'to retain the old name):-";
  291. gets(n);
  292. cout<<"\nEnter new designation(Enter '.'to retain old ):-";
  293. gets(desig);
  294. cout<<"\nEnter new address(Enter '.'to retain the old address):-";
  295. gets(ad);
  296. cout<<"\nEnter new email(Enter '.'to retain old:-";
  297. gets(em);
  298. cout<<"\nEnter new sex(M/F)(Enter '.'to retain the old sex):-";
  299. cin>>se;
  300. cout<<"\nEnter new phoneno(Enter '.'to retain the old phoneno):-";
  301. gets(p);
  302. cout<<"\nEnter New Salary:('0' for old):-";
  303. cin>>sal;
  304. if(eid!=0)
  305. empid=eid;
  306. if(strcmp(n,".")!=0)
  307. strcpy(name,n);
  308. if(strcmp(desig,".")!=0)
  309. strcpy(designation,desig);
  310. if(strcmp(ad,".")!=0)
  311. strcpy(address,ad);
  312. if(strcmp(em,".")!=0)
  313. strcpy(email,em);
  314. if(se!=0)
  315. sex=se;
  316. if(strcmp(p,".")!=0)
  317. strcpy(mobno,p);
  318. if(sal!=0)
  319. ebasic=sal;
  320. }
  321. void employee::modify1()
  322. { int cuid;
  323. employee C3;
  324. char found='f';
  325. long pos;
  326. fstream ifile;
  327. ifile.open("employ.dat",ios::in|ios::out|ios::binary);
  328. if(!ifile)
  329. { cout<<"Unable to open file...";
  330. getch();
  331. exit(0);
  332. }
  333. cout<<"Enter the employee id to be modified:";
  334. cin>>cuid;
  335. while(ifile)
  336. { pos=ifile.tellg();
  337. ifile.read((char*)&C3,sizeof(C3));
  338. if(cuid==C3.retempid())
  339. { C3.modify();
  340. ifile.seekg(pos);
  341. ifile.write((char*)&C3,sizeof(C3));
  342. found='t';
  343. break;
  344. }
  345. }
  346. if(found=='f')
  347. cout<<"Record not found...!";
  348. ifile.close();
  349. }
  350. void del()
  351. { employee e;
  352. int cid,flag=0;
  353. ifstream ifile;
  354. ifile.open("employ.dat",ios::binary);
  355. ofstream ofile;
  356. ofile.open("temp.dat",ios::binary);
  357. if(!ifile)
  358. { cout<<"Unable to open file....press any key to continue !";
  359. getch();
  360. exit(0);
  361. }
  362. cout<<"Enter The Employee id to be deleted:";
  363. cin>>cid;
  364. while( ifile.read((char*)&e,sizeof(e)))
  365. {
  366. if(cid==e.retempid())
  367. { flag=1;
  368. cout<<"Record deleted.....";
  369. }
  370. else
  371. ofile.write((char*)&e,sizeof(e));
  372. }
  373. if(flag==0)
  374. cout<<"Such a record does not exist..!";
  375. ifile.close();
  376. ofile.close();
  377. remove("employ.dat");
  378. rename("temp.dat","employ.dat");
  379. }
  380. void employee::display()
  381. { cout<<"\n\tEMPLOYEE DETAILS";
  382. cout<<"\n\t***************************";
  383. cout<<"\nEMPLOYEE ID:"<<empid;
  384. cout<<"\nEMPLOYEE NAME:"<<name;
  385. cout<<"\nEMPLOYEE DESIGNATION:"<<designation;
  386. cout<<"\nEMPLOYEE ADDRESS:"<<address;
  387. cout<<"\nEMPLOYEE EMAIL:"<<email;
  388. cout<<"\nEMPLOYEE SEX:"<<sex;
  389. cout<<"\nEMPLOYEE MOBILE NO:"<<mobno;
  390. }
  391. void employee::display1()
  392. {
  393. cout<<"\n\t\t***************************************************";
  394. cout<<"\nEMPID"<<"\tNAME"<<"\tDESIGNATION"<<"\tADDRESS"<<"\tEMAIL"<<"\tSEX"<<"\tMOBNO"<<"\tSALARY";
  395. cout<<"\n"<<empid<<"\t"<<name<<"\t"<<designation<<"\t"<<address<<"\t"<<email<<"\t"<<sex<<"\t"<<mobno<<"\t"<<ebasic;
  396. }
  397. void employee::bio()
  398. { employee e;
  399. cout<<"\n\t\tADDING OF AN EMPLOYEE";
  400. cout<<"\n\t\t*****************************";
  401. cout<<"\nEnter Employee Id No:";
  402. cin>>empid;
  403. id(empid);
  404. cout<<"\nEnter Name:";
  405. gets(name);
  406. cout<<"Enter Designation:";
  407. gets(designation);
  408. cout<<"Enter Address:";
  409. gets(address);
  410. cout<<"Enter Email:";
  411. gets(email);
  412. cout<<"Enter Gender(m/f):";
  413. cin>>sex;
  414. cout<<"Enter Mobile Number:";
  415. gets(mobno);
  416. }
  417. void employee::mainmenu()
  418. {
  419. employee e;
  420. int choice,id,flag=0;
  421. clrscr();
  422. do{
  423. cout<<"\n\t\t\tMAIN MENU";
  424. cout<<"\n\t\t***********************";
  425. cout<<"\n1.Employee Biodata";
  426. cout<<"\n2.Display";
  427. cout<<"\n3.SALARY SLIP";
  428. cout<<"\n4.Display Individual";
  429. cout<<"\n5.Exit";
  430. cout<<"\nEnter Your Choice:";
  431. cin>>choice;
  432. switch(choice)
  433. {
  434. case 1: e.biomenu(); break;
  435. case 2: clrscr();
  436. cout<<"\n\n\t\t\tALL EMPLOYEE'S DETAILS";
  437. ifstream ifile;
  438. ifile.open("employ.dat",ios::binary);
  439. while(ifile.read((char*)&e,sizeof(e)))
  440. {
  441. e.display1();
  442. //e.dispsal();
  443. }
  444. ifile.close();
  445. break;
  446. case 3: slip();
  447. case 4:
  448. ifstream file1;
  449. file1.open("employ.dat",ios::binary|ios::in);
  450. cout<<"\nenter employee id to be searched:";
  451. cin>>id;
  452. while(file1.read((char*)&e,sizeof(e)))
  453. {
  454. if(id==e.retempid())
  455. { cout<<"RECORD FOUND";
  456. flag=1;
  457. e.display();
  458. e.dispsal();
  459. break;
  460. }
  461. }
  462. if(flag==0)
  463. cout<<"\nThis employee does not exists!!";
  464. file1.close(); break;
  465. case 5:exit(0) ; break;
  466. default: cout<<"\nWrong Choice!!";
  467.  
  468. }
  469. }while(choice!=5);
  470. getch();
  471. }
  472. void employee::biomenu()
  473. {
  474. int choice;
  475. employee e;
  476. do
  477. {
  478. cout<<"\n\t\tBIODATA MENU";
  479. cout<<"\n\t\t************************";
  480. cout<<"\n1.ADD";
  481. cout<<"\n2.BACK";
  482. cout<<"\n3.DELETE";
  483. cout<<"\n4.MODIFY";
  484. cout<<"\nEnter Your Choice:";
  485. cin>>choice;
  486. switch(choice)
  487. {
  488. case 1: clrscr();
  489. ofstream file;
  490.  
  491. file.open("employ.dat",ios::out|ios::binary|ios::app);
  492. if(!file)
  493. {
  494. cout<<"unable to open the file";
  495. exit(0);
  496. }
  497. else
  498. {
  499. e.bio();
  500. e.salary();
  501. file.write((char*)&e,sizeof(e));
  502. }
  503. file.close(); break;
  504. case 2: e.mainmenu();
  505. break;
  506. case 3: del();
  507. break;
  508. case 4: modify1();
  509. break;
  510. default: cout<<"Wrong Choice";
  511. }
  512. }while(choice!=2);
  513. }
  514. void main()
  515. { int a;
  516. clrscr();
  517. intro();
  518. clrscr();
  519. a=login();
  520. if(a!=-1)
  521. {
  522. employee e;
  523.  
  524. e.mainmenu(); }
  525.  
  526. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement