<em>Mac</em>Book项目 2009年学校开始实施<em>Mac</em>Book项目,所有师生配备一本<em>Mac</em>Book,并同步更新了校园无线网络。学校每周进行电脑技术更新,每月发送技术支持资料,极大改变了教学及学习方式。因此2011
2021-06-01 09:32:01
本文範例為大家分享了C++實現學生資訊管理系統的具體程式碼,供大家參考,具體內容如下
實現功能
上面的功能基本完全實現
目前的程式其實還存在兩個問題:
1、無法從檔案中讀取資訊,我感覺是格式問題,輸出的格式需要改,但是這樣的話,儲存在檔案的資訊看起來就不是很方便了
2、儲存新同學的學號與當前記錄的學號相同時不會提醒,這個實現起來比較容易,在儲存的時候,再加一個連結串列查詢就可以了,是我太懶了。
原始碼附上
#include <cstdlib> #include <iostream> #include <string> #include<windows.h> #include<conio.h> #include <fstream> using namespace std; #define null NULL class student { private: int flag; friend class studentMessage; student *next; //節點指標 string name; //學生姓名 string address; //家庭住址 int age; //年齡 int id; //學號 string sex; char grade; 班級 // A 代表大學生 // B 代表中學生 // C 代表小學生 double chinese , math , english; //語文 , 數學 , 英語 double history , geography ; //歷史 , 地理 string major; long long int TL; // 專業 , 電話 public: static int num_total; //總數 static int num_sex; static int num_age; //小學生初始化 student(int _id,string _name,string _sex,int _age,char _grade,double _chinese,double _math,double _english) { name = _name; grade = _grade; age = _age; sex = _sex; id = _id; chinese = _chinese; math = _math; english = _english; next = NULL; } //初中生初始化 student(int _id,string _name,string _sex,int _age,char _grade,double _geography,double _history,string _address) { name = _name; grade = _grade; age = _age; sex = _sex; id = _id; geography = _geography; history = _history; address = _address; next = NULL; } //大學生初始化 student(int _id,string _name,string _sex,int _age,char _grade,string _major,string _address,long long int _TL) { name = _name; grade = _grade; age = _age; sex = _sex; id = _id; major = _major; address = _address; TL = _TL; next = NULL; } //建構函式 student() //為studentMessage初始化頭結點用 { name = "null"; sex = "null"; address = "null"; age = 0; id = 0; chinese = 0; math = 0; english = 0; grade = '0'; geography = 0; history = 0; major = "null"; TL = 0; next = NULL; } ~student(){} void swap(student*); }; int student::num_total = 0; 初始化 int student::num_sex = 0; int student::num_age = 0; void student::swap(student *q) { string _name,_sex,_address; int _age,_id; char grade; 班級 // A 代表大學生 // B 代表中學生 // C 代表小學生 double _chinese , _math , _english; //語文 , 數學 , 英語 double _history , _geography ; //歷史 , 地理 string _major; long long int _TL; // 專業 , 電話 _chinese = chinese; chinese = q->chinese; q->chinese = _chinese; _math = math; math = q->math; q->math = _math; _english = english; english = q->english; q->english = _english; _history = history; history = q->history; q->history = _history; _geography = geography; geography = q->geography; q->geography = _geography; _major = major; major = q->major; q->major = _major; _TL = TL; TL = q->TL; q->TL = _TL; _name = name; name = q->name; q->name = _name; _sex = sex; sex = q->sex; q->sex = _sex; _address = address; address = q->address; q->address = _address; _age = age; age = q->age; q->age = _age; _id = id; id = q->id; q->id = _id; } class studentMessage { private: student *first; //頭指標 int num; //資訊中的學生人數 public: studentMessage() { num = 0; //初始化學生人數為0 first = new student; //初始化頭結點 } ~studentMessage(){delete first;} /*管理系統常規操作*/ void Insret(void); //插入 void Display(void); //顯示 void Delete(void); //刪除 void Search(void); //搜尋 void Change(void); //改動 void SearchByid(void); //按照學號查詢 void SearchByname(void); //按照姓名查詢 int menu(void); //初始的選單 void clear(void); //清空列表 void tongji(void); //統計學生人數 void save(void); void read(void); }; int studentMessage::menu(void) { system("cls"); int ch; cout<<endl;cout<<endl;cout<<endl;cout<<endl; cout<<"**********************************************************************"<<endl; cout<<"======================================================================"<<endl; cout<<"***************************學生資訊管理系統***************************"<<endl;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<<" 0.退出系統"<<endl;cout<<endl; cout<<endl; cout<<"***********************************************************************"<<endl; cout<<"======================================================================="<<endl; cout<<"***********************************************************************"<<endl; cout<<endl;cout<<endl;cout<<endl;cout<<endl;cout<<endl;cout<<endl; cin >> ch; cout<<"nnn"<<endl; return ch; } void studentMessage::save(void) { system("cls"); fstream f("student.txt",ios::out); int i; if(!f) { cout<<endl;cout<<endl;cout<<endl; cout<<"檔案儲存失敗!!!!按任意鍵返回..."<<endl; if(i = getch()) return ; } if(student::num_total == 0) { f<<"當前記錄中無學生..."<<endl; } else { student *p = first->next; while(p != null) { f<<"學號:"<<p->id<<" "<<endl; f<<"姓名:"<<p->name<<endl; f<<"性別(boy/girl):"<<p->sex<<endl; f<<"年齡:"<<p->age<<endl; f<<"班級:"<<p->grade<<endl; if(p->grade == 'A') { f<<"專業:"<<p->major<<endl; f<<"家庭住址:"<<p->address<<endl; f<<"聯絡方式:"<<p->TL<<endl; } else if(p->grade == 'B') { f<<"地理成績:"<<p->geography<<endl; f<<"歷史成績:"<<p->history<<endl; f<<"家庭住址:"<<p->address<<endl; } else { f<<"語文成績:"<<p->chinese<<endl; f<<"數學成績:"<<p->math<<endl; f<<"英語成績:"<<p->english<<endl; } f<<"------------------------------------------------"<<endl; p = p->next; } } f.close(); cout<<endl;cout<<endl;cout<<endl; cout<<"學生資訊檔案已建立,按任意鍵繼續"<<endl; i = getch(); } void studentMessage::read(void) { system("cls"); string name; int age; int id; char grade; string sex,address; double chinese , math , english; //語文 , 數學 , 英語 double history , geography ; //歷史 , 地理 string major; long long int TL; // 專業 , 電話 int i; char ch; ifstream f("student.txt"); while(1) { f>>ch; if(f.eof()) { cout<<"檔案為空!按任意鍵返回"<<endl; if(i = getch()) return ; } f>>name; f>>sex; f>>age; f>>id; f>>grade; if(grade=='A') { f>>major; f>>address; f>>TL; } else if(grade == 'B') { f>>geography; f>>history; f>>address; } else { f>>chinese; f>>math; f>>english; } student::num_total ++; if(sex=="boy") student::num_sex++; if(age>=18) student::num_age ++; student *newstu = new student(); if(grade == 'A') newstu = new student(id,name,sex,age,grade,major,address,TL); else if(grade == 'B') newstu = new student(id,name,sex,age,grade,geography,history,address); else if(grade == 'C') newstu = new student(id,name,sex,age,grade,chinese,math,english); student *p = first; while(p->next != NULL) { p = p->next; } p->next = newstu; newstu->next = null; } } /統計 void studentMessage::tongji(void) { system("cls");// cout<<"學生人數一共為:" <<student::num_total<<endl; cout<<"男生一共有:"<<student::num_sex<<endl; cout<<"女生一共有:"<<student::num_total-student::num_sex<<endl; cout<<"成年人有:"<<student::num_age<<endl; int i; cout<<endl;cout<<endl;cout<<endl; cout<<"按任意鍵繼續"<<endl; i = getch(); } //插入 void studentMessage::Insret(void) { system("cls");// string name; int age; int id; char grade; string sex,address; double chinese , math , english; //語文 , 數學 , 英語 double history , geography ; //歷史 , 地理 string major; long long int TL; // 專業 , 電話 cout<<"請輸入學生姓名: "; cin>>name; cout<<"請輸入學生性別(boy/girl): "; cin>>sex; cout<<"請輸入學生年齡: "; cin>>age; cout<<"請輸入學生學號: "; cin>>id; cout<<"下面請輸入學生班級(大學生輸入'A',初中生輸入'B',小學生輸入'C'): "; cout<<endl; cin>>grade; cout<<endl; if(grade=='A') { cout<<"請輸入專業:"<<endl; cin>>major; cout<<"請輸入家庭住址:"<<endl; cin>>address; cout<<"請輸入聯絡電話:"<<endl; cin>>TL; } else if(grade == 'B') { cout<<"請輸入地理成績:"<<endl; cin>>geography; cout<<"請輸入歷史成績:"<<endl; cin>>history; cout<<"請輸入家庭住址:"<<endl; cin>>address; } else { cout<<"請輸入語文成績:"<<endl; cin>>chinese; cout<<"請輸入數學成成績:"<<endl; cin>>math; cout<<"請輸入英語成績:"<<endl; cin>>english; } student::num_total ++; if(sex=="boy") student::num_sex++; if(age>=18) student::num_age ++; student *newstu = new student(); if(grade == 'A') newstu = new student(id,name,sex,age,grade,major,address,TL); else if(grade == 'B') newstu = new student(id,name,sex,age,grade,geography,history,address); else if(grade == 'C') newstu = new student(id,name,sex,age,grade,chinese,math,english); student *p = first; while(p->next != NULL) { p = p->next; } p->next = newstu; newstu->next = null; } //00000000000000000000000/ void studentMessage::Display(void) { system("cls"); if(student::num_total == 0) { cout<<"當前記錄中無學生..."<<endl; } else { student *p = first->next; while(p != null) { cout<<"學號:"<<p->id<<" "<<endl; cout<<"姓名:"<<p->name<<endl; cout<<"性別(boy/girl):"<<p->sex<<endl; cout<<"年齡:"<<p->age<<endl; cout<<"班級:"<<p->grade<<endl; if(p->grade == 'A') { cout<<"專業:"<<p->major<<endl; cout<<"家庭住址:"<<p->address<<endl; cout<<"聯絡方式:"<<p->TL<<endl; } else if(p->grade == 'B') { cout<<"地理成績:"<<p->geography<<endl; cout<<"歷史成績:"<<p->history<<endl; cout<<"家庭住址:"<<p->address<<endl; } else { cout<<"語文成績:"<<p->chinese<<endl; cout<<"數學成績:"<<p->math<<endl; cout<<"英語成績:"<<p->english<<endl; } cout<<"------------------------------------------------"<<endl; p = p->next; } } int i; cout<<endl;cout<<endl;cout<<endl; cout<<"按任意鍵繼續"<<endl; i = getch(); } //刪除功能~~~~~~~~~~~~~~~~ void studentMessage::Delete(void) { string _name; system("cls"); cout<<"請輸入需要刪除的同學姓名:"<<endl; cin>>_name; int k=0; student *p = first; student *pre = first; while(p->next) { pre=p->next; if(pre->name == _name) { p->next=pre->next; k=1; delete pre; } p=p->next; } if(k==0&&p->name!=_name) cout<<"記錄為空!"<<endl; else { student::num_total--; if(p->sex=="boy") student::num_sex--; if(p->age>=18) student::num_age--; } int i; cout<<endl;cout<<endl;cout<<endl; cout<<"按任意鍵繼續"<<endl; i = getch(); } void studentMessage::Search(void) { system("cls");/ int temp = 0; cout<<"請輸入查詢的條件,有如下選項..."<<endl; cout<<"按照學號查詢(請輸入【1】) 按照姓名查詢(請輸入【2】) "<<endl; cout<<" 退出(請輸入【666】)"<<endl; cin>>temp; switch(temp) { case 1: SearchByid(); break; case 2: SearchByname(); break; case 666: return; default: cout<<"輸入有誤..."<<endl; } } void studentMessage::SearchByid(void) { system("cls");// int _id; int flag = 0; cout<<"請輸入待查詢學生的學號:"; cin >> _id; student *p = first->next; while(p != null) { if(p->id == _id) { flag = 1; cout<<"下面是查詢匹配結果:"<<endl; cout<<endl;cout<<endl;cout<<endl; cout<<"學號:"<<p->id<<" "<<endl; cout<<"姓名:"<<p->name<<endl; cout<<"性別(boy/girl):"<<p->sex<<endl; cout<<"年齡:"<<p->age<<endl; cout<<"班級:"<<p->grade<<endl; if(p->grade == 'A') { cout<<"專業:"<<p->major<<endl; cout<<"家庭住址:"<<p->address<<endl; cout<<"聯絡方式:"<<p->TL<<endl; } else if(p->grade == 'B') { cout<<"地理成績:"<<p->geography<<endl; cout<<"歷史成績:"<<p->history<<endl; cout<<"家庭住址:"<<p->address<<endl; } else { cout<<"語文成績:"<<p->chinese<<endl; cout<<"數學成績:"<<p->math<<endl; cout<<"英語成績:"<<p->english<<endl; } } p = p->next; } if(flag == 0) { cout<<"未找到匹配項..."<<endl; } int i; cout<<endl;cout<<endl;cout<<endl; cout<<"按任意鍵繼續"<<endl; i = getch(); } void studentMessage::SearchByname(void) { system("cls");/ string _name; int flag = 0; cout<<"請輸入待查詢的學生姓名: "; cin >> _name; student *p = first->next; while(p != null) { if(p->name == _name) { cout<<"下面是查詢匹配結果:"<<endl; cout<<endl;cout<<endl;cout<<endl; cout<<"學號:"<<p->id<<" "<<endl; cout<<"姓名:"<<p->name<<endl; cout<<"性別(boy/girl):"<<p->sex<<endl; cout<<"年齡:"<<p->age<<endl; cout<<"班級:"<<p->grade<<endl; if(p->grade == 'A') { cout<<"專業:"<<p->major<<endl; cout<<"家庭住址:"<<p->address<<endl; cout<<"聯絡方式:"<<p->TL<<endl; } else if(p->grade == 'B') { cout<<"地理成績:"<<p->geography<<endl; cout<<"歷史成績:"<<p->history<<endl; cout<<"家庭住址:"<<p->address<<endl; } else { cout<<"語文成績:"<<p->chinese<<endl; cout<<"數學成績:"<<p->math<<endl; cout<<"英語成績:"<<p->english<<endl; } } p = p->next; } if(flag == 0) { cout<<"未找到匹配項..."<<endl; } int i; cout<<endl;cout<<endl;cout<<endl; cout<<"按任意鍵繼續"<<endl; i = getch(); } void studentMessage::Change(void) { system("cls");// string _name,_sex,_address,_major; char _grade; long long int _TL; double _chinese , _math , _english; //語文 , 數學 , 英語 double _history , _geography ; //歷史 , 地理 int flag = 0,temp; int _id,_age; int course = 0; cout<<"請輸入需要改動資訊的學生的姓名: "; cin >> _name; student *p = first->next; while(p != null) { if(p->name == _name) { flag = 1; cout<<"該學生當前資訊如下:"<<endl; cout<<"學號:"<<p->id<<" "<<endl; cout<<"姓名:"<<p->name<<endl; cout<<"性別(boy/girl):"<<p->sex<<endl; cout<<"年齡:"<<p->age<<endl; cout<<"班級:"<<p->grade<<endl; if(p->grade == 'A') { cout<<"專業:"<<p->major<<endl; cout<<"家庭住址:"<<p->address<<endl; cout<<"聯絡方式:"<<p->TL<<endl; } else if(p->grade == 'B') { cout<<"地理成績:"<<p->geography<<endl; cout<<"歷史成績:"<<p->history<<endl; cout<<"家庭住址:"<<p->address<<endl; } else { cout<<"語文成績:"<<p->chinese<<endl; cout<<"數學成績:"<<p->math<<endl; cout<<"英語成績:"<<p->english<<endl; } cout<<"請指明哪一項需要修改..."<<endl; cout<<"修改學號(輸入【1】) 修改年齡(輸入【2】)修改班級資訊(輸入【3】) "<<endl; cout<<" 退出(輸入【666】)"<<endl; cin >> temp; switch(temp) { case 1: { cout<<"請輸入新的學號:"<<endl;cin>>_id; p->id = _id; } break; case 2: { cout<<"請輸入新的年齡:"<<endl;;cin>>_age; p->age = _age; } break; case 3: { cout<<"請輸入新的班級資訊(大學生輸入'A',初中生輸入'B',小學生輸入'C'):"<<endl;;cin>>_grade; p->grade = _grade; if(_grade=='A') { cout<<"請輸入專業:"<<endl; cin>>_major; p->major = _major; cout<<"請輸入家庭住址:"<<endl; cin>>_address; p->address = _address; cout<<"請輸入聯絡電話:"<<endl; cin>>_TL; p->TL = _TL; } else if(_grade == 'B') { cout<<"請輸入地理成績:"<<endl; cin>>_geography; p->geography = _geography; cout<<"請輸入歷史成績:"<<endl; cin>>_history; p->history = _history; cout<<"請輸入家庭住址:"<<endl; cin>>_address; p->address = _address; } else { cout<<"請輸入語文成績:"<<endl; cin>>_chinese; p->chinese = _chinese; cout<<"請輸入數學成成績:"<<endl; cin>>_math; p->major = _math; cout<<"請輸入英語成績:"<<endl; cin>>_english; p->english = _english; } } break; case 666: return ; cout<<"修改後的資訊如下: "<<endl; cout<<"姓名:"<<p->name<<" "<<endl; cout<<"性別:"<<p->sex<<" "<<endl; cout<<"年齡:"<<p->age<<" "<<endl; cout<<"學號:"<<p->id<<" "<<endl; cout<<"地址:"<<p->address<<" "<<endl; default: cout<<"輸入有誤..."<<endl; } } p = p->next; } if(flag == 0) cout<<"當前記錄中沒有此學生..."<<endl; } void studentMessage::clear(void) { student *p = first->next; while(p != null) { first->next = p->next; p->next = null; delete p; p = first->next; } } int main() { studentMessage stulist; int ch; while(ch = stulist.menu()) { switch(ch) { case 1: stulist.Insret(); break; case 2: stulist.Search(); break; case 3: stulist.Display(); break; case 4: stulist.Change(); break; case 5: stulist.Delete(); break; case 6: stulist.tongji(); break; case 7: stulist.save(); break; case 8: stulist.clear(); break; case 0: return 0; default: cout<<"請按要求輸入..."<<endl; } } return 0; }
以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支援it145.com。
相關文章
<em>Mac</em>Book项目 2009年学校开始实施<em>Mac</em>Book项目,所有师生配备一本<em>Mac</em>Book,并同步更新了校园无线网络。学校每周进行电脑技术更新,每月发送技术支持资料,极大改变了教学及学习方式。因此2011
2021-06-01 09:32:01
综合看Anker超能充系列的性价比很高,并且与不仅和iPhone12/苹果<em>Mac</em>Book很配,而且适合多设备充电需求的日常使用或差旅场景,不管是安卓还是Switch同样也能用得上它,希望这次分享能给准备购入充电器的小伙伴们有所
2021-06-01 09:31:42
除了L4WUDU与吴亦凡已经多次共事,成为了明面上的厂牌成员,吴亦凡还曾带领20XXCLUB全队参加2020年的一场音乐节,这也是20XXCLUB首次全员合照,王嗣尧Turbo、陈彦希Regi、<em>Mac</em> Ova Seas、林渝植等人全部出场。然而让
2021-06-01 09:31:34
目前应用IPFS的机构:1 谷歌<em>浏览器</em>支持IPFS分布式协议 2 万维网 (历史档案博物馆)数据库 3 火狐<em>浏览器</em>支持 IPFS分布式协议 4 EOS 等数字货币数据存储 5 美国国会图书馆,历史资料永久保存在 IPFS 6 加
2021-06-01 09:31:24
开拓者的车机是兼容苹果和<em>安卓</em>,虽然我不怎么用,但确实兼顾了我家人的很多需求:副驾的门板还配有解锁开关,有的时候老婆开车,下车的时候偶尔会忘记解锁,我在副驾驶可以自己开门:第二排设计很好,不仅配置了一个很大的
2021-06-01 09:30:48
不仅是<em>安卓</em>手机,苹果手机的降价力度也是前所未有了,iPhone12也“跳水价”了,发布价是6799元,如今已经跌至5308元,降价幅度超过1400元,最新定价确认了。iPhone12是苹果首款5G手机,同时也是全球首款5nm芯片的智能机,它
2021-06-01 09:30:45