C + + realizes simple staff information Management System _c language

Source: Internet
Author: User

Functional Main Module Description

Module One: Add the Staff function add (), increase the basic information of workers.
Module Two: Delete the Staff function delete (), delete the basic information and compensation for the specified employee.
Module Three: Modify the Staff function modify (); Modify the specified employee basic information.
Module Four: Query Employee information function search (), query the specified employee information and remuneration.
Module Five: Sort employee information function sort (); Realization of sorting function of employee information
Module SIX: base data set function set (), set the basic remuneration for five categories of positions.
Module VII: Data storage, load function save () and load (), store employee basic information, remuneration and basic remuneration for five categories of positions.
The object-oriented program design method is adopted in this system. All methods are based on the class.

Code implementation:

#include <iostream> #include "string" #include <fstream> #include <stdlib.h> #include <stdio.h>  #define N-//n as the largest total number of workers int f=0;
F as a switch using namespace std;  string P;  P as a string void menu () for receiving menu options;  Show Menu class Worker {Public:worker () {} void Show ();//Employee information displays ~worker () {} friend class Workerlist; private:string
 Num,name,sex,edu,address,tel;
int age,salary;


};
 Class Workerlist {Private:worker w[n];  int NUM; Used to calculate the number of employees int count; Used to temporarily record the current operation the first few employees public:void add (); Employee Information entry void sort (); Employee Information sort void search (); Employee Information lookup void dele (); Staff information delete void Modify (); Employee information modify void save ();
 Employee information in the form of file Save void Showworker ()//Display employee information on the screen workerlist () {num=0;
 count=0;


}
};
 void menu ()//Display Menu {cout<<endl;
 cout<< "***********************************************" <<endl;
 cout<< "* * * * *" <<endl;
 cout<< "* * Employee Information Management System Main Menu * * <<endl;
 cout<< "* * * * *" <<endl; cout<< "* * 1. Employee Information Add * * <<endl;
 cout<< "* * 2. Employee Information Modification * * <<endl;
 cout<< "* * 3. Employee Information Delete * * <<endl;
 cout<< "* * 4. Employee Information Sort * * <<endl;
 cout<< "* * 5. Employee Information Search * * * <<endl;
 cout<< "* * 6. Employee Information Display * * <<endl;
 cout<< "* * 7. Employee Information Save * * <<endl;
 cout<< "* * 0. Exit * * <<endl;
 cout<< "* * * * *" <<endl;
 cout<< "***********************************************" <<endl;
cout<<endl;
 } void Domain ()//main Menu function implementation {Workerlist WL;
 while (1) {System ("CLS");
 menu ();
 cout<< "Please select number 0~7" <<endl;
 int i1;
 cin>>i1; while (!) (
 i1>=0&&i1<=7)) {cout<< "entered incorrectly, please re-enter:" <<endl;
 cin>>i1;
  Switch (i1) {case 1:wl.add ();
  Case 2:wl.modify ();
  Case 3:wl.dele ();
  Case 4:wl.sort ();
   Case 5:wl.search ();
  Case 6:wl.showworker ();
  Case 7:wl.save (); Case 0:cout<< "System exit!!
  "<<endl;
  Exit (0);
 Default:break; } Cout<< "Do you want to return to the main menu?
 y/n "<<endl;
 cin>>p; if (p== "n" | | p== "N") {cout<< system exit!!
 "<<endl;
 Exit (0);
 }} void Workerlist::add ()//Employee information Add function implementation {cout<< "Please enter employee information:" <<endl;
 cout<< "Work number:";
 String num;
 cin>>num;
 for (int i=0;i<num;i++) while (num==w[i].num) {cout<< "This employee number already exists, please re-enter:" <<endl;
 cout<< "Work number:";
 cin>>num;
 } W[num].num=num;
 cout<< "Name:";cin>>w[num].name;
 cout<< "Sex:";cin>>w[num].sex;
 cout<< "Education:";cin>>w[num].edu;
 cout<< "Age:";cin>>w[num].age;
 cout<< "Wages:";cin>>w[num].salary;
 cout<< "Address:";cin>>w[num].address;
 cout<< "Tel:";cin>>w[num].tel;
 ++num;
