




版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡(jiǎn)介
1、精選優(yōu)質(zhì)文檔-傾情為你奉上/*題目:學(xué)生考勤管理系統(tǒng) 考勤信息記錄了學(xué)生的缺課情況,它包括:缺課日期、第幾節(jié)課(連續(xù)多節(jié)課用 begin-end 的形式表示)、課程名稱(課程名稱中不會(huì)出現(xiàn)空格)、學(xué)生姓名、缺課類型(遲到、早退、請(qǐng)假及曠課)。試設(shè)計(jì)一考勤管理系統(tǒng),使之能提供以下功能: 1 錄入學(xué)生的缺課記錄:從鍵盤輸入數(shù)據(jù)(提示:為避免重復(fù)從鍵盤輸入數(shù)據(jù),測(cè)試時(shí)可將數(shù)據(jù)存儲(chǔ)在文件中,利用輸入重定向功能讀入),輸入格式為: 缺課日期 第幾節(jié)課 課程名稱 學(xué)生姓名 缺課類型 每行一條紀(jì)錄。 例如: 2008-04-29 3-4 C+程序設(shè)計(jì)實(shí)驗(yàn) 張三 遲到 2008-04-28 3-4 C+程序設(shè)
2、計(jì) 李四 曠課 2修改某個(gè)學(xué)生的缺課記錄:可以對(duì)缺課紀(jì)錄的任意部分進(jìn)行修改。 3查詢某個(gè)學(xué)生的缺課情況:查詢結(jié)果按照日期升序排序,同一天內(nèi)按照所缺課程的時(shí)間升序排序。 4統(tǒng)計(jì)某段時(shí)間內(nèi)(以天為單位),曠課學(xué)生姓名及曠課節(jié)數(shù),查詢結(jié)果先按曠課節(jié)數(shù)降序排序,曠課節(jié)數(shù)相同的學(xué)生按姓名升序排序; 5統(tǒng)計(jì)某段時(shí)間內(nèi),有學(xué)生曠課的課程及曠課人次,按曠課人次由多到少排序,曠課人次相同的課程按課程名稱升序排序; 6系統(tǒng)以菜單方式工作。 通過幾天的奮斗終于將這個(gè)設(shè)計(jì)做出來了,如下是該程序的詳細(xì)過程*/#include <algorithm> #include <iomanip> #inc
3、lude <iostream> #include <vector> #include <stdexcept> #include <string> #include <iterator> #include <map> using namespace std; struct Student_info int year,month,day,lesson1,lesson2; std:string course,name,type; std:istream& read(std:istream&); ; istream
4、& Student_info:read(istream& in) in>>year>>month>>day>>lesson1>>lesson2>>course>>name>>type; return in; istream& read_record(istream& in,vector<Student_info>& s)/第一個(gè)模塊-輸入學(xué)生的缺課記錄 Student_info record; s.clear();/調(diào)用s.clear()來清空s的
5、記錄 while(record.read(in) s.push_back(record); in.clear();/將記錄的錯(cuò)誤狀態(tài)恢復(fù)正確,以繼續(xù)讀取記錄 return in; bool is_empty(vector<Student_info>& s)/判斷輸入學(xué)生的記錄是否為空,為空則返回真 return s.empty(); bool compare(Student_info& x,Student_info& y)/按照時(shí)間排序,若日期相等則看課程時(shí)間 if(x.year=y.year&&x.month=y.month&&am
6、p;x.day=y.day) return x.lesson1<y.lesson1; else if(x.year=y.year&&x.month=y.month&&x.day!=y.day) return x.day<y.day; else if(x.year=y.year&&x.month!=y.month) return x.month<y.month; else return x.year<y.year; bool time(const Student_info& stud,int y1,int m1,in
7、t d1,int y2,int m2,int d2)/篩選符合輸入時(shí)間段的數(shù)據(jù) if (y1 = stud.year && stud.month = m1 && stud.day < d1) | (y2 = stud.year && stud.month = m2 && stud.day > d2) return 0; else if (y1 = stud.year && stud.month < m1) | (y2 = stud.year && stud.month > m
8、2) return 0; else if (y1 > stud.year | y2 < stud.year) return 0; else return 1; void rewrite(vector<Student_info>& s)/第二個(gè)模塊-修改某個(gè)學(xué)生的缺課情況 if(!is_empty(s) int n,m,j,k; map<string,vector<Student_info> > s_name; map<string,vector<Student_info> >:iterator ix2; vecto
9、r<Student_info>:iterator ix,iter,itera; string name;/-定義這些參數(shù)和迭代器必須在SWITHC外,不然它可能被忽略跳過 while(true) cout<<" *"<<endl; cout<<" * 1.請(qǐng)輸入你要修改缺課記錄的學(xué)生姓名 *"<<endl; cout<<" * *"<<endl; cout<<" * 2.返回上一級(jí)菜單 *"<<endl; c
10、out<<" *"<<endl; cout<<"請(qǐng)選擇菜單選項(xiàng): " cin>>n; if(n=1) s_name.clear();/-清空MAP容器 for(ix=s.begin();ix!=s.end();+ix) s_name(*ix).name.push_back(*ix); s.clear(); cout<<"請(qǐng)輸入該學(xué)生的姓名: " cin>>name; cout<<endl; if(s_name.find(name)!=s_name.en
11、d() ix2=s_name.find(name); /-找到符合名字要求的數(shù)據(jù),并顯示出 for(iter=(*ix2).second.begin();iter!=(*ix2).second.end();+iter) cout<<(*iter).year<<"-"<<(*iter).month<<"-"<<(*iter).day<<"t" cout<<(*iter).lesson1<<"-"<<(*iter
12、).lesson2; cout<<"t"<<(*iter).course<<"t"<<(*iter).name<<"t"<<(*iter).type<<endl; itera=(*ix2).second.begin(); cout<<"請(qǐng)輸入要更改記錄的序號(hào): " cin>>j; for(k=0;k!=j-1;+k) +itera; cout<<" *"<<endl
13、; cout<<" * 需要更改的項(xiàng)目 *"<<endl; cout<<" * *"<<endl; cout<<" * 1 日期 2 節(jié)次 3 課程名稱 4 姓名 5 缺課類型 6 返回上一級(jí) *"<<endl; cout<<" * *"<<endl; cout<<" *"<<endl; cout<<"請(qǐng)選擇要更改的項(xiàng)目號(hào): " cin>&
14、gt;m; switch(m) case 1: cout<<"請(qǐng)輸入更改的日期(年 月 日): " cin>>(*itera).year>>(*itera).month>>(*itera).day; break; case 2: cout<<"請(qǐng)輸入更改的節(jié)次(L1、L2): " cin>>(*itera).lesson1>>(*itera).lesson2; break; case 3: cout<<"請(qǐng)輸入要更改的課程名稱: " cin
15、>>(*itera).course; break; case 4: cout<<"請(qǐng)輸入要更改的學(xué)生姓名: " cin>>(*itera).name; break; case 5: cout<<"請(qǐng)輸入缺課類型: " cin>>(*itera).type; break; case 6: break; default: cout<<"你的選擇錯(cuò)了,請(qǐng)看清楚!"<<endl; break; for(ix2=s_name.begin();ix2!=s_nam
16、e.end();ix2+)/將改寫后的數(shù)據(jù)放入vector容器中 for(iter=ix2->second.begin();iter!=ix2->second.end();iter+) s.push_back(*iter); else cout<<"沒有這個(gè)學(xué)生的缺課記錄"<<endl; cout<<endl; break; else if(n=2) return ; else cout<<"你的選擇錯(cuò)了,請(qǐng)看清楚!"<<endl; else cout<<"記錄
17、為空,沒有學(xué)生的缺課記錄!"<<endl; void Search_record(vector<Student_info>& s)/第三個(gè)模塊-查找某學(xué)生的缺課情況 if(!is_empty(s) int i; vector<Student_info>:iterator iter; map<string,vector<Student_info> >:iterator it1; map<string,vector<Student_info> > s_name; map<string, ve
18、ctor<Student_info> >:iterator itera; vector<Student_info>:iterator it; string name; while(true) cout<<" *"<<endl; cout<<" * *"<<endl; cout<<" * 1 輸入你要查詢的學(xué)生姓名 2 返回上一級(jí) *"<<endl; cout<<" * *"<<endl; c
19、out<<" *"<<endl; cout<<"請(qǐng)選擇菜單: " cin>>i; if(i=1) s_name.clear(); for(it=s.begin();it!=s.end();+it) s_name(*it).name.push_back(*it); for(itera=s_name.begin();itera!=s_name.end(); +itera) sort(itera->second.begin(),itera->second.end(),compare); cout<
20、;<"請(qǐng)輸入名字: " cin>>name; cout<<endl; if(s_name.find(name)!=s_name.end() it1=s_name.find(name); for(iter=(*it1).second.begin();iter!=(*it1).second.end();+iter) cout<<(*iter).year<<"-"<<(*iter).month<<"-"<<(*iter).day<<&quo
21、t;t" cout<<(*iter).lesson1<<"-"<<(*iter).lesson2; cout<<"t"<<(*iter).course<<"t"<<(*iter).name<<"t"<<(*iter).type<<endl; else cout<<"沒有這個(gè)學(xué)生."<<endl; cout<<endl; else i
22、f(i=2) return ; else cout<<"對(duì)不起,沒有這個(gè)選項(xiàng)!"<<endl; else cout<<"沒有這個(gè)學(xué)生的缺課記錄"<<endl; struct Search_struct string name,course; int times; ;/定義另一個(gè)結(jié)構(gòu)模塊 bool compare2(Search_struct& x,Search_struct& y)/按照次數(shù)排序,次數(shù)相等的則按照名字排序 if(x.times=y.times) return &l
23、t;; else return x.times>y.times; void Search_s_t(vector<Student_info>& std)/第四個(gè)模塊-查找某段時(shí)間內(nèi)曠課學(xué)生姓名及曠課節(jié)數(shù) if(!is_empty(std) vector<Student_info>:iterator it; vector<Search_struct>:iterator itera; map<string,int>:iterator iter; vector<Search_struct> vec; int y1,m
24、1,d1,y2,m2,d2; map<string,int> ret; cout<<"請(qǐng)輸入你要查找的一個(gè)時(shí)間段(y1 m1 d1 y2 m2 d2): "<<endl; cin>>y1>>m1>>d1>>y2>>m2>>d2; for(it=std.begin();it!=std.end();+it) if(time(*it,y1,m1,d1,y2,m2,d2) retit->name+=(it->lesson2-it->lesson1+1); f
25、or(iter=ret.begin();iter!=ret.end();iter+) Search_struct tmp; =iter->first; tmp.times=iter->second; vec.push_back(tmp); sort(vec.begin(),vec.end(),compare2); for(itera=vec.begin();itera!=vec.end();itera+) cout<<itera->name<<"t"<<itera->times<<end
26、l; else cout<<"對(duì)不起,沒有你要查找的記錄!"<<endl; void Search_c_t(vector<Student_info>& std)/第五個(gè)模塊-查找某段時(shí)間內(nèi)曠課的課程及曠課人次 if(!is_empty(std) vector<Student_info>:iterator it; vector<Search_struct>:iterator itera; map<string,int>:iterator iter; vector<Search_struct&
27、gt; vec; int y1,m1,d1,y2,m2,d2; map<string,int> ret; cout<<"請(qǐng)輸入你想要查找的時(shí)間段(y1 m1 d1 y2 m2 d2): "<<endl; cin>>y1>>m1>>d1>>y2>>m2>>d2; for(it=std.begin();it!=std.end();+it)/建立map容器 if(time(*it,y1,m1,d1,y2,m2,d2) retit->course+=1; for(ite
28、r=ret.begin();iter!=ret.end();iter+) Search_struct tmp; tmp.course=iter->first; tmp.times=iter->second; vec.push_back(tmp); sort(vec.begin(),vec.end(),compare2); for(itera=vec.begin();itera!=vec.end();itera+) cout<<itera->course<<"t"<<itera->times<<endl;
29、 else cout<<"這段時(shí)間內(nèi)沒有學(xué)生的缺課紀(jì)錄!"<<endl; int main() vector<Student_info> stu; int choice; while(true) cout<<" *"<<endl; cout<<" * 學(xué)生考勤管理系統(tǒng) *"<<endl; cout<<" * "<<endl; cout<<" * 1. 錄入學(xué)生的缺課記錄 *"<<endl; cout<<" * *"<<endl; cout<<" * 2. 修改某個(gè)學(xué)生的缺課記錄 *&
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。
最新文檔
- 釩酸銨正極材料的電解液優(yōu)化及其儲(chǔ)鋅機(jī)理研究
- 基于深度學(xué)習(xí)的長(zhǎng)輸管道漏磁缺陷識(shí)別方法研究
- Liddle綜合征臨床診療策略與長(zhǎng)期隨訪研究及新致病突變的功能鑒定與動(dòng)物模型構(gòu)建
- 功能化農(nóng)林廢棄物對(duì)水中全氟辛酸的去除研究
- 幾種水泥合同范本
- 均衡問題與不動(dòng)點(diǎn)問題的鄰近型算法研究
- 2025年基因工程項(xiàng)目合作計(jì)劃書
- 六自由度機(jī)械臂軌跡規(guī)劃及多目標(biāo)抓取順序的研究
- 保濕潤唇膏修復(fù)干裂行業(yè)深度調(diào)研及發(fā)展戰(zhàn)略咨詢報(bào)告
- 醫(yī)學(xué)級(jí)卸妝油行業(yè)深度調(diào)研及發(fā)展戰(zhàn)略咨詢報(bào)告
- 第1課中華優(yōu)秀傳統(tǒng)文化的內(nèi)涵與特點(diǎn)課件(共28張PPT)
- 小學(xué)語文中高學(xué)段單元整體教學(xué)的實(shí)踐研究課題中期報(bào)告
- 耳鼻咽喉頭頸外科學(xué)-鼻科癥狀學(xué)課件
- 《幼小銜接存在的問題及對(duì)策研究(論文)6400字》
- 通信工程監(jiān)理方案
- 主題閱讀25:陜北的春
- 晉中項(xiàng)目投決會(huì)報(bào)告
- 2022年中小學(xué)心理健康教育指導(dǎo)綱要
- 公共關(guān)系文書(《公共關(guān)系學(xué)》課件)
- 2023屆高考復(fù)習(xí)之文學(xué)類文本閱讀訓(xùn)練
- 國家基礎(chǔ)教育實(shí)驗(yàn)中心外語教育研究中心
評(píng)論
0/150
提交評(píng)論