



版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡(jiǎn)介
1、/* 題目:學(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è)計(jì)李四曠課2修改某個(gè)學(xué)生的缺課記錄:可以對(duì)缺課紀(jì)
2、錄的任意部分進(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>#include <iostream>#include &l
3、t;vector>#include <stdexcept>#include <string>#include <iterator>#include <map>using namespace std;struct Student_infoint year,month,day,lesson1,lesson2;std:string course,name,type;std:istream& read(std:istream&);istream& Student_info:read(istream& in)in>
4、;>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 的記錄while(record.read(in)s.push_back(record);in
5、.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&&x.day=y.day)return x.lesson1<y.lesson1;else if
6、(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,int d1,int y2,int m2,int d2)/篩選符合輸入時(shí)間段的數(shù)據(jù)if (y1 = stud.year
7、&& 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 > m2)return 0;else if (y1 > stud.year | y2 < stud.year)ret
8、urn 0;elsereturn 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;vector<Student_info>:iterator ix,iter,itera;string name;/- 定義這些參數(shù)和迭代器必
9、須在SWITHC外 ,不然它可能被忽略跳過while(true)cout<<"*"<<endl;cout<<" * 1.請(qǐng)輸入你要修改缺課記錄的學(xué)生姓名*"<<endl;cout<<"*"<<endl;cout<<"*2.返回上一級(jí)菜單*"<<endl;cout<<"*"<<endl;cout<<" 請(qǐng)選擇菜單選項(xiàng)cin>>n;: "
10、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.end()ix2=s_name.find(name); /- 找到符合名字要求的數(shù)據(jù),并顯示出for(iter=(*ix2).second.begin();iter!=(*ix2).seco
11、nd.end();+iter)cout<<(*iter).year<<"-"<<(*iter).month<<"-"<<(*iter).day<<"t"cout<<(*iter).lesson1<<"-"<<(*iter).lesson2;cout<<"t"<<(*iter).course<<"t"<<(*iter).na
12、me<<"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;cout<<"*需要更改的項(xiàng)目*"<<endl;cout<<"*"<<endl;cout<<"
13、* 1 日期2 節(jié)次3 課程名稱4 姓名5 缺課類型6 返回上一級(jí)*"<<endl;cout<<"*"<<endl;cout<<"*"<<endl;cout<<" 請(qǐng)選擇要更改的項(xiàng)目號(hào): "cin>>m;switch(m)case 1:cout<<" 請(qǐng)輸入更改的日期(年月 日) : "cin>>(*itera).year>>(*itera).month>>(*itera).
14、day;break;case 2:cout<<" 請(qǐng)輸入更改的節(jié)次(L1、 L2) : "cin>>(*itera).lesson1>>(*itera).lesson2;break;case 3:cout<<" 請(qǐng)輸入要更改的課程名稱: "cin>>(*itera).course;break;case 4:cout<<" 請(qǐng)輸入要更改的學(xué)生姓名: "cin>>(*itera).name;break;case 5:cout<<" 請(qǐng)
15、輸入缺課類型: "cin>>(*itera).type;break;case 6:break;default:cout<<" 你的選擇錯(cuò)了,請(qǐng)看清楚!"<<endl;break;for(ix2=s_name.begin();ix2!=s_name.end();ix2+)/將改寫后的數(shù)據(jù)放入 vector 容器中for(iter=ix2->second.begin();iter!=ix2->second.end();iter+)s.push_back(*iter);elsecout<<" 沒有這個(gè)
16、學(xué)生的缺課記錄"<<endl;cout<<endl;break;else if(n=2)return ;elsecout<<" 你的選擇錯(cuò)了,請(qǐng)看清楚!"<<endl;elsecout<<" 記錄為空,沒有學(xué)生的缺課記錄!"<<endl;void Search_record(vector<Student_info>& s)/第三個(gè)模塊 - 查找某學(xué)生的缺課情況if(!is_empty(s)int i;vector<Student_info>:
17、iterator iter;map<string,vector<Student_info> >:iterator it1;map<string,vector<Student_info> > s_name;map<string, vector<Student_info> >:iterator itera;vector<Student_info>:iterator it;string name;while(true)cout<<"*"<<endl;cout<<
18、"*"<<endl;cout<<" * 1輸入你要查詢的學(xué)生姓名2 返回上一級(jí)*"<<endl;cout<<"*"<<endl;cout<<"*"<<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(i
19、tera=s_name.begin();itera!=s_name.end(); +itera)sort(itera->second.begin(),itera->second.end(),compare);cout<<" 請(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&
20、lt;<(*iter).year<<"-"<<(*iter).month<<"-"<<(*iter).day<<"t"cout<<(*iter).lesson1<<"-"<<(*iter).lesson2;cout<<"t"<<(*iter).course<<"t"<<(*iter).name<<"t&qu
21、ot;<<(*iter).type<<endl;elsecout<<" 沒有這個(gè)學(xué)生."<<endl;cout<<endl;else if(i=2)return ;elsecout<<" 對(duì)不起,沒有這個(gè)選項(xiàng)!"<<endl;elsecout<<" 沒有這個(gè)學(xué)生的缺課記錄"<<endl;struct Search_structstring name,course;int times;/ 定義另一個(gè)結(jié)構(gòu)模塊bool compare
22、2(Search_struct& x,Search_struct& y)/ 按照次數(shù)排序 ,次數(shù)相等的則按照名字排序if(x.times=y.times)return <;elsereturn 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>
23、:iterator itera;map<string,int>:iterator iter;vector<Search_struct> vec;int y1,m1,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()
24、;+it)if(time(*it,y1,m1,d1,y2,m2,d2)retit->name+=(it->lesson2-it->lesson1+1);for(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+)co
25、ut<<itera->name<<"t"<<itera->times<<endl;elsecout<<" 對(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>:i
26、terator itera;map<string,int>:iterator iter;vector<Search_struct> 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();
27、+it)/建立 map 容器if(time(*it,y1,m1,d1,y2,m2,d2)retit->course+=1;for(iter=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->
28、;course<<"t"<<itera->times<<endl;elsecout<<" 這段時(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<<"*"<<e
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫(kù)網(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ì)自己和他人造成任何形式的傷害或損失。
最新文檔
- 鄉(xiāng)鎮(zhèn)生活垃圾壓縮轉(zhuǎn)運(yùn)站建設(shè)項(xiàng)目可行性研究報(bào)告(編制大綱)
- 2024年VOC檢測(cè)行業(yè)發(fā)展運(yùn)行現(xiàn)狀及投資策略研究報(bào)告
- 某地鐵存量PPP項(xiàng)目可行性研究報(bào)告
- 中國(guó)直升機(jī)旅游行業(yè)發(fā)展?jié)摿︻A(yù)測(cè)及投資戰(zhàn)略研究報(bào)告
- 特種蠟行業(yè)深度研究報(bào)告
- 合同工程量漏項(xiàng)報(bào)告
- 中國(guó)蒸餾罐行業(yè)發(fā)展趨勢(shì)預(yù)測(cè)及投資戰(zhàn)略咨詢報(bào)告
- 2024年無錫市第八人民醫(yī)院招聘工作人員筆試真題
- 電商物流中的智能分揀技術(shù)應(yīng)用研究
- 保險(xiǎn)柜合同范本
- 小兒急性中毒的處理與急救
- 涂裝工技能鑒定考試題庫(kù)匯總-下(多選、判斷題部分)
- 非遺傳統(tǒng)文化課件
- 橋梁施工常見問題及預(yù)防控制要點(diǎn)(PPT,46)
- 中俄文一般貿(mào)易合同范本
- 知情同意書核查要點(diǎn)課件
- 廣東省深圳市2021-2022學(xué)年高二下學(xué)期期末考試 語(yǔ)文 Word版含解析
- 專項(xiàng)施工方案專家論證意見回復(fù)表
- 《醫(yī)古文》教學(xué)全套課件580頁(yè)
- 水電廠計(jì)算機(jī)監(jiān)控系統(tǒng)改造技術(shù)要求
- 勝利油田壓驅(qū)技術(shù)工藝研究進(jìn)展及下步工作方向
評(píng)論
0/150
提交評(píng)論