职工信息管理系统C++代码
生活随笔
收集整理的這篇文章主要介紹了
职工信息管理系统C++代码
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
相關文章推薦:
1、?C語言學生成績管理系統源代碼?★★★★★
2、?C語言學籍管理系統源代碼?★★
3、C語言學生成績管理系統設計 《C語言程序設計》實訓報告?★★★
4、C語言學生信息管理系統源代碼?★★★★
掃描上方二維碼,回復?999?直接獲取作者之前收藏的學習資源,謝謝網友們的分享。
更多管理系統更新中,請注意關注!
大學實訓課學習到的一段源代碼,職工信息管理系統 c++項目源代碼。
#include <string> #include <iostream> #include <fstream> #include <iomanip> #include <memory.h> #include <stdio.h> #include <conio.h> #include <stdlib.h> using namespace std; class employee { public:string m_Code; string m_Name; unsigned short int m_Year; string m_Sex; string m_Post; string m_Department; unsigned int m_Wage; //鏈表節點的指針域--- employee* Next; public:employee* Create(employee* Head); void Rel(employee* Head); employee* Add(employee* Head); bool Search(employee* Head); employee* Search_Unique_Front(employee* Head); void Display_List(employee* Head); void Display_Node(employee* pNode); employee* Modify(employee* Head); employee* Del(employee* Head); void Save_ByFile(employee* Head,fstream& ofile); employee* Sort(employee* Head); };employee* employee::Create(employee* Head) {//創建一個帶頭節點的空鏈表。 Head=new employee; if(!Head) { cout<<"分配內存失敗!"<<endl; return NULL; } Head->m_Code=""; Head->m_Name=""; Head->m_Year=0; Head->m_Sex=""; Head->m_Post=""; Head->m_Department=""; Head->m_Wage=0; Head->Next=NULL; return Head; } void employee::Rel(employee* Head) {//釋放鏈表。 employee* ptr;//聲明一個操作用的指針。 while(Head!=NULL) { ptr=Head; Head=Head->Next; delete ptr;//釋放節點資源。 } } employee* employee::Add(employee* Head) {//前插法添加數據。 employee* pNew;// 聲明一個新節點。 char again; string code,name,sex,post,department; unsigned short int year; unsigned int wage; do { pNew=new employee; //數據域。 cout<<"請輸入職工代碼:"; cin>>code; cout<<endl<<"請輸入職工姓名:"; cin>>name; cout<<endl<<"請輸入職工出生年份:"; cin>>year; while(cin.fail()) { cout<<"請輸入正確的年份格式。"<<endl; cin.clear(); fflush(stdin); cin>>year; } cout<<endl<<"請輸入職工性別:"; cin>>sex; cout<<endl<<"請輸入職工職稱:"; cin>>post; cout<<endl<<"請輸入職工部門:"; cin>>department; cout<<endl<<"請輸入職工工資:"; cin>>wage; while(cin.fail()) { cout<<"請輸入正確的工資數據。"<<endl; cin.clear(); fflush(stdin); cin>>wage; } cout<<endl; pNew->m_Code=code; pNew->m_Name=name; pNew->m_Year=year; pNew->m_Sex=sex; pNew->m_Post=post; pNew->m_Department=department; pNew->m_Wage=wage; //指針域。 pNew->Next=Head->Next; Head->Next=pNew; cout<<"數據添加成功!是否繼續添加?(Y/N)"<<endl; cin>>again; }while(again=='Y'||again=='y'); return Head; } bool employee::Search(employee* Head) {//查詢同時滿足“姓名”和“部門”的職工信息。 employee* ptr; string department; string name; ptr=Head->Next; cout<<"請輸入部門:"; cin>>department; cout<<endl<<"請輸入姓名:"; cin>>name; cout<<endl<<"----------------查詢結果------------------"<<endl; while(ptr) { if((ptr->m_Name==name)&&(ptr->m_Department==department)) { Display_Node(ptr);//打印滿足條件的節點。 return true; } ptr=ptr->Next;//查詢下一節點。 } cout<<"無此職工的信息。"<<endl; return false; } employee* employee::Search_Unique_Front(employee* Head) {employee* ptr;string code;ptr= Head->Next;cout<<"請輸入職工代碼:";cin>>code;cout<<endl<<"----------------查詢結果------------------"<<endl; while(ptr){if(ptr->m_Code==code)return ptr;ptr=ptr->Next;}return ptr; } void employee::Display_List(employee* Head) { employee* ptr; ptr=Head->Next; cout<<"==================所有職工信息=================="<<endl; while(ptr) { Display_Node(ptr); ptr=ptr->Next; } } void employee::Display_Node(employee* pNode) {//在標準輸出設備上輸出。 cout<<setw(10)<<left<<pNode->m_Code <<setw(10)<<left<<pNode->m_Name <<setw(10)<<left<<pNode->m_Year <<setw(10)<<left<<pNode->m_Sex <<setw(10)<<left<<pNode->m_Post <<setw(10)<<left<<pNode->m_Department <<setw(10)<<left<<pNode->m_Wage<<endl;//setw(10)表示占10個字符位置。 } employee* employee::Modify(employee* Head) {// 修改單一個節點。 employee* ptr; ptr=Search_Unique_Front(Head); string code,name,sex,post,department; unsigned short int year; unsigned int wage; if(ptr) { cout<<"-------你現在可以修改此職工的信息了-------"<<endl; //數據域。 cout<<"請輸入職工代碼:"; cin>>code; cout<<endl<<"請輸入職工姓名:"; cin>>name; cout<<endl<<"請輸入職工出生年份:"; cin>>year; while(cin.fail()) { cout<<"請輸入正確的年份格式。"<<endl; cin.clear(); fflush(stdin); cin>>year; } cout<<endl<<"請輸入職工性別:"; cin>>sex; cout<<endl<<"請輸入職工職稱:"; cin>>post; cout<<endl<<"請輸入職工部門:"; cin>>department; cout<<endl<<"請輸入職工工資:"; cin>>wage; while(cin.fail()) { cout<<"請輸入正確的工資數據。"<<endl; cin.clear(); fflush(stdin); cin>>wage; } cout<<endl; ptr->m_Code=code;ptr->m_Name=name; ptr->m_Year=year; ptr->m_Sex=sex; ptr->m_Post=post; ptr->m_Department=department; ptr->m_Wage=wage; } else{cout<<"沒找到此職工的記錄,無法修改。"<<endl; }return Head; } employee* employee::Del(employee* Head) { string code;employee* parentptr; employee* ptr_front; //ptr_front=Search_Unique_Front(Head); cout<<"請輸入職工代碼:";cin>>code;parentptr= Head;ptr_front = Head->Next;while(ptr_front){if(ptr_front->m_Code==code){parentptr->Next = ptr_front->Next;delete ptr_front;return Head;}parentptr = ptr_front;ptr_front = ptr_front->Next;}return Head; }void employee::Save_ByFile(employee* Head,fstream& ofile) { employee* pNode; pNode=Head->Next; ofile.clear();//清除文件結束狀態。 while(pNode) { ofile<<setw(10)<<left<<pNode->m_Code <<setw(10)<<left<<pNode->m_Name <<setw(10)<<left<<pNode->m_Year <<setw(10)<<left<<pNode->m_Sex <<setw(10)<<left<<pNode->m_Post <<setw(10)<<left<<pNode->m_Department <<setw(10)<<left<<pNode->m_Wage<<endl;//setw(10)表示占10個字符位置。 pNode=pNode->Next; } cout<<"數據文件保存成功!"<<endl; } employee* employee::Sort(employee* Head) {//我創建的是帶頭節點的鏈表。用直接插入法。 if((Head->Next==NULL)||(Head->Next->Next==NULL))//此步條件判斷非常有價值。 { cout<<"數據節點數少于2個,不用排序!"<<endl; return Head; } //-----------第二步; employee* ptr; employee* ptr_F; employee* ptr_N; ptr=Head->Next->Next; ptr_F=Head; Head->Next->Next=NULL;//到此,分成了兩個鏈表。 //第三步。 while(ptr) { ptr_N=ptr->Next; ptr_F=Head;//ptr_F的歸位。 while(ptr_F->Next) { if(ptr->m_Wage>ptr_F->Next->m_Wage) { ptr->Next=ptr_F->Next; ptr_F->Next=ptr; break; }else { ptr_F=ptr_F->Next; } }if(ptr_F->Next==NULL) { ptr->Next=ptr_F->Next; ptr_F->Next=ptr;//表示插到有序鏈表的最后面了。 } ptr=ptr_N;//歸位,準備下一次排序。 }cout<<"從高到低,排序成功!"<<endl; return Head; } int main() { employee* st = new employee();st=st->Create(st); fstream iofile; iofile.open("d:\\iofile.txt",ios_base::in|ios_base::out|ios_base::app);//文件以三種方式打開。 if(!iofile) { cout<<"打開文件失敗!"<<endl; return -1; } int menu; while(1) { cout<<"*****************************************************"<<endl; cout<<"*====================菜單選頂=======================*"<<endl; cout<<"* *"<<endl; cout<<"* 1.注冊職工 2.修改信息 3.刪除信息 4.信息查詢 *"<<endl; cout<<"* 5.保存文件 6.工資排行 7.信息顯示 0.退出系統 *"<<endl; cout<<"* *"<<endl;cout<<"*****************************************************"<<endl; cout<<endl<<"請選擇相應操作菜單項:"; cin>>menu; while(cin.fail()) { cout<<"請選擇正確的菜單選項。"<<endl; cin.clear(); fflush(stdin); cin>>menu; } switch(menu) { case 0: cout<<"成功退出系統!"<<endl; return 0; case 1: st=st->Add(st); break; case 2: st=st->Modify(st); break; case 3: st=st->Del(st); break; case 4: st->Search(st); break; case 5: st->Save_ByFile(st,iofile); break; case 6: st->Sort(st); break; case 7: st->Display_List(st); break; default: cout<<"請選擇正確的菜單項進行操作。多謝合作!"<<endl; } } st->Rel(st); iofile.close(); return 0; }也希望能幫到正在做實訓報告的你,歡迎留言區討論。
分享:C語言學生成績管理系統設計?《C語言程序設計》實訓報告
掃描下方公眾號,發送?成績系統?4個字,獲取下載實訓源碼。
感謝關注,共同進步!
總結
以上是生活随笔為你收集整理的职工信息管理系统C++代码的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 谈自动化测试与CI中一些常见的谬见
- 下一篇: ASP.NET页面揭秘之页面生命周期【转