您好,登錄后才能下訂單哦!
這篇文章主要講解了“用C++實(shí)現(xiàn)高校人員信息管理系統(tǒng)”,文中的講解內(nèi)容簡(jiǎn)單清晰,易于學(xué)習(xí)與理解,下面請(qǐng)大家跟著小編的思路慢慢深入,一起來研究和學(xué)習(xí)“用C++實(shí)現(xiàn)高校人員信息管理系統(tǒng)”吧!
高校人員信息管理系統(tǒng)設(shè)計(jì),供大家參考,具體內(nèi)容如下
1、問題描述
某高校有四類員工:教師、實(shí)驗(yàn)員、行政人員,教師兼行政人員;共有的信息包括:編號(hào)、姓名、性別、年齡等。其中,教師還包含的信息有:所在系部、專業(yè)、職稱;實(shí)驗(yàn)員還包含的信息由:所在實(shí)驗(yàn)室、職務(wù);行政人員還包含的信息有:政治面貌、職稱等。
2、功能要求
(1)添加功能:程序能夠任意添加上述四類人員的記錄,可提供選擇界面供用戶選擇所要添加的人員類別,要求員工的編號(hào)要唯一,如果添加了重復(fù)編號(hào)的記錄時(shí),則提示數(shù)據(jù)添加重復(fù)并取消添加。
(2)查詢功能:可根據(jù)編號(hào)、姓名等信息對(duì)已添加的記錄進(jìn)行查詢,如果未找到,給出相應(yīng)的提示信息,如果找到,則顯示相應(yīng)的記錄信息。
(3)顯示功能:可顯示當(dāng)前系統(tǒng)中所有記錄,每條記錄占據(jù)一行。
(4)編輯功能:可根據(jù)查詢結(jié)果對(duì)相應(yīng)的記錄進(jìn)行修改,修改時(shí)注意編號(hào)的唯一性。
(5)刪除功能:主要實(shí)現(xiàn)對(duì)已添加的人員記錄進(jìn)行刪除。如果當(dāng)前系統(tǒng)中沒有相應(yīng)的人員記錄,則提示“記錄為空!”并返回操作;否則,輸入要?jiǎng)h除的人員的編號(hào)或姓名,根據(jù)所輸入的信息刪除該人員記錄,如果沒有找到該人員信息,則提示相應(yīng)的記錄不存。
(6)統(tǒng)計(jì)功能:能根據(jù)多種參數(shù)進(jìn)行人員的統(tǒng)計(jì)。能統(tǒng)計(jì)四類人員數(shù)量以及總數(shù),統(tǒng)計(jì)男、女員工的數(shù)量。
(7)保存功能:可將當(dāng)前系統(tǒng)中各類人員記錄存入文件中,存入方式任意。
(8)讀取功能:可將保存在文件中的人員信息讀入到當(dāng)前系統(tǒng)中,供用戶進(jìn)行使用。
二、代碼實(shí)現(xiàn) 帶有注釋
廢話不說,直接代碼,歡迎指正。
#include"iostream" #include <fstream> #include"stdlib.h" #define MAX 100 using namespace std; class person //定義一個(gè)類實(shí)現(xiàn)共有的基礎(chǔ)信息 { public: int num; char name[20]; char sex[4]; int age; }; //Teacher class class Teacher:virtual public person { public: char dept[20]; char special[20]; char title[20]; void Input() //錄入信息 { cout<<"Input num:";cin>>num; cout<<"Input name:";cin>>name; cout<<"Input sex:";cin>>sex; cout<<"Input age:";cin>>age; cout<<"Input dept:";cin>>dept; cout<<"Input special:";cin>>special; cout<<"Input title:";cin>>title; } void Output() //輸出信息 { cout<<"編號(hào): "<<num<<" "<<"姓名: "<<name<<" "<<"性別: "<<sex<<" "<<"年齡: "<<age<< " "<<"所在系: "<<dept<<" "<<"專業(yè): "<<special<<" "<<"職稱: "<<title<<endl; } }; Teacher Tea[MAX]; //定義一個(gè)教師的對(duì)象數(shù)組 static int Teatop; //定義一個(gè)靜態(tài)常量 class TeaManager //教師的管理類 { public: int Add(); int Search(); void Show(); void Edit(); int Delete(); void Save(); void Read(); }; int TeaManager::Add() //添加功能 { system("cls"); //清屏 Teacher t; int i,nu; if(Teatop==MAX) {cout<<"人數(shù)已滿"<<endl; return 0; } cout<<"請(qǐng)輸入編號(hào):";cin>>nu; for(i=0;i<Teatop;i++) { if(nu==Tea[i].num) {cout<<"已有該編號(hào)"<<endl; return 0; } } t.Input();Tea[Teatop]=t;Teatop++; cout<<"添加成功!"<<endl; return 1; } int TeaManager::Search() //查詢功能 { system("cls"); int j,n; cout<<"請(qǐng)輸入編號(hào):";cin>>n; for(j=0;j<Teatop;j++) { if(n==Tea[j].num) break; } if(j==Teatop) cout<<"沒有此人!"<<endl; else Tea[j].Output(); return 1; } void TeaManager::Show() //顯示功能 { system("cls"); int i; if(Teatop==0) {cout<<"記錄為空!"<<endl; return;} for(i=0;i<Teatop;i++) Tea[i].Output(); } void TeaManager::Edit() //編輯功能 { system("cls"); //清屏 Teacher t1; int j,n; cout<<"請(qǐng)輸入要編輯的人的編號(hào):";cin>>n; for(j=0;j<Teatop;j++) { if(n==Tea[j].num) break; } if(j==Teatop) {cout<<"沒有此人!"<<endl;return;}; cout<<"輸入修改后的信息,編號(hào)不能改:"<<endl; t1.Input(); Tea[j]=t1; cout<<"編輯成功!"<<endl; } int TeaManager::Delete() //刪除功能 { system("cls"); //清屏 int j,n; cout<<"請(qǐng)輸入要?jiǎng)h除的人的編號(hào):";cin>>n; for(j=0;j<Teatop;j++) { if(n==Tea[j].num) break; } if(j==Teatop) {cout<<"沒有此人!"<<endl;return 0;}; for(j;j<Teatop;j++) { Tea[j]=Tea[j+1]; } Teatop--; cout<<"刪除成功!"<<endl; return 1; } void TeaManager::Save() //保存功能 { system("cls"); //清屏 int i; ofstream outfile,outfile1; outfile1.open("Teatop.dat",ios::out); outfile1<<Teatop; outfile.open("Tea_data.dat",ios::binary); if(!outfile) {cerr<<"open error!"<<endl; return; } for(i=0;i<Teatop;i++) outfile.write((char *)&Tea[i],sizeof(Tea[i])); outfile.close(); cout<<"保存成功!"<<endl; } void TeaManager::Read() //讀取功能 { system("cls"); int i; ifstream infile,infile1; infile1.open("Teatop.dat",ios::in); infile1>>Teatop; infile.open("Tea_data.dat",ios::binary); if(!infile) {cerr<<"open error!"<<endl; return; } for(i=0;i<Teatop;i++) infile.read((char *)&Tea[i],sizeof(Tea[i])); infile.close(); cout<<"讀取成功!"<<endl; } void Tea_mune(TeaManager TM) //用一個(gè)管理教師的類來實(shí)現(xiàn)結(jié)果的顯示 { system("cls"); int b; char c; do{ cout<<endl;cout<<endl; cout<<"教師管理"<<endl; cout<<"=========================================================================================="<<endl; cout<<"| 1.添加 "; cout<<"2.查詢 "; cout<<"3.顯示 "; cout<<"4.編輯 "; cout<<"5.刪除 "; cout<<"6.統(tǒng)計(jì) "; cout<<"7.保存 "; cout<<"8.讀取 "; cout<<"0.退出 |"<<endl; cout<<"=========================================================================================="<<endl; cout<<"請(qǐng)選擇:";cin>>b; switch(b) { case 1:TM.Add();break; case 2:TM.Search();break; case 3:TM.Show();break; case 4:TM.Edit();break; case 5:TM.Delete();break; case 6:cout<<"共有教師人數(shù):"<<Teatop<<endl;break; //統(tǒng)計(jì)功能 case 7:TM.Save();break; case 8:TM.Read();break; default:cout<<"\n error"<<endl;break; case 0:break; } }while(b!=0); } class Tester:virtual public person //實(shí)驗(yàn)員 { public: char testroom[10]; char post[10]; void Input() { cout<<"Input num:";cin>>num; cout<<"Input name:";cin>>name; cout<<"Input sex:";cin>>sex; cout<<"Input age:";cin>>age; cout<<"Input testroom:";cin>>testroom; cout<<"Input post:";cin>>post; } void Output() { cout<<"編號(hào): "<<num<<" "<<"姓名: "<<name<<" "<<"性別: "<<sex<<" "<<"年齡: "<<age<< " "<<"所在實(shí)驗(yàn)室: "<<testroom<<" "<<"職務(wù): "<<post<<endl; } }; Tester Test[MAX]; static int Testop; class TestManager //管理實(shí)驗(yàn)員的類 { public: int Add(); int Search(); void Show(); void Edit(); int Delete(); void Save(); void Read(); }; int TestManager::Add() { system("cls"); Tester t; int i,nu; if(Testop==MAX) {cout<<"人數(shù)已滿"<<endl; return 0; } cout<<"請(qǐng)輸入編號(hào):";cin>>nu; for(i=0;i<Testop;i++) { if(nu==Test[i].num) {cout<<"已有該編號(hào)"<<endl; return 0; } } t.Input(); Test[Testop]=t; Testop++; cout<<"添加成功!"<<endl; return 1; } int TestManager::Search() { system("cls"); int j,n; cout<<"請(qǐng)輸入編號(hào):";cin>>n; for(j=0;j<Testop;j++) { if(n==Test[j].num) break; } if(j==Testop) cout<<"沒有此人!"<<endl; else Test[j].Output(); return 1; } void TestManager::Show() { system("cls"); int i; if(Testop==0) {cout<<"記錄為空!"<<endl; return;} for(i=0;i<Testop;i++) Test[i].Output(); } void TestManager::Edit() {system("cls"); Tester t1; int j,n; cout<<"請(qǐng)輸入要編輯的人的編號(hào):";cin>>n; for(j=0;j<Testop;j++) { if(n==Test[j].num) break; } if(j==Testop) {cout<<"沒有此人!"<<endl;return;}; cout<<"輸入修改后的信息,編號(hào)不能改:"<<endl; t1.Input(); Test[j]=t1; cout<<"編輯成功!"<<endl; } int TestManager::Delete() { system("cls"); int j,n; cout<<"請(qǐng)輸入要?jiǎng)h除的人的編號(hào):";cin>>n; for(j=0;j<Testop;j++) { if(n==Test[j].num) break; } if(j==Testop) {cout<<"沒有此人!"<<endl;return 0;}; for(j;j<Testop;j++) { Test[j]=Test[j+1]; } Testop--; cout<<"刪除成功!"<<endl; return 1; } void TestManager::Save() { system("cls"); int i; ofstream outfile,outfile1; outfile1.open("Testop.dat",ios::out); outfile1<<Testop; outfile.open("Test_data.dat",ios::binary); if(!outfile) {cerr<<"open error!"<<endl; return; } for(i=0;i<Testop;i++) outfile.write((char *)&Test[i],sizeof(Test[i])); outfile.close(); cout<<"保存成功!"<<endl; } void TestManager::Read() { system("cls"); int i; ifstream infile,infile1; infile1.open("Testop.dat",ios::in); infile1>>Testop; infile.open("Test_data.dat",ios::binary); if(!infile) {cerr<<"open error!"<<endl; return; } for(i=0;i<Testop;i++) infile.read((char *)&Test[i],sizeof(Test[i])); infile.close(); cout<<"讀取成功!"<<endl; } void Test_mune(TestManager TM) { system("cls"); int b; char c; do{ cout<<endl;cout<<endl; cout<<"實(shí)驗(yàn)人員管理"<<endl; cout<<"=========================================================================================="<<endl; cout<<"| 1.添加 "; cout<<"2.查詢 "; cout<<"3.顯示 "; cout<<"4.編輯 "; cout<<"5.刪除 "; cout<<"6.統(tǒng)計(jì) "; cout<<"7.保存 "; cout<<"8.讀取 "; cout<<"0.退出 |"<<endl; cout<<"=========================================================================================="<<endl; cout<<"請(qǐng)選擇:";cin>>b; switch(b) { case 1:TM.Add();break; case 2:TM.Search();break; case 3:TM.Show();break; case 4:TM.Edit();break; case 5:TM.Delete();break; case 6:cout<<"共有實(shí)驗(yàn)員人數(shù):"<<Testop<<endl;break; case 7:TM.Save();break; case 8:TM.Read();break; default:cout<<"\n error"<<endl;break; case 0:break; } }while(b!=0); } class Policer:virtual public person //行政人員 { public: char polices[10]; char post1[10]; void Input() { cout<<"Input num:";cin>>num; cout<<"Input name:";cin>>name; cout<<"Input sex:";cin>>sex; cout<<"Input age:";cin>>age; cout<<"Input polices:";cin>>polices; cout<<"Input post1:";cin>>post1; } void Output() { cout<<"編號(hào): "<<num<<" "<<"姓名: "<<name<<" "<<"性別: "<<sex<<" "<<"年齡: "<<age<< " "<<"政治面貌: "<<polices<<" "<<"職稱: "<<post1<<endl; } }; Policer Policers[MAX]; static int Policersop; class PolicerManager //管理行政人員的類 { public: int Add(); int Search(); void Show(); void Edit(); int Delete(); void Save(); void Read(); }; int PolicerManager::Add() { system("cls"); Policer t; int i,nu; if(Policersop==MAX) {cout<<"人數(shù)已滿"<<endl; return 0; } cout<<"請(qǐng)輸入編號(hào):";cin>>nu; for(i=0;i<Policersop;i++) { if(nu==Policers[i].num) {cout<<"已有該編號(hào)"<<endl; return 0; } } t.Input(); Policers[Policersop]=t; Policersop++; cout<<"添加成功!"<<endl; return 1; } int PolicerManager::Search() { system("cls"); int j,n; cout<<"請(qǐng)輸入編號(hào):";cin>>n; for(j=0;j<Policersop;j++) { if(n==Policers[j].num) break; } if(j==Policersop) cout<<"沒有此人!"<<endl; else Policers[j].Output(); return 1; } void PolicerManager::Show() { system("cls"); int i; if(Policersop==0) {cout<<"記錄為空!"<<endl; return;} for(i=0;i<Policersop;i++) Policers[i].Output(); } void PolicerManager::Edit() {system("cls"); Policer t1; int j,n; cout<<"請(qǐng)輸入要編輯的人的編號(hào):";cin>>n; for(j=0;j<Policersop;j++) { if(n==Policers[j].num) break; } if(j==Policersop) {cout<<"沒有此人!"<<endl;return;}; cout<<"輸入修改后的信息,編號(hào)不能改:"<<endl; t1.Input(); Policers[j]=t1; cout<<"編輯成功!"<<endl; } int PolicerManager::Delete() { system("cls"); int j,n; cout<<"請(qǐng)輸入要?jiǎng)h除的人的編號(hào):";cin>>n; for(j=0;j<Policersop;j++) { if(n==Policers[j].num) break; } if(j==Policersop) {cout<<"沒有此人!"<<endl;return 0;}; for(j;j<Policersop;j++) { Policers[j]=Policers[j+1]; } Policersop--; cout<<"刪除成功!"<<endl; return 1; } void PolicerManager::Save() { system("cls"); int i; ofstream outfile,outfile1; outfile1.open("Policersop.dat",ios::out); outfile1<<Policersop; outfile.open("Policers_data.dat",ios::binary); if(!outfile) {cerr<<"open error!"<<endl; return; } for(i=0;i<Policersop;i++) outfile.write((char *)&Policers[i],sizeof(Policers[i])); outfile.close(); cout<<"保存成功!"<<endl; } void PolicerManager::Read() { system("cls"); int i; ifstream infile,infile1; infile1.open("Policersop.dat",ios::in); infile1>>Policersop; infile.open("Policers_data.dat",ios::binary); if(!infile) {cerr<<"open error!"<<endl; return; } for(i=0;i<Policersop;i++) infile.read((char *)&Policers[i],sizeof(Policers[i])); infile.close(); cout<<"讀取成功!"<<endl; } void Policers_mune(PolicerManager TM) { system("cls"); int b; char c; do{ cout<<endl;cout<<endl; cout<<"行政人員管理"<<endl; cout<<"=========================================================================================="<<endl; cout<<"| 1.添加 "; cout<<"2.查詢 "; cout<<"3.顯示 "; cout<<"4.編輯 "; cout<<"5.刪除 "; cout<<"6.統(tǒng)計(jì) "; cout<<"7.保存 "; cout<<"8.讀取 "; cout<<"0.退出 |"<<endl; cout<<"=========================================================================================="<<endl; cout<<"請(qǐng)選擇:";cin>>b; switch(b) { case 1:TM.Add();break; //TM去調(diào)用add類 case 2:TM.Search();break; case 3:TM.Show();break; case 4:TM.Edit();break; case 5:TM.Delete();break; case 6:cout<<"共有行政員人數(shù):"<<Policersop<<endl;break; case 7:TM.Save();break; case 8:TM.Read();break; default:cout<<"\n error"<<endl;break; case 0:break; } }while(b!=0); } class Teapoli:virtual public person //教師兼行政 { public: void Input() //錄入信息 { cout<<"Input num:";cin>>num; cout<<"Input name:";cin>>name; cout<<"Input sex:";cin>>sex; cout<<"Input age:";cin>>age; } void Output() //輸出信息 { cout<<"編號(hào): "<<num<<" "<<"姓名: "<<name<<" "<<"性別: "<<sex<<" "<<"年齡: "<<age<<endl; } }; Teapoli Teap[MAX]; static int Teapolitop; class TeapoliManager //教師兼行政管理類 { public: int Add(); int Search(); void Show(); void Edit(); int Delete(); void Save(); void Read(); }; int TeapoliManager::Add() //添加功能 { system("cls"); //清屏 Teapoli t; int i,nu; if(Teapolitop==MAX) {cout<<"人數(shù)已滿"<<endl; return 0; } cout<<"請(qǐng)輸入編號(hào):";cin>>nu; for(i=0;i<Teapolitop;i++) { if(nu==Teap[i].num) {cout<<"已有該編號(hào)"<<endl; return 0; } } t.Input();Teap[Teapolitop]=t;Teapolitop++; cout<<"添加成功!"<<endl; return 1; } int TeapoliManager::Search() //查詢功能 { system("cls"); int j,n; cout<<"請(qǐng)輸入編號(hào):";cin>>n; for(j=0;j<Teapolitop;j++) { if(n==Teap[j].num) break; } if(j==Teapolitop) cout<<"沒有此人!"<<endl; else Teap[j].Output(); return 1; } void TeapoliManager::Show() //顯示功能 { system("cls"); int i; if(Teapolitop==0) {cout<<"記錄為空!"<<endl; return;} for(i=0;i<Teapolitop;i++) Teap[i].Output(); } void TeapoliManager::Edit() //編輯功能 { system("cls"); //清屏 Teapoli t1; int j,n; cout<<"請(qǐng)輸入要編輯的人的編號(hào):";cin>>n; for(j=0;j<Teapolitop;j++) { if(n==Teap[j].num) break; } if(j==Teapolitop) {cout<<"沒有此人!"<<endl;return;}; cout<<"輸入修改后的信息,編號(hào)不能改:"<<endl; t1.Input(); Teap[j]=t1; cout<<"編輯成功!"<<endl; } int TeapoliManager::Delete() //刪除功能 { system("cls"); //清屏 int j,n; cout<<"請(qǐng)輸入要?jiǎng)h除的人的編號(hào):";cin>>n; for(j=0;j<Teapolitop;j++) { if(n==Teap[j].num) break; } if(j==Teapolitop) {cout<<"沒有此人!"<<endl;return 0;}; for(j;j<Teapolitop;j++) { Teap[j]=Teap[j+1]; } Teapolitop--; cout<<"刪除成功!"<<endl; return 1; } void TeapoliManager::Save() //保存功能 { system("cls"); //清屏 int i; ofstream outfile,outfile1; outfile1.open("Teatop.dat",ios::out); outfile1<<Teapolitop; outfile.open("Tea_data.dat",ios::binary); if(!outfile) {cerr<<"open error!"<<endl; return; } for(i=0;i<Teapolitop;i++) outfile.write((char *)&Tea[i],sizeof(Tea[i])); outfile.close(); cout<<"保存成功!"<<endl; } void TeapoliManager::Read() //讀取功能 { system("cls"); int i; ifstream infile,infile1; infile1.open("Teatop.dat",ios::in); infile1>>Teapolitop; infile.open("Tea_data.dat",ios::binary); if(!infile) {cerr<<"open error!"<<endl; return; } for(i=0;i<Teapolitop;i++) infile.read((char *)&Teap[i],sizeof(Teapoli[i])); infile.close(); cout<<"讀取成功!"<<endl; } void Teapoli_mune(TeapoliManager TM) { system("cls"); int b; char c; do{ cout<<endl;cout<<endl; cout<<"教師兼行政管理"<<endl; cout<<"=========================================================================================="<<endl; cout<<"| 1.添加 "; cout<<"2.查詢 "; cout<<"3.顯示 "; cout<<"4.編輯 "; cout<<"5.刪除 "; cout<<"6.統(tǒng)計(jì) "; cout<<"7.保存 "; cout<<"8.讀取 "; cout<<"0.退出 |"<<endl; cout<<"=========================================================================================="<<endl; cout<<"請(qǐng)選擇:";cin>>b; switch(b) { case 1:TM.Add();break; case 2:TM.Search();break; case 3:TM.Show();break; case 4:TM.Edit();break; case 5:TM.Delete();break; case 6:cout<<"共有教師兼行政人數(shù):"<<Teapolitop<<endl;break; //統(tǒng)計(jì)功能 case 7:TM.Save();break; case 8:TM.Read();break; default:cout<<"\n error"<<endl;break; case 0:break; } }while(b!=0); } int main() //主函數(shù) { TeaManager Tmer1; TestManager Tetmer; PolicerManager Polimer; TeapoliManager Tp; int a=1,m=0; char c; cout<<" *************************************"; cout<<endl<<" $ 高校人員管理系統(tǒng) $"<<endl; cout<<" *************************************"; cout<<endl<<"請(qǐng)輸入密碼:";cin>>m; if(m!=666666) { cout<<"密碼錯(cuò)誤!"<<endl; c=getchar(); return 0; } while(a) {system("cls"); cout<<endl; cout<<" ****歡迎使用高校人員信息管理系統(tǒng)****"<<endl; cout<<" ================================="<<endl; cout<<" | 1.教師管理 |"<<endl; cout<<" | 2.實(shí)驗(yàn)員管理 |"<<endl; cout<<" | 3.行政員管理 |"<<endl; cout<<" | 4.教師兼行政管理 |"<<endl; cout<<" | 0.退出 |"<<endl; cout<<" ================================="<<endl; cout<<"請(qǐng)選擇:";cin>>a; switch(a) //用switch語句來判斷輸入的數(shù)字 { case 1:Tea_mune(Tmer1);break; case 2:Test_mune(Tetmer);break; case 3:Policers_mune(Polimer);break; case 4:Teapoli_mune(Tp);break; case 0:break; default:cout<<"\n error"<<endl; cout<<"按回車鍵繼續(xù)"<<endl; c=getchar(); break; } } system("cls"); cout<<endl<<"謝謝使用"<<endl; c=getchar(); return 0; }
感謝各位的閱讀,以上就是“用C++實(shí)現(xiàn)高校人員信息管理系統(tǒng)”的內(nèi)容了,經(jīng)過本文的學(xué)習(xí)后,相信大家對(duì)用C++實(shí)現(xiàn)高校人員信息管理系統(tǒng)這一問題有了更深刻的體會(huì),具體使用情況還需要大家實(shí)踐驗(yàn)證。這里是億速云,小編將為大家推送更多相關(guān)知識(shí)點(diǎn)的文章,歡迎關(guān)注!
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。