职工信息管理系统C++代码
生活随笔
收集整理的這篇文章主要介紹了
职工信息管理系统C++代码
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
相關(guān)文章推薦:
1、?C語言學(xué)生成績管理系統(tǒng)源代碼?★★★★★
2、?C語言學(xué)籍管理系統(tǒng)源代碼?★★
3、C語言學(xué)生成績管理系統(tǒng)設(shè)計(jì) 《C語言程序設(shè)計(jì)》實(shí)訓(xùn)報(bào)告?★★★
4、C語言學(xué)生信息管理系統(tǒng)源代碼?★★★★
掃描上方二維碼,回復(fù)?999?直接獲取作者之前收藏的學(xué)習(xí)資源,謝謝網(wǎng)友們的分享。
更多管理系統(tǒng)更新中,請注意關(guān)注!
大學(xué)實(shí)訓(xùn)課學(xué)習(xí)到的一段源代碼,職工信息管理系統(tǒng) c++項(xiàng)目源代碼。
#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; //鏈表節(jié)點(diǎn)的指針域--- 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) {//創(chuàng)建一個(gè)帶頭節(jié)點(diǎn)的空鏈表。 Head=new employee; if(!Head) { cout<<"分配內(nèi)存失敗!"<<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;//聲明一個(gè)操作用的指針。 while(Head!=NULL) { ptr=Head; Head=Head->Next; delete ptr;//釋放節(jié)點(diǎn)資源。 } } employee* employee::Add(employee* Head) {//前插法添加數(shù)據(jù)。 employee* pNew;// 聲明一個(gè)新節(jié)點(diǎn)。 char again; string code,name,sex,post,department; unsigned short int year; unsigned int wage; do { pNew=new employee; //數(shù)據(jù)域。 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<<"請輸入正確的工資數(shù)據(jù)。"<<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<<"數(shù)據(jù)添加成功!是否繼續(xù)添加?(Y/N)"<<endl; cin>>again; }while(again=='Y'||again=='y'); return Head; } bool employee::Search(employee* Head) {//查詢同時(shí)滿足“姓名”和“部門”的職工信息。 employee* ptr; string department; string name; ptr=Head->Next; cout<<"請輸入部門:"; cin>>department; cout<<endl<<"請輸入姓名:"; cin>>name; cout<<endl<<"----------------查詢結(jié)果------------------"<<endl; while(ptr) { if((ptr->m_Name==name)&&(ptr->m_Department==department)) { Display_Node(ptr);//打印滿足條件的節(jié)點(diǎn)。 return true; } ptr=ptr->Next;//查詢下一節(jié)點(diǎn)。 } cout<<"無此職工的信息。"<<endl; return false; } employee* employee::Search_Unique_Front(employee* Head) {employee* ptr;string code;ptr= Head->Next;cout<<"請輸入職工代碼:";cin>>code;cout<<endl<<"----------------查詢結(jié)果------------------"<<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) {//在標(biāo)準(zhǔn)輸出設(shè)備上輸出。 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個(gè)字符位置。 } employee* employee::Modify(employee* Head) {// 修改單一個(gè)節(jié)點(diǎn)。 employee* ptr; ptr=Search_Unique_Front(Head); string code,name,sex,post,department; unsigned short int year; unsigned int wage; if(ptr) { cout<<"-------你現(xiàn)在可以修改此職工的信息了-------"<<endl; //數(shù)據(jù)域。 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<<"請輸入正確的工資數(shù)據(jù)。"<<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();//清除文件結(jié)束狀態(tài)。 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個(gè)字符位置。 pNode=pNode->Next; } cout<<"數(shù)據(jù)文件保存成功!"<<endl; } employee* employee::Sort(employee* Head) {//我創(chuàng)建的是帶頭節(jié)點(diǎn)的鏈表。用直接插入法。 if((Head->Next==NULL)||(Head->Next->Next==NULL))//此步條件判斷非常有價(jià)值。 { cout<<"數(shù)據(jù)節(jié)點(diǎn)數(shù)少于2個(gè),不用排序!"<<endl; return Head; } //-----------第二步; employee* ptr; employee* ptr_F; employee* ptr_N; ptr=Head->Next->Next; ptr_F=Head; Head->Next->Next=NULL;//到此,分成了兩個(gè)鏈表。 //第三步。 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;//歸位,準(zhǔ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.退出系統(tǒng) *"<<endl; cout<<"* *"<<endl;cout<<"*****************************************************"<<endl; cout<<endl<<"請選擇相應(yīng)操作菜單項(xiàng):"; cin>>menu; while(cin.fail()) { cout<<"請選擇正確的菜單選項(xiàng)。"<<endl; cin.clear(); fflush(stdin); cin>>menu; } switch(menu) { case 0: cout<<"成功退出系統(tǒng)!"<<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<<"請選擇正確的菜單項(xiàng)進(jìn)行操作。多謝合作!"<<endl; } } st->Rel(st); iofile.close(); return 0; }也希望能幫到正在做實(shí)訓(xùn)報(bào)告的你,歡迎留言區(qū)討論。
分享:C語言學(xué)生成績管理系統(tǒng)設(shè)計(jì)?《C語言程序設(shè)計(jì)》實(shí)訓(xùn)報(bào)告
掃描下方公眾號,發(fā)送?成績系統(tǒng)?4個(gè)字,獲取下載實(shí)訓(xùn)源碼。
感謝關(guān)注,共同進(jìn)步!
總結(jié)
以上是生活随笔為你收集整理的职工信息管理系统C++代码的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 谈自动化测试与CI中一些常见的谬见
- 下一篇: s3c2440移植MQTT