C++實(shí)現(xiàn)簡(jiǎn)單學(xué)生管理系統(tǒng)
本文實(shí)例為大家分享了C++實(shí)現(xiàn)簡(jiǎn)單學(xué)生管理系統(tǒng)的具體代碼,供大家參考,具體內(nèi)容如下
實(shí)現(xiàn)學(xué)生管理,其中關(guān)鍵字可以自行替換。經(jīng)過(guò)Visual C++6.0驗(yàn)證可執(zhí)行成功。
#include<iostream> #include"string" #include<fstream> #include <stdlib.h> #include <stdio.h> #define N 100 //N作為最大學(xué)生總數(shù) int f=0; //f作為開(kāi)關(guān) using namespace std; string p; //p作為接收菜單選項(xiàng)的字符串 void menu(); //顯示菜單 class student { public: ?student(){}? ?void show(); //學(xué)生信息顯示? ?~student(){} ?friend class StudentList; private: ?string num,name,dorm,uptown,address; ?int grade,distance; }; class StudentList { private: ?student w[N]; ?int NUM; //用來(lái)計(jì)算學(xué)生數(shù)目 ?int count; //用來(lái)暫時(shí)記錄當(dāng)前操作第幾個(gè)學(xué)生 public: ?void add(); //學(xué)生信息錄入 ?void sort(); //學(xué)生信息排序 ?void search(); //學(xué)生信息查找 ?void dele(); //學(xué)生信息刪除 ?void modify(); //學(xué)生信息修改 ?void save(); //學(xué)生信息以文件形式保存 ?void showstudent();//顯示學(xué)生信息在屏幕上 ?StudentList(){ ?NUM=0; ?count=0; ?} }; void menu() //顯示菜單 { ?cout<<endl; ?cout<<"***********************************************"<<endl; ?cout<<"** **"<<endl; ?cout<<"** 學(xué)生信息管理系統(tǒng)主菜單 **"<<endl; ?cout<<"** **"<<endl; ?cout<<"** 1.學(xué)生信息添加 **"<<endl; ?cout<<"** 2.學(xué)生信息修改 **"<<endl; ?cout<<"** 3.學(xué)生信息刪除 **"<<endl; ?cout<<"** 4.學(xué)生信息排序 **"<<endl; ?cout<<"** 5.學(xué)生信息查找 **"<<endl; ?cout<<"** 6.學(xué)生信息顯示 **"<<endl; ?cout<<"** 7.學(xué)生信息保存 **"<<endl; ?cout<<"** 0.退出 **"<<endl; ?cout<<"** **"<<endl; ?cout<<"***********************************************"<<endl; ?cout<<endl; } void domain() //主菜單函數(shù)實(shí)現(xiàn) { ? ?StudentList wl; ?while(1) ?{ ?system("cls"); ?menu(); ?cout<<"請(qǐng)選擇數(shù)字編號(hào)0~7"<<endl; ?int i1; ?cin>>i1; ?while(!(i1>=0&&i1<=7)) ?{ ?cout<<"輸入有誤,請(qǐng)重新輸入:"<<endl; ?cin>>i1; ?} ?switch(i1) ?{ ?case 1:wl.add();break; ?case 2:wl.modify();break; ?case 3:wl.dele();break; ?case 4:wl.sort();break; ?case 5:wl.search();break; ?case 6:wl.showstudent();break; ?case 7:wl.save();break; ?case 0:cout<<"系統(tǒng)退出?。?<<endl; ?exit(0); ?default: ?break; ?} ?cout<<"是否返回主菜單? Y/N"<<endl; ?cin>>p; ?if(p=="n"||p=="N") ?{? ?cout<<"系統(tǒng)退出?。?<<endl; ?exit(0); ?} ?} } void StudentList::add() //學(xué)生信息添加函數(shù)實(shí)現(xiàn) { ?cout<<"請(qǐng)輸入學(xué)生信息:"<<endl; ?cout<<"學(xué)號(hào):"; ?string num; ?cin>>num; ?for(int i=0;i<NUM;i++) ?while(num==w[i].num) ?{ ?cout<<"此學(xué)生編號(hào)已存在,請(qǐng)重新輸入:"<<endl; ?cout<<"學(xué)號(hào):"; ?cin>>num; ?} ?w[NUM].num=num; ?cout<<"姓名:";cin>>w[NUM].name; ?cout<<"宿舍:";cin>>w[NUM].dorm; ?cout<<"是否住宿:";cin>>w[NUM].uptown; ?cout<<"成績(jī):";cin>>w[NUM].grade; ?cout<<"距離:";cin>>w[NUM].distance; ?cout<<"家庭住址:";cin>>w[NUM].address; ?++NUM; ?count=NUM; } void student::show() //學(xué)生信息顯示函數(shù)實(shí)現(xiàn) { ?cout<<"學(xué)號(hào):"<<num<<endl; ?cout<<"姓名:"<<name<<endl; ?cout<<"宿舍:"<<dorm<<endl; ?cout<<"是否住宿:"<<uptown<<endl; ?cout<<"成績(jī):"<<grade<<endl; ?cout<<"距離:"<<distance<<endl; ?cout<<"家庭住址:"<<address<<endl; ?cout<<endl; } void StudentList::modify() //學(xué)生信息修改函數(shù)實(shí)現(xiàn) { ?if(NUM<=0) ?{ ?cout<<"沒(méi)有學(xué)生信息存入,系統(tǒng)將返回主菜單"<<endl; ?menu(); ?} ?cout<<"請(qǐng)輸入需要修改信息學(xué)生的學(xué)號(hào):"<<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<<"不存在此學(xué)生,請(qǐng)重新輸入:"<<endl; ?j=0; ?cin>>num1; ?} ?} ?cout<<"你選擇的學(xué)生的信息為:"<<endl; ?cout<<" 學(xué)號(hào):"<<w[k].num<<endl; ?cout<<" 姓名:"<<w[k].name<<endl; ?cout<<" 宿舍:"<<w[k].dorm<<endl; ?cout<<" 是否住宿:"<<w[k].uptown<<endl; ?cout<<" 成績(jī):"<<w[k].grade<<endl; ?cout<<" 距離:"<<w[k].distance<<endl; ?cout<<" 家庭住址:"<<w[k].address<<endl; ?cout<<endl; ?cout<<"***********************************************"<<endl; ?cout<<"** 1.修改學(xué)號(hào) **"<<endl; ?cout<<"** 2.修改姓名 **"<<endl; ?cout<<"** 3.修改宿舍 **"<<endl; ?cout<<"** 4.修改是否住宿 **"<<endl; ?cout<<"** 5.修改成績(jī) **"<<endl; ?cout<<"** 6.修改距離 **"<<endl; ?cout<<"** 7.修改家庭住址 **"<<endl; ?cout<<"** 0.返回主菜單 **"<<endl; ?cout<<"***********************************************"<<endl; ?cout<<endl; ?cout<<"請(qǐng)選擇數(shù)字編號(hào)0~8"<<endl; ?int i3; ?cin>>i3; ?while(i3<0||i3>8) ?{ ?cout<<"輸入有誤,請(qǐng)重新輸入:"<<endl; ?cin>>i3; ?} ?switch(i3) ?{ ?case 1: ?cout<<"請(qǐng)輸入新的學(xué)生學(xué)號(hào):"; ?cin>>w[k].num; ?cout<<"修改信息已保存,現(xiàn)返回主菜單:"<<endl; ?menu(); ?break; ?case 2: ?cout<<"請(qǐng)輸入新的學(xué)生姓名:"; ?cin>>w[k].name; ?cout<<"修改信息已保存,現(xiàn)返回主菜單:"<<endl; ?menu(); ?break; ?case 3: ?cout<<"請(qǐng)輸入新的學(xué)生宿舍:"; ?cin>>w[k].dorm; ?cout<<"修改信息已保存,現(xiàn)返回主菜單:"<<endl; ?menu(); ?break; ?case 4: ?cout<<"請(qǐng)輸入新的學(xué)生是否住宿:"; ?cin>>w[k].uptown; ?cout<<"修改信息已保存,現(xiàn)返回主菜單:"<<endl; ?menu(); ?break; ?case 5: ?cout<<"請(qǐng)輸入新的學(xué)生成績(jī):"; ?cin>>w[k].grade; ?cout<<"修改信息已保存,現(xiàn)返回主菜單:"<<endl; ?menu(); ?break; ?case 6: ?cout<<"請(qǐng)輸入新的學(xué)生距離:"; ?cin>>w[k].distance; ?cout<<"修改信息已保存,現(xiàn)返回主菜單:"<<endl; ?menu(); ?break; ?case 7: ?cout<<"請(qǐng)輸入新的學(xué)生家庭住址:"; ?cin>>w[k].address; ?cout<<"修改信息已保存,現(xiàn)返回主菜單:"<<endl; ?menu(); ?break; ?cout<<"修改信息已保存,現(xiàn)返回主菜單:"<<endl; ?menu(); ?break; ?case 0: ?menu(); ?default: ?break; ?} } void StudentList::showstudent() //學(xué)生信息顯示函數(shù)實(shí)現(xiàn) { ?if(NUM<=0) ?{ ?cout<<"沒(méi)有學(xué)生信息存入,系統(tǒng)將返回主菜單"<<endl; ?menu(); ?} ?else ?cout<<"已保存的學(xué)生信息如下:"<<endl; ?for(int i=0;i<count;i++) ?{ ?cout<<"***********************************************"<<endl; ?cout<<" 學(xué)號(hào):"<<w[i].num<<endl; ?cout<<" 姓名:"<<w[i].name<<endl; ?cout<<" 宿舍:"<<w[i].dorm<<endl; ?cout<<" 是否住宿:"<<w[i].uptown<<endl; ?cout<<" 成績(jī):"<<w[i].grade<<endl; ?cout<<" 距離:"<<w[i].distance<<endl; ?cout<<" 家庭住址:"<<w[i].address<<endl; ? ?cout<<"***********************************************"<<endl; ?} } void StudentList::search() //學(xué)生信息查詢(xún)函數(shù)實(shí)現(xiàn) { ?if(NUM<=0) ?{ ?cout<<"沒(méi)有學(xué)生信息存入,系統(tǒng)將返回主菜單"<<endl; ?menu(); ?} ?else ?cout<<"***********************************************"<<endl; ?cout<<"** 請(qǐng)選擇查找方式: **"<<endl; ?cout<<"** 1.按學(xué)號(hào)查找 **"<<endl; ?cout<<"** 2.按姓名查找 **"<<endl; ?cout<<"** 3.按是否住宿查找 **"<<endl; ?cout<<"** 0.返回主菜單 **"<<endl; ?cout<<"***********************************************"<<endl; ?cout<<endl; ?cout<<"請(qǐng)選擇數(shù)字編號(hào)0~3"<<endl; ?int i4; ?cin>>i4; ?while(i4<0||i4>3) ?{ ?cout<<"輸入有誤,請(qǐng)重新輸入:"<<endl; ?cin>>i4; ?} ?if(i4==1) ?{? ?string num2; ?cout<<"請(qǐng)輸入要查詢(xún)的學(xué)生的學(xué)號(hào):"<<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<<"查詢(xún)的學(xué)生信息如下:"<<endl; ?cout<<" 學(xué)號(hào):"<<w[k].num<<endl; ?cout<<" 姓名:"<<w[k].name<<endl; ?cout<<" 宿舍:"<<w[k].dorm<<endl; ?cout<<" 是否住宿:"<<w[k].uptown<<endl; ?cout<<" 成績(jī):"<<w[k].grade<<endl; ?cout<<" 距離:"<<w[k].distance<<endl; ?cout<<" 家庭住址:"<<w[k].address<<endl; ?break; ?} ?} ?if(flag) ?{ ?flag=0; ?cout<<"不存在此學(xué)生!!\n返回主菜單"<<endl; ?break; ?} ?} ?}? ?else if(i4==2) ?{ ?string name2; ?cout<<"請(qǐng)輸入要查詢(xún)的學(xué)生的姓名:"<<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<<"查詢(xún)的學(xué)生信息如下:"<<endl; ?cout<<" 學(xué)號(hào):"<<w[k2].num<<endl; ?cout<<" 姓名:"<<w[k2].name<<endl; ?cout<<" 宿舍:"<<w[k2].dorm<<endl; ?cout<<" 是否住宿:"<<w[k2].uptown<<endl; ?cout<<" 成績(jī):"<<w[k2].grade<<endl; ?cout<<" 距離:"<<w[k2].distance<<endl; ?cout<<" 家庭住址:"<<w[k2].address<<endl; ?break; ?} ?} ?if(flag2) ?{ ?flag2=0; ?cout<<"不存在此學(xué)生!!\n返回主菜單"<<endl; ?break; ?} ?} ? ?} ?else if(i4==3) ?{ ?string uptown2; ?cout<<"請(qǐng)輸入要查詢(xún)的學(xué)生的是否住宿:"<<endl; ?cin>>uptown2; ?int j4=0,k4; ?int flag4=1; ?while(flag4) ?{ ?for(;j4<count;j4++) ?{ ?if(uptown2==w[j4].uptown) ?{ ?flag4=0; ?k4=j4; ?cout<<"查詢(xún)的學(xué)生信息如下:"<<endl; ?cout<<" 學(xué)號(hào):"<<w[k4].num<<endl; ?cout<<" 姓名:"<<w[k4].name<<endl; ?cout<<" 宿舍:"<<w[k4].dorm<<endl; ?cout<<" 是否住宿:"<<w[k4].uptown<<endl; ?cout<<" 成績(jī):"<<w[k4].grade<<endl; ?cout<<" 距離:"<<w[k4].distance<<endl; ?cout<<" 家庭住址:"<<w[k4].address<<endl; ?break; ?} ?} ?if(flag4) ?{ ?flag4=0; ?cout<<"不存在此學(xué)生!!\n返回主菜單"<<endl; ?break; ?} ?} ? ?} ?else if(i4==0) ?menu(); } void StudentList::sort() //學(xué)生信息排序功能實(shí)現(xiàn) {? ?if(NUM<=0) ?{ ?cout<<"沒(méi)有學(xué)生信息存入,系統(tǒng)將返回主菜單"<<endl; ?menu(); ?} ?else ?cout<<"***********************************************"<<endl; ?cout<<"** 請(qǐng)選擇排序方式: **"<<endl; ?cout<<"** 1.按距離排序(升序) **"<<endl; ?cout<<"** 2.按距離排序(降序) **"<<endl; ?cout<<"** 0.返回主菜單 **"<<endl; ?cout<<"***********************************************"<<endl; ?cout<<endl; ?cout<<"請(qǐng)選擇數(shù)字編號(hào)0~2"<<endl; ?int i5; ?cin>>i5; ?while(i5<0||i5>2) ?{ ?cout<<"輸入有誤,請(qǐng)重新輸入:"<<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].distance>w[j+1].distance) ?{ ?student temp; ?temp=w[j]; ?w[j]=w[j+1]; ?w[j+1]=temp; ?} ?cout<<"按距離升序后的信息如下:"<<endl; ?for( i=0;i<count;i++) ?{ ?cout<<"***********************************************"<<endl; ?cout<<" 學(xué)號(hào):"<<w[i].num<<endl; ?cout<<" 姓名:"<<w[i].name<<endl; ?cout<<" 宿舍:"<<w[i].dorm<<endl; ?cout<<" 是否住宿:"<<w[i].uptown<<endl; ?cout<<" 成績(jī):"<<w[i].grade<<endl; ?cout<<" 距離:"<<w[i].distance<<endl; ?cout<<" 家庭住址:"<<w[i].address<<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].distance<w[j+1].distance) ?{ ?student temp; ?temp=w[j]; ?w[j]=w[j+1]; ?w[j+1]=temp; ?} ?cout<<"按距離降序后的信息如下:"<<endl; ?for( i=0;i<count;i++) ?{ ?cout<<"***********************************************"<<endl; ?cout<<" 學(xué)號(hào):"<<w[i].num<<endl; ?cout<<" 姓名:"<<w[i].name<<endl; ?cout<<" 宿舍:"<<w[i].dorm<<endl; ?cout<<" 是否住宿:"<<w[i].uptown<<endl; ?cout<<" 成績(jī):"<<w[i].grade<<endl; ?cout<<" 距離:"<<w[i].distance<<endl; ?cout<<" 家庭住址:"<<w[i].address<<endl; ?cout<<"***********************************************"<<endl; ?} ?} ?else if(i5==0) ?menu(); } void StudentList::dele() //學(xué)生信息刪除函數(shù)實(shí)現(xiàn) { ?if(NUM<=0) ?{ ?cout<<"沒(méi)有學(xué)生信息存入,系統(tǒng)將返回主菜單"<<endl; ?menu(); ?} ?cout<<"請(qǐng)輸入需要?jiǎng)h除信息學(xué)生的學(xué)號(hào):"<<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<<"不存在此學(xué)生,請(qǐng)重新輸入:"<<endl; ?j=0; ?cin>>num3; ?} ?} ?cout<<"你選擇的學(xué)生的信息為:"<<endl; ?cout<<" 學(xué)號(hào):"<<w[k].num<<endl; ?cout<<" 姓名:"<<w[k].name<<endl; ?cout<<" 宿舍:"<<w[k].dorm<<endl; ?cout<<" 是否住宿:"<<w[k].uptown<<endl; ?cout<<" 成績(jī):"<<w[k].grade<<endl; ?cout<<" 距離:"<<w[k].distance<<endl; ?cout<<" 家庭住址:"<<w[k].address<<endl; ?cout<<endl; ?cout<<"確認(rèn)刪除請(qǐng)輸入Y,返回主菜單請(qǐng)輸入N "<<endl; ?string p; ?cin>>p; ?while(1) ?{ ?if(p=="y"||p=="Y") ?{ ?cout<<"學(xué)生信息已刪除!"<<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<<"輸入有誤,請(qǐng)重新輸入:"; ?cin>>p; ?} ?} } void StudentList::save() //學(xué)生信息保存函數(shù)實(shí)現(xiàn) { ?if(NUM<=0) ?{ ?cout<<"沒(méi)有學(xué)生信息存入,系統(tǒng)將返回主菜單"<<endl; ?menu(); ?} ?else ?{ ?ofstream fout; ?fout.open("student.txt",ios::out); ?cout<<"文件正在保存......請(qǐng)稍候??!"<<endl; ?cout<<"數(shù)據(jù)保存成功!??!"<<endl; ?fout<<"已保存學(xué)生信息如下:"<<endl; ?for(int i=0;i<count;i++) ?{ ?fout<<"***********************************************"<<endl; ?fout<<" 學(xué)號(hào):"<<w[i].num<<endl; ?fout<<" 姓名:"<<w[i].name<<endl; ?fout<<" 宿舍:"<<w[i].dorm<<endl; ?fout<<" 是否住宿:"<<w[i].uptown<<endl; ?fout<<" 成績(jī):"<<w[i].grade<<endl; ?fout<<" 距離:"<<w[i].distance<<endl; ?fout<<" 家庭住址:"<<w[i].address<<endl; ?fout<<"***********************************************"<<endl; ?} ?cout<<"系統(tǒng)返回主菜單:"<<endl; ?menu(); ?fout.close(); ?}? } int main() {? ?domain();? ?return 0; }
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
- C++使用文件實(shí)現(xiàn)學(xué)生信息管理系統(tǒng)
- C++實(shí)現(xiàn)學(xué)生考勤信息管理系統(tǒng)
- C++實(shí)現(xiàn)學(xué)生信息管理系統(tǒng)
- linux下C/C++學(xué)生信息管理系統(tǒng)
- C++學(xué)生信息管理系統(tǒng)
- C++實(shí)現(xiàn)學(xué)生管理系統(tǒng)示例解析
- C++實(shí)現(xiàn)學(xué)生管理系統(tǒng)
- C++基礎(chǔ)學(xué)生管理系統(tǒng)
- C++實(shí)現(xiàn)簡(jiǎn)單的學(xué)生管理系統(tǒng)
- C++實(shí)現(xiàn)簡(jiǎn)單學(xué)生信息管理系統(tǒng)
相關(guān)文章
C++ 實(shí)現(xiàn)即時(shí)通信的示例代碼(直接運(yùn)行)
本文主要介紹了C++ 實(shí)現(xiàn)即時(shí)通信的示例代碼,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2022-05-05C++實(shí)現(xiàn)俄羅斯方塊(windows API)
這篇文章主要為大家詳細(xì)介紹了C++實(shí)現(xiàn)俄羅斯方塊,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2018-06-06C/C++字符串與數(shù)字互轉(zhuǎn)的實(shí)現(xiàn)
這篇文章主要介紹了C/C++字符串與數(shù)字互轉(zhuǎn)的實(shí)現(xiàn),文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2020-01-01C語(yǔ)言數(shù)據(jù)結(jié)構(gòu)中樹(shù)與森林專(zhuān)項(xiàng)詳解
這篇文章主要介紹了C語(yǔ)言數(shù)據(jù)結(jié)構(gòu)中樹(shù)與森林,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)吧2022-11-11Windows下ncnn環(huán)境配置教程詳解(VS2019)
這篇文章主要介紹了Windows下ncnn環(huán)境配置(VS2019),本文通過(guò)圖文并茂的形式給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2020-03-03