The design and realization of C + + staff salary management

Source: Internet
Author: User
Tags strcmp

Design and realization of employee's salary management

Design and realization of employee's salary management

Functional Design Requirements

1. Enter records: Each employee's name, ID number and basic salary, dominate, post allowance, medical insurance, Provident Fund data as a record. The software can create a new data file or add records to an established data file.

2. Display records: According to the user-provided records or according to the name of the employee shows the wages and average salary of one or several employees.

3. Modify the Record: You can modify the data of any record of the data file and display the contents of the record before and after the modification.

4. Find records: You can look up data from any record in a data file and display the contents of the record before and after it is found.

5. Delete a record: You can delete any record in the data file.

6. Statistics: (A) The calculation of the average wage and the total wages of wages, (B) The statistics meet the specified conditions (such as the first three of staff wages and above 3000 yuan, 3000~2000 yuan, 2000~1000 yuan) within the number of wage workers and the percentage of total staff. (C) Print all Employee payroll information forms and average wages (including the total average salary) in the form of a character table.

7. Save the data file feature.

For example: Employee Payroll Information Form
ID number name basic salary dominate subsidy Medicare-provident Fund-Total wage
01 Peering 1286 794 198 109 135 2034
02 Li Ming 1185 628 135 94 114 1740
03 Wang Xiaomin 895 438 98 64 73 1294
04 Effect Chapter 1350 868 210 116 150 2162
05 Pengshan 745 398 84 61 68 1098
? ? ? ? ? ? ? ?
Average wage 1092.2 625.2 145 88.8 108


