C++实现员工信息管理系统
生活随笔
收集整理的這篇文章主要介紹了
C++实现员工信息管理系统
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
一、問題描述及要求
| 設計題目 | ?員工信息管理系統 | 成績 | ? |
| 課 程 設 計 主 要 內 容 | 【問題描述】 編寫一個程序來管理員工信息。通過一個類來存放輸入的每一位員工的記錄(包括員工號、姓名、性別、所屬部門、職稱、入職時間、聯系電話等),然后將其信息保存到文件中。通過幾個函數來創建新員工號,并對職工信息進行刪除及修改,輸入一個員工號查詢該職工的信息,并顯示在屏幕上。 【任務要求】 運用類的思想來實現員工信息管理系統的編寫。實現以下操作: | ||
二、運營環境及開發工具
1、C語言以及C++語言
2、vc++6.0
3、Dev-C++
三、流程圖
1、系統流程圖
?
2、主函數流程圖
?3、具體函數流程圖略
? ? 很好畫的,可以參考上面的流程圖。
四、實現代碼
#include <iostream> #include <string> #include <fstream> using namespace std; class staff { private: string employee_number;//職工號 string name;//姓名 int age;//年齡 string sex;//性別 string zip_code;//職稱 string department;//部門 string time; //入職時間 string tel; //聯系電話 class staff* next; public: staff():next(NULL){} void registration(class staff* head);//注冊 尾插 void query_employeenumber(class staff* t);//按員工號查詢 void query_name(class staff* t);//按照姓名查詢員工信息 void query_tel(class staff* t);//按照聯系電話查詢員工信息 void delete_num(class staff* t);//按工號刪除員工信息 void delete_name(class staff* t);//按姓名刪除員工信息 void show_all(class staff* head);//輸出所有員工信息 void query_sex(class staff* t); void update(class staff* head); void update_num(class staff* head);//修改工號 void update_name(class staff* head);//修改姓名 void update_age(class staff* head);//修改年齡 void update_sex(class staff* head);//修改性別 void update_zip(class staff* head);//修改職稱 void update_depart(class staff* head);//修改部門 void update_time(class staff* head);//修改入職時間 void update_tel(class staff* head);//修改聯系電話 void update_all(class staff* head);//修改全部 int read(class staff* head); void write(class staff* t); }; void staff::registration(class staff* head)//注冊 尾插 { while(head->next != NULL) { head = head->next; } staff* newnode = new staff; head->next = newnode; newnode->next = NULL; cout << "請輸入員工信息" << endl; cout << "員工號: " << endl; cin >> newnode->employee_number; cout << "員工姓名: " << endl; cin >> newnode->name; cout << "員工年齡: " << endl; cin >> newnode->age; cout << "職工性別: " << endl; cin >> newnode->sex; cout << "員工職稱: " << endl; cin >> newnode->zip_code; cout << "員工部門: " << endl; cin >> newnode->department; cout<<"員工入職時間: "<<endl; cin >> newnode->time; cout<<"員工聯系電話: "<<endl; cin >> newnode->tel; } void staff::show_all(class staff* head)//輸出 { int i = 0; while(head->next != NULL) { i++; cout << i << "." << "工號:" ; cout << head->next->employee_number <<'\t'; cout << "名字:" ; cout << head->next->name <<'\t'; cout << "性別:" ; cout << head->next->sex <<'\t'; cout << "年齡:" ; cout << head->next->age <<'\t'; cout << "職稱:" ; cout << head->next->zip_code << '\t'; cout << "部門:" ; cout << head->next->department << '\t'; cout << "入職時間:" ; cout << head->next->time << '\t'; cout << "聯系電話:" ; cout << head->next->tel << endl; head = head->next; } } void staff::query_employeenumber(class staff* t)//按員工工號查詢 { string n; cout << "請輸入你想查詢員工工號:" << endl; cin >> n; int count = 0; while(t->next != NULL) { if(t->next->employee_number == n) { cout << "工號:" ; cout << t->next->employee_number <<'\t'; cout << "名字:"; cout << t->next->name <<'\t'; cout << "性別:" ; cout << t->next->sex <<'\t'; cout << "年齡:" ; cout << t->next->age <<'\t'; cout << "郵編:" ; cout << t->next->zip_code << '\t'; cout << "部門:"; cout << t->next->department << '\t'; cout << "入職時間:" ; cout << t->next->time << '\t'; cout << "聯系電話:" ; cout << t->next->tel << endl; count++; } t = t->next; } if(count == 0) { cout << "查無此人!" << endl; } } void staff::query_name(class staff* t)//按員工姓名查詢 { string n; cout << "請輸入你想查詢員工姓名:" << endl; cin >> n; int count = 0; while(t->next != NULL) { if(t->next->name == n) { cout << "工號:" ; cout << t->next->employee_number <<'\t'; cout << "名字:"; cout << t->next->name <<'\t'; cout << "性別:" ; cout << t->next->sex <<'\t'; cout << "年齡:" ; cout << t->next->age <<'\t'; cout << "職稱:" ; cout << t->next->zip_code << '\t'; cout << "部門:"; cout << t->next->department << '\t'; cout << "入職時間:" ; cout << t->next->time << '\t'; cout << "聯系電話:" ; cout << t->next->tel << endl; count++; } t = t->next; } if(count == 0) { cout << "查無此人!" << endl; } } void staff::query_tel(class staff* t)//按員工聯系電話查詢 { string n; cout << "請輸入你想查詢聯系電話:" << endl; cin >> n; int count = 0; while(t->next != NULL) { if(t->next->tel == n) { cout << "工號:" ; cout << t->next->employee_number <<'\t'; cout << "名字:"; cout << t->next->name <<'\t'; cout << "性別:" ; cout << t->next->sex <<'\t'; cout << "年齡:" ; cout << t->next->age <<'\t'; cout << "郵編:" ; cout << t->next->zip_code << '\t'; cout << "部門:"; cout << t->next->department << '\t'; cout << "入職時間:" ; cout << t->next->time << '\t'; cout << "聯系電話:" ; cout << t->next->tel << endl; count++; } t = t->next; } if(count == 0) { cout << "查無此人!" << endl; } } void staff::delete_num(class staff* t)//按員工號刪除 { string n; cout << "請輸入你想刪除員工工號:" << endl; cin >> n; int count = 0; while(t->next != NULL) { if(t->next->employee_number == n) { staff* temp = t->next; t->next = t->next->next; delete temp; temp = NULL; cout << "刪除成功!" << endl; count++; break; } t = t->next; } if(count == 0) { cout << "查無此人!" << endl; } } void staff::delete_name(class staff* t)//按員工姓名刪除 { string n; cout << "請輸入你想刪除員工的姓名:" << endl; cin >> n; int count = 0; while(t->next != NULL) { if(t->next->name == n) { staff* temp = t->next; t->next = t->next->next; delete temp; temp = NULL; cout << "刪除成功!" << endl; count++; break; } t = t->next; } if(count == 0) { cout << "查無此人!" << endl; } } void staff::update(class staff* head) { int num = 0; cout << "1.修改員工號" << endl; cout << "2.修改員工姓名" << endl; cout << "3.修改員工年齡" << endl; cout << "4.修改員工性別" << endl; cout << "5.修改員工職稱" << endl; cout << "6.修改員工部門" << endl; cout << "7.修改員工入職時間" << endl; cout << "8.修改員工聯系電話" << endl; cout << "9.修改全部" << endl; cin >> num; switch(num) { case 1: update_num(head); break; case 2: update_name(head); break; case 3: update_age(head); break; case 4: update_sex(head); break; case 5: update_zip(head); break; case 6: update_depart(head); break; case 7: update_time(head); break; case 8: update_tel(head); case 9: update_all(head); break; default: cout << "請重新輸入正確的指令!" << endl; } } void staff::query_sex(class staff* t)//統計 { string n; cout << "請輸入你要統計的員工的姓別(男或女):" << endl; cin >> n; int count = 0; while(t->next != NULL) { if(t->next->sex == n) { count++; break; } t = t->next; } cout << "共有"<<n<<"員工: " <<count<<"個"<< endl; } void staff::update_num(class staff* head)//修改工號 { cout << "輸入要修改對象的工號:"<< endl; int count = 0; string temp; cin >> temp; while(head->next != NULL) { if(temp == head->next->employee_number) { count = 1; cout<< "輸入新工號:"<< endl; string temp2; cin>>temp2; head->next->employee_number = temp2; cout << "修改成功" << endl; break; } head = head->next; } if(count == 0) { cout << "查無此人" << endl; } } void staff::update_name(class staff* head)//修改姓名 { cout << "輸入要修改對象的工號:"<< endl; int count = 0; string temp; cin >> temp; while(head->next != NULL) { if(temp == head->next->employee_number) { count = 1; cout << "輸入新名字:"<< endl; string temp2; cin >> temp2; head->next->name = temp2; cout << "修改成功" << endl; break; } head = head->next; } if(count == 0) { cout << "查無此人" << endl; } } void staff::update_age(class staff* head)//修改年齡 { cout << "輸入要修改對象的工號:"<< endl; int count = 0; string temp; cin >> temp; while(head->next != NULL) { if(temp == head->next->employee_number) { count = 1; cout << "輸入新年齡:"<< endl; int temp2; cin >> temp2; head->next->age = temp2; cout << "修改成功" << endl; break; } head = head->next; } if(count == 0) { cout << "查無此人" << endl; } } void staff::update_sex(class staff* head)//修改性別 { cout << "輸入要修改對象的工號:"<< endl; int count = 0; string temp; cin >> temp; while(head->next != NULL) { if(temp == head->next->employee_number) { count = 1; cout << "輸入新性別:"<< endl; string temp2; cin >> temp2; head->next->sex = temp2; cout << "修改成功" << endl; break; } head = head->next; } if(count == 0) { cout << "查無此人" << endl; } } void staff::update_zip(class staff* head)//修改職稱 { cout << "輸入要修改對象的工號:"<< endl; int count = 0; string temp; cin >> temp; while(head->next != NULL) { if(temp == head->next->employee_number) { count = 1; cout << "輸入職稱:"<< endl; string temp2; cin >> temp2; head->next->zip_code = temp2; cout << "修改成功" << endl; break; } head = head->next; } if(count == 0) { cout << "查無此人" << endl; } } void staff::update_depart(class staff* head)//修改部門 { cout << "輸入要修改對象的工號:"<< endl; int count = 0; string temp; cin >> temp; while(head->next != NULL) { if(temp == head->next->employee_number) { count = 1; cout << "輸入新部門:"<< endl; string temp2; cin >> temp2; head->next->department = temp2; cout << "修改成功" << endl; break; } head = head->next; } if(count == 0) { cout << "查無此人" << endl; } } void staff::update_time(class staff* head)//修改入職時間 { cout << "輸入要修改對象的工號:"<< endl; int count = 0; string temp; cin >> temp; while(head->next != NULL) { if(temp == head->next->employee_number) { count = 1; cout << "輸入新入職時間:"<< endl; int temp2; cin >> temp2; head->next->time = temp2; cout << "修改成功" << endl; break; } head = head->next; } if(count == 0) { cout << "查無此人" << endl; } } void staff::update_tel(class staff* head)//修改聯系電話 { cout << "輸入要修改對象的工號:"<< endl; int count = 0; string temp; cin >> temp; while(head->next != NULL) { if(temp == head->next->employee_number) { count = 1; cout << "輸入新入職時間:"<< endl; int temp2; cin >> temp2; head->next->tel = temp2; cout << "修改成功" << endl; break; } head = head->next; } if(count == 0) { cout << "查無此人" << endl; } } void staff::update_all(class staff* head)//修改全部 { cout<<"輸入要修改對象的工號:"<<flush; int count = 0; string tmp; cin >> tmp; while(head->next != NULL) { if(tmp == head->next->employee_number) { count = 1; cout << "輸入新工號:"<< endl; string temp; int tmp; cin >> temp; head->next->employee_number = temp; cout<< "輸入新名字:"<< endl; cin >> temp; head->next->name = temp; cout<< "輸入新性別:"<< endl; cin >> temp; head->next->sex = temp; cout<< "輸入新年齡:"<< endl; cin >> tmp; head->next->age = tmp; cout<< "輸入新職稱:"<< endl; cin >> temp; head->next->zip_code = temp; cout<< "輸入新部門:"<< endl; cin >> temp; head->next->department = temp; cout<< "輸入新入職時間:"<< endl; cin >> temp; head->next->time = tmp; cout<< "輸入新入聯系電話:"<< endl; cin >> temp; head->next->tel = tmp; cout << "修改成功" << endl; break; } head = head->next; } if(count == 0) { cout << "查無此人" << endl; } } int staff::read(class staff* head) { ofstream infile1; infile1.open("員工系統.txt",ios::app); if(!infile1) { return 0; } else { infile1.close(); ifstream infile; infile.open("員工系統.txt",ios::in); while(!infile.eof()) { staff* newnode = new staff; infile >> newnode->employee_number; if(newnode->employee_number.length() == 0) { delete newnode; break; } infile >> newnode->name; infile >> newnode->sex; infile >> newnode->age; infile >> newnode->zip_code; infile >> newnode->department; infile >> newnode->time; infile >> newnode->tel; head->next = newnode; head = head->next; } infile.close(); } return 0; } void staff::write(class staff* t) { ofstream outfile; outfile.open("員工系統.txt",ios::out); while(t->next != NULL) { outfile << t->next->employee_number << '\t'; outfile << t->next->name << '\t'; outfile << t->next->sex << '\t'; outfile << t->next->age << '\t'; outfile << t->next->zip_code << '\t'; outfile << t->next->department << '\t'; outfile << t->next->time << '\t'; outfile << t->next->tel << endl; t = t->next; } outfile.close(); } int main() { staff* head = new staff; head->read(head); string temp; cout << "********歡迎來到員工管理系統!********" << endl; while(1) { cout << "------------------------------------" << endl; head->show_all(head); cout << "------------------------------------" << endl; cout << endl; cout << "1.輸入員工信息" << endl; cout << "2.輸出員工信息" << endl; cout << "3.按員工工號查詢員工信息"<< endl; cout << "4.按照姓名查詢員工信息" << endl; cout << "5.按照聯系電話查詢員工信息" << endl; cout << "6.按工號刪除員工信息" << endl; cout << "7.按姓名刪除員工信息" << endl; cout << "8.統計員工個數" << endl; cout << "9.修改員工信息" << endl; cout << "0.退出" << endl; cout << endl; cout << "請輸入你想選擇的功能:" << endl; int number; cin >> number; switch(number) { case 1: { head->registration(head); break; } case 2: {head->show_all(head); break; } case 3: { head->query_employeenumber(head); break; } case 4: { head->query_name(head); break; } case 5: { head->query_tel(head); break; } case 6: { head->delete_num(head); break; } case 7: { head->delete_name(head); break; } case 8: { head->query_sex(head); break; } case 9: { head->update(head); break; } case 0: { head->write(head); return 0; } default: cout << "請重新輸入正確的操作指令" << endl; } } }五、結果舉例
?
?
?
?
?
?
?
?
?
總結
以上是生活随笔為你收集整理的C++实现员工信息管理系统的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Quartus 中快速分配器件管脚
- 下一篇: 快速求幂算法