Count=num;
 } void Worker::show ()//Employee information display function implementation {cout<< "work number:" <<num<<endl;
 cout<< "Name:" <<name<<endl;
 cout<< "Sex:" <<sex<<endl;
 cout<< "Education:" <<edu<<endl;
 cout<< "Age:" <<age<<endl; cout<< "Salary: "<<salary<<endl;
 cout<< "Address:" <<address<<endl;
 cout<< "Tel:" <<tel<<endl;
cout<<endl;
 } void Workerlist::modify ()//Employee information modification function Implementation {if (num<=0) {cout<< "No employee information deposit, the system will return to the main menu" <<endl;
 menu ();
 cout<< "Please enter the work number of the employee who needs to modify the information:" <<endl;
 String Num1;
 cin>>num1;
 int j=0,k;
 int flag=1;
 while (flag) {for (; j<count;j++) {if (num1==w[j].num) {flag=0;
 K=j;
 Break
 } if (flag) {cout<< does not exist this employee, please re-enter: "<<endl;
 j=0;
 cin>>num1;
 } cout<< "The information of the employee you selected is:" <<endl;
 cout<< "Work No.:" <<w[k].num<<endl;
 cout<< "Name:" <<w[k].name<<endl;
 cout<< "Sex:" <<w[k].sex<<endl;
 cout<< "Education:" <<w[k].edu<<endl;
 cout<< "Age:" <<w[k].age<<endl;
 cout<< "Salary:" <<w[k].salary<<endl;
 cout<< "Address:" <<w[k].address<<endl;
 cout<< "Tel:" <<w[k].tel<<endl;
 cout<<endl;cout<< "***********************************************" <<endl;
 cout<< "* * 1. Change the work number * * * <<endl;
 cout<< "* * 2. Change name * * * <<endl;
 cout<< "* * 3. Modify Gender * * * <<endl;
 cout<< "* * 4. Revise education * * * <<endl;
 cout<< "* * 5. Revise age * * <<endl;
 cout<< "* * 6. Revise salary * * * <<endl;
 cout<< "* * 7. Modify Address * * <<endl;
 cout<< "* * 8. Modify Phone * * * <<endl;
 cout<< "* * 0. Back to main Menu * * <<endl;
 cout<< "***********************************************" <<endl;
 cout<<endl;
 cout<< "Please select number 0~8" <<endl;
 int i3;
 cin>>i3; while (i3<0| |
 i3>8) {cout<< "entered incorrectly, please re-enter:" <<endl;
 cin>>i3;
 Switch (i3) {case 1:cout<< "Please enter a new worker number:";
 cin>>w[k].num;
 cout<< "Modify information has been saved, now return to the main menu:" <<endl;
 menu ();
 Break
 Case 2:cout<< "Please enter the name of the new employee:";
 cin>>w[k].name;
 cout<< "Modify information has been saved, now return to the main menu:" <<endl;
 menu ();
 Break Case 3:cout<< "Please enter a newEmployee Sex: ";
 cin>>w[k].sex;
 cout<< "Modify information has been saved, now return to the main menu:" <<endl;
 menu ();
 Break
 Case 4:cout<< "Please enter a new staff degree:";
 cin>>w[k].edu;
 cout<< "Modify information has been saved, now return to the main menu:" <<endl;
 menu ();
 Break
 Case 5:cout<< "Please enter the new Age of workers:";
 cin>>w[k].age;
 cout<< "Modify information has been saved, now return to the main menu:" <<endl;
 menu ();
 Break
 Case 6:cout<< "Please enter the new worker's salary:";
 cin>>w[k].salary;
 cout<< "Modify information has been saved, now return to the main menu:" <<endl;
  menu ();
 Break
 Case 7:cout<< "Please enter the new employee's address:";
 cin>>w[k].address;
 cout<< "Modify information has been saved, now return to the main menu:" <<endl;
 menu ();
 Break
 Case 8:cout<< "Please enter a new employee Tel:";
 cin>>w[k].tel;
 cout<< "Modify information has been saved, now return to the main menu:" <<endl;
 menu ();
 Break
 Case 0:menu ();
 Default:break;
 } void Workerlist::showworker ()//Employee information display function implementation {if (num<=0) {cout<< "No employee information is stored, the system will return to the main menu" <<endl;
 menu ();
 Else cout<< "The saved employee information is as follows:" <<endl; for (int i=0;i<count;i++) {cout<< "***********************************************" &Lt;<endl;
  cout<< "Work No.:" <<w[i].num<<endl;
  cout<< "Name:" <<w[i].name<<endl;
  cout<< "Sex:" <<w[i].sex<<endl;
  cout<< "Education:" <<w[i].edu<<endl;
  cout<< "Age:" <<w[i].age<<endl;
  cout<< "Salary:" <<w[i].salary<<endl;
  cout<< "Address:" <<w[i].address<<endl;
 cout<< "Tel:" <<w[i].tel<<endl;
 cout<< "***********************************************" <<endl;
 } void Workerlist::search ()//Employee information query function implementation {if (num<=0) {cout<< "No employee information is stored, the system will return to the main menu" <<endl;
 menu ();
 else cout<< "***********************************************" <<endl;
 cout<< "* * Please choose the way to find: * * <<endl;
 cout<< "* * 1. Search by Work Number * * <<endl;
 cout<< "* * 2. Search by name * * <<endl;
 cout<< "* * 3. Search by Education * * <<endl;
 cout<< "* * 0. Back to main Menu * * <<endl; cout<< "***********************************************" <<endL
 cout<<endl;
 cout<< "Please select number 0~3" <<endl;
 int I4;
 cin>>i4; while (i4<0| |
 i4>3) {cout<< "entered incorrectly, please re-enter:" <<endl;
 cin>>i4;
 } if (i4==1) {string num2;
 cout<< "Please enter the work number of the employee to be queried:" <<endl;
 cin>>num2;
 int j=0,k;
 int flag=1;
 while (flag) {for (; j<count;j++) {if (num2==w[j].num) {flag=0;
  K=j;
  cout<< "Inquires the employee information as follows:" <<endl;
    cout<< "Work No.:" <<w[k].num<<endl;
     cout<< "Name:" <<w[k].name<<endl;
    cout<< "Sex:" <<w[k].sex<<endl;
    cout<< "Education:" <<w[k].edu<<endl;
    cout<< "Age:" <<w[k].age<<endl;
    cout<< "Salary:" <<w[k].salary<<endl;
    cout<< "Address:" <<w[k].address<<endl;
 cout<< "Tel:" <<w[k].tel<<endl;
 Break
 } if (flag) {flag=0; cout<< "does not exist this worker!!
 \ n Return to main menu "<<endl;
 Break
 }} else if (i4==2) {string name2; cout<< "Please enter the name of the employee you want to query:" <<endL
 cin>>name2;
 int j2=0,k2;
 int flag2=1;
 while (Flag2) {for (; j2<count;j2++) {if (name2==w[j2].name) {flag2=0;
 K2=j2;
 cout<< "Inquires the employee information as follows:" <<endl;
    cout<< "Work No.:" <<w[k2].num<<endl;
    cout<< "Name:" <<w[k2].name<<endl;
    cout<< "Sex:" <<w[k2].sex<<endl;
    cout<< "Education:" <<w[k2].edu<<endl;
    cout<< "Age:" <<w[k2].age<<endl;
    cout<< "Salary:" <<w[k2].salary<<endl;
    cout<< "Address:" <<w[k2].address<<endl;
 cout<< "Tel:" <<w[k2].tel<<endl;
 Break
 } if (Flag2) {flag2=0; cout<< "does not exist this worker!!
 \ n Return to main menu "<<endl;
 Break
 }} else if (i4==3) {string edu2;
 cout<< "Please enter the qualifications of the staff to inquire:" <<endl;
 cin>>edu2;
 int j4=0,k4;
 int flag4=1;
 while (FLAG4) {for (; j4<count;j4++) {if (edu2==w[j4].edu) {flag4=0;
 K4=j4;
 cout<< "Inquires the employee information as follows:" <<endl; cout<< "Work No.:" <<w[k4].num<<endL
    cout<< "Name:" <<w[k4].name<<endl;
    cout<< "Sex:" <<w[k4].sex<<endl;
    cout<< "Education:" <<w[k4].edu<<endl;
    cout<< "Age:" <<w[k4].age<<endl;
    cout<< "Salary:" <<w[k4].salary<<endl;
    cout<< "Address:" <<w[k4].address<<endl;
 cout<< "Tel:" <<w[k4].tel<<endl;
 Break
 } if (Flag4) {flag4=0; cout<< "does not exist this worker!!
 \ n Return to main menu "<<endl;
 Break
}} else if (i4==0) menu ();
 } void Workerlist::sort ()//Employee information sorting function implementation {if (num<=0) {cout<< "No employee information deposit, system will return to main menu" <<endl;
 menu ();
 else cout<< "***********************************************" <<endl;
 cout<< "* * Please select the sort way: * * <<endl;
 cout<< "* * 1. Sort by salary (ascending) * * <<endl;
 cout<< "* * 2. Sort by payroll (descending) * * <<endl;
 cout<< "* * 0. Back to main Menu * * <<endl;
 cout<< "***********************************************" <<endl;
 cout<<endl; cout<< "
 Please select a digital number 0~2 "<<endl;
 int i5;
 cin>>i5; while (i5<0| |
 I5&GT;2) {cout<< "entered incorrectly, please re-enter:" <<endl;
 cin>>i5; } if (I5==1) {for (int i=0;i<count-1;i++) for (int j=0;j<count-i-1;j++) if (w[j].salary>w[j+1].salary) {wor
 Ker temp;
 TEMP=W[J];
 W[J]=W[J+1];
 W[j+1]=temp;
 cout<< "The information in ascending order is as follows:" <<endl;
 for (i=0;i<count;i++) {cout<< "***********************************************" <<endl;
  cout<< "Work No.:" <<w[i].num<<endl;
  cout<< "Name:" <<w[i].name<<endl;
  cout<< "Sex:" <<w[i].sex<<endl;
  cout<< "Education:" <<w[i].edu<<endl;
  cout<< "Age:" <<w[i].age<<endl;
  cout<< "Salary:" <<w[i].salary<<endl;
  cout<< "Address:" <<w[i].address<<endl;
 cout<< "Tel:" <<w[i].tel<<endl;
 cout<< "***********************************************" <<endl;
} else if (i5==2) {for (int i=0;i<count-1;i++) for (int j=0;j<count-i-1;j++) if (w[j].salary<w[j+1].salary) {worker temp;
 TEMP=W[J];
 W[J]=W[J+1];
 W[j+1]=temp;
 cout<< the information in descending order of wages is as follows: <<endl;
 for (i=0;i<count;i++) {cout<< "***********************************************" <<endl;
  cout<< "Work No.:" <<w[i].num<<endl;
  cout<< "Name:" <<w[i].name<<endl;
  cout<< "Sex:" <<w[i].sex<<endl;
  cout<< "Education:" <<w[i].edu<<endl;
  cout<< "Age:" <<w[i].age<<endl;
  cout<< "Salary:" <<w[i].salary<<endl;
  cout<< "Address:" <<w[i].address<<endl;
 cout<< "Tel:" <<w[i].tel<<endl;
 cout<< "***********************************************" <<endl;
} else if (i5==0) menu ();
 } void Workerlist::d ele ()//Worker information Delete function implementation {if (num<=0) {cout<< "No employee information is stored, the system will return to the main menu" <<endl;
 menu ();
 cout<< "Please enter the work number of the employee who needs to delete information:" <<endl;
 String num3;
 cin>>num3;
 int j=0,k; int FLAg=1;
 while (flag) {for (; j<count;j++) {if (num3==w[j].num) {flag=0;
 K=j;
 Break
 } if (flag) {cout<< does not exist this employee, please re-enter: "<<endl;
 j=0;
 cin>>num3;
 } cout<< "The information of the employee you selected is:" <<endl;
 cout<< "Work No.:" <<w[k].num<<endl;
 cout<< "Name:" <<w[k].name<<endl;
 cout<< "Sex:" <<w[k].sex<<endl;
 cout<< "Education:" <<w[k].edu<<endl;
 cout<< "Age:" <<w[k].age<<endl;
 cout<< "Salary:" <<w[k].salary<<endl;
 cout<< "Address:" <<w[k].address<<endl;
 cout<< "Tel:" <<w[k].tel<<endl;
 cout<<endl;
 cout<< "Confirm Delete Please enter Y, return main Menu Please enter n" <<endl;
 string P;
 cin>>p; while (1) {if (p== "Y" | | p== "Y") {cout<< employee information has been deleted!
 "<<endl;
 for (int i=0;i<count;i++) if (w[i].num==num3) int j=i;
 for (; j<=count-1;j++) w[j]=w[j+1];
 count--;
 Break else if (p== "n" | | 
 p== "N") {menu ();
 else {cout<< "entered incorrectly, please re-enter:"; Cin>>p;
 }} void Workerlist::save ()//Worker information Save function Implementation {if (num<=0) {cout<< "No employee information is stored, the system will return to the main menu" <<endl;
 menu ();
 else {ofstream fout;
 Fout.open ("D:\\worker.txt", ios::out); cout<< "file is being saved ... Please wait a moment!!
 "<<endl; cout<< "Data saved successfully!!!
 "<<endl;
 fout<< "The saved employee information is as follows:" <<endl;
 for (int i=0;i<count;i++) {fout<< "***********************************************" <<endl;
 fout<< "Work No.:" <<w[i].num<<endl;
 fout<< "Name:" <<w[i].name<<endl;
 fout<< "Sex:" <<w[i].sex<<endl;
 fout<< "Education:" <<w[i].edu<<endl;
 fout<< "Age:" <<w[i].age<<endl;
 fout<< "Salary:" <<w[i].salary<<endl;
 fout<< "Address:" <<w[i].address<<endl;
 fout<< "Tel:" <<w[i].tel<<endl;
 fout<< "***********************************************" <<endl;
 cout<< "System return Main Menu:" <<endl;
 menu ();
 Fout.close (); 
 int main () {domain (); Return0;
 }

Operation Effect:

When the program is running, the main interface menu appears first, the user carries on the function choice, chooses the different number, enters the different function area. As shown in Figure 1.

Figure 1 Program run main interface

Select 1 to display the secondary menu and enter the employee information add interface, as shown in Figure 2.

Figure 2 Employee Information Add interface

Select Y, return to the program run the main interface, continue to select 6, then show the secondary menu, enter the staff information browsing display interface as shown in Figure 3.

Figure 3 Employee Information Display interface

To find the staff information, select 5, through the work number, name, education three ways to find, select 1 to determine according to the work number to find, as shown in Figure 4.

Figure 4 Employee Information Sorting interface

Select 4, you can sort by salary, select 1 to sort in ascending order, as shown in Figure 5.

Figure 5 Employee Information Lookup interface

Back to the program run the main interface, select 2, the staff 1 information to modify, select the secondary menu which 1~8 options to modify, as shown in Figure 6.

Figure 6 Employee Information Modification interface

Select 3 to delete the employee information, as shown in Figure 7.

Figure 7 Employee Information Deletion interface

Back to the program run the main interface, select 7, the operation of staff information to save, while returning to the main system interface, as shown in Figure 8.

Figure 8 Employee Information Saving interface

The above is the entire content of this article, I hope to help you learn.

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.