Code Analysis:
#define _crt_secure_no_warnings1#include<iostream> #include <fstream> #include <stdlib.h> #include <string.h> #include <Windows.h> #define Max 100000000;using namespace Std;class staff{public:staff () {id[5] = ' 0 '; NAME[10] = ' 0 '; mon1 = Mon2 = Mon3 = Mon4 = Mon5 = 0.0;} void Setstaff (char *id,char *name,double money1,double money2,double money3,double money4,double money5) {strcpy (Id,ID)  ;  strcpy (Name,name);  Mon1 = Money1;  Mon2 = Money2;  Mon3 = Money3;  Mon4 = Money4; Mon5 = Money5;} void print ();//Display employee Information double Summoney ();//Ask everyone for the total wage double avgmoney ();//Ask everyone for the average wage char id[5],name[10];d ouble mon1,mon2, Mon3,mon4,mon5; };//The total wage for each person double Staff::summoney () {double sum;sum= mon1 + mon2 + mon3 + mon4 + mon5;return sum;} Ask everyone for the average wage double Staff::avgmoney () {Double avg;avg= (Staff::summoney ())/5;return avg;} VOID staff::p rint () {cout<<id<< "" <<name<< "" <<mon1<< "" <<mon2     << "<<mon3<<""<<mon4<<" "<<mon5<<" "<<staff::summoney () <<" "<<staff::avgmoney () <<endl;} Add Employee information int input (Staff sta[]) {cout<< "Employee information input" <<endl;cout<< "Please enter the number of employees you want to enter:" <<endl int num = 0;cin>>num;cout<< "ID number name basic salary dominate subsidy medical insurance provident Fund" <<endl;for (int i = 0;i < num; i++) {Flag1:c       Har id[10]={0},name[10]={0}; Double mon1,mon2,mon3,mon4,mon5; cin>>id>>name>>mon1>>mon2>>mon3>>mon4>>mon5;for (Int J =0;j < I; j + +) {   if (strcmp (id,sta[j].id) = = 0) {cout<< "the worker's employee number already exists please re-enter" <<endl;   Goto Flag1; }} sta[i].setstaff (ID,NAME,MON1,MON2,MON3,MON4,MON5);} return num;}    Count is the current number of employees int Insert (staff sta[],int count) {int n=1; while (n==1) {cout<< "Please enter the new employee information to be added:" <<endl;    cout<< "ID number name basic salary dominate subsidy medical insurance provident Fund" <<endl;flag2:char Id[10]={0},name[10]={0}; Double mon1,mon2,mon3,mon4,mon5; Cin>>id>>name>>mon1>>mon2>>mon3>>mon4>>mon5;   for (Int J =0;j < count; J + +) {if (strcmp (id,sta[j].id) = = 0) {cout<< "the worker's employee number already exists please re-enter" <<endl;   Goto Flag2;    }}sta[count].setstaff (ID,NAME,MON1,MON2,MON3,MON4,MON5); cout<< "added successfully!    "; count++;    cout<< "To continue adding, press 1/exit please press 0:" <<endl; Cin>>n;} return count;} Find employee information count is the number of employees void Select (Staff sta[],int count) {cout<< "Please enter the employee ID to be queried:"; Char Id[10]={0};cin>>id;int     i = 0;for (i = 0;i < count; i++) {if (strcmp (id,sta[i].id) ==0) {cout<< "The Employee information is:" <<endl;cout<< "ID number Name basic salary dominate subsidy medical Insurance Provident Fund total wage average salary "<<endl;sta[i].print (); Break;}} if (I >= count) cout<< "There is no such employee information in the system" &LT;&LT;ENDL;} Deposit in file void Infile (Staff sta[],int count) {fstream outfile;outfile.open ("Staff.dat", ios::out); if (!outfile) {cout << "folder cannot be opened." <<endl;abort ();} for (int i=0; i < count; i++) {outfile<<sta[i].id<< "" <<sta[i].name<< "<<sta[i].mon1<<" "<<sta[i].mon2<<" "<<sta[i].mon3<<" "    <<sta[i].mon4<< "" <<sta[i].mon5 << "\ n"; }outfile.close ();}  Modify Employee information void Update (staff sta[],int count) {flag3:cout<< "Please enter the employee number to modify the information:"; char id[5] = {0};cin>>id;int    i= 0; for (i=0;i <count; i++) {if (strcmp (id,sta[i].id) ==0) {cout<< "Please select the information to be modified:" <<endl;cout<< "******** "<<endl; cout<< "****** 1. Modify base pay ******" <<endl;cout<< "****** 2. Modify dominate ******              "<<endl;cout<<" ****** 3. Modify ****** "<<endl;cout<<" ****** 4. Modify Medical Insurance "<<endl;cout<<" ****** 5. Modify the CPF ****** "<<endl;cout<<" ********** "<<endl;    cout<< "Please select the corresponding number sequence to operate:";    int a =0; char name[10] ={0}; Double Mon1 =0.0,mon2 =0.0,mon3 =0.0,mon4 =0.0,mon5 =0.0;cin>>a;switch (a) {case 1:cout<< "Please enter a new base salary:";  cin>>mon1;  Sta[i].mon1 = Mon1;  Break;case 2:cout<< "Please enter a new post salary:";  cin>>mon2;  Sta[i].mon2 = Mon2;   Break;case 3:cout<< "Please enter a new post salary:";  cin>>mon3;  Sta[i].mon3 = Mon3;  Break;case 4:cout<< "Please enter a new post salary:";  cin>>mon4;  Sta[i].mon4 = Mon4;   Break;case 5:cout<< "Please enter a new post salary:";  cin>>mon5;  Sta[i].mon5 = Mon5; break;default:cout<< "Input non-standard" &LT;&LT;ENDL;} Break;}} if (i >=count) {cout<< "Query not to the employee's ID" <<endl;cout<< "Please select whether to re-enter, if yes, enter Yes, otherwise enter the other" <<endl;char Ch [5];cin>>ch;if (strcmp (CH, "yes") ==0) goto Flag3;}} Delete Employee Information int Delete (staff sta[],int count) {char id[10]={0};cout<< "Please enter the employee ID you want to delete:"; Cin>>id;if (Count < 1 ) {cout<< "The system has no staff information. "<<endl;return count;} else{for (int i = 0;i < count;i++) {if (strcmp (id,sta[i].id) = = 0) {for (int j = i;j< (count-1); j + +) Sta[j]=sta[j+1];retu    RN count-1; }}cout<< "The platform does not have this employee information" <<endl;return count;}} Average void money for each item (staff Sta[],int count) {Double count1 = 0;double Count2 = 0;double Count3 = 0;double Count4 = 0;dou  ble count5 = 0;for (int i = 0;i< count; i++) {count1 = count1 + Sta[i].mon1;count2 = count2 + Sta[i].mon2;count3 = Count3 + sta[i].mon3;count4 = count4 + sta[i].mon4;count5 = count5 + sta[i].mon5;} cout<< "The average wage for each salary is" <<count1/count<< "<<count2/count<<" <<count3/count< < "<<count4/count<<" "&LT;&LT;COUNT5/COUNT&LT;&LT;ENDL; Statistics: Statistics meet the specified conditions (such as the first three employees wages and above 3000 yuan, 3000~2000 yuan, 2000~1000 yuan)//within the number of wage workers and the percentage of the total number of employees. Double Tongji (Staff sta[],int count,int m,int N)/* M-n for 1000-2000,2000-3000,3000-max*/{double number = 0.0;double mo Ney = 0.0;for (int i = 0; i < count; i++) {money = Sta[i].mon1 + Sta[i].mon2 + sta[i].mon3;if ((Money >= m) && ( Money <= N)) number++;} return number/count;} System interface void menu () {cout<< "####################################################################### "<<endl;cout<<"-------------------------- Employee Payroll Management System ()---------------------------"<<endl;cout<<" ********************************************** "<<endl;cout<<" * * 1. Modify Employee Information * * "<<endl;cout<<" * * 2.    Add Employee Information * * "<<endl; cout<< "* * 3.    Delete Employee Information * * "<<endl; cout<< "* * 4. Find Employee Information * * "<<endl;cout<<" * * 5. Statistical Staff Information * * "<<endl;cout<<" * * 6. Show Employee Information * * "<<endl;cout<<" * * 7. Exit System * * "<<endl;cout<<" ######################################################### ############## "<&Lt;endl;}    int main () {staff Sta[100];int count = 0;menu (); GetChar (); Count = Input (STA);cout<< "ID number name basic salary dominate allowance medical Insurance Provident Fund total wage average salary" <<endl;for (int i =0; i&lt ; count;i++) Sta[i].print (); Infile (sta,count);flag4:cout<< "Please select the function you want to perform:" <<endl;int num=0;double m = 0.0, n=  0.0;double temp = 0.0;cin>>num;switch (num) {case 1:update (sta,count);  Infile (Sta,count);  cout<< "ID number name basic salary dominate subsidy Medicare Provident Fund total wage average salary" <<endl;  for (int i =0; i< count;i++) sta[i].print ();  Break  Case 2:count=insert (Sta,count);  Infile (Sta,count);  cout<< "ID number name basic salary dominate subsidy Medicare Provident Fund total wage average salary" <<endl;  for (int i =0; i< count;i++) sta[i].print ();  Break  Case 3:count=delete (Sta,count);  Infile (Sta,count);  cout<< "ID number name basic salary dominate subsidy Medicare Provident Fund total wage average salary" <<endl;  for (int i =0; i< count;i++) sta[i].print ();  Break  Case 4:select (Sta,count); Case 5:Cout<< "Please enter the conditions you want to count the employee information specified by M and N:";  cin>>m>>n;  if (M > N) {temp = m; m = n;n=temp; } cout<< "The number of employees in the first three of the wages and the percentage of workers in the" <<m<< "-" <<n<< "and the total number of employees is as follows:" <<tongji (Sta,count  , M,n) <<endl;   Break   Case 6:cout<< "ID number name basic salary dominate allowance medical Insurance Provident Fund total wage average salary" <<endl;   for (int i =0; i< count;i++) sta[i].print ();   Money (Sta,count);  Break  Case 7:cout<< "exit system after 3 seconds" <<endl;  Sleep (3000);  return 0; default:cout<< "Input non-standard" &LT;&LT;ENDL;} cout<< "Please choose whether to continue using the system if it is input yes" <<endl;char ch[5]={0};cin>>ch;if (strcmp (CH, "yes") ==0) {menu (); Goto Flag4;} System ("pause"); return 0;}

There are a lot of problems with the code in this experiment. For example, the created array of classes takes up too much memory space and has a lot of spare. I think the next time you can try to use a linked list to do.


The design and realization of C + + staff salary management

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.