版權(quán)說(shuō)明:本文檔由用戶(hù)提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡(jiǎn)介
/*題目:學(xué)生考勤管理系統(tǒng)
考勤信息記錄了學(xué)生的缺課狀況,它包括:缺課日期、第幾節(jié)課【連續(xù)多節(jié)課用begin-end的
形式表示)、課程名稱(chēng)(課程名稱(chēng)中不會(huì)出現(xiàn)空格)、學(xué)生姓名、缺課類(lèi)型(遲到、早退、請(qǐng)
假及曠課)。試設(shè)計(jì)一考勤管理系統(tǒng),使之能供應(yīng)以下功能:
1.錄入學(xué)生的缺課記錄:從健盤(pán)輸入數(shù)據(jù)(提示:為避開(kāi)重復(fù)從鍵盤(pán)輸入數(shù)據(jù),測(cè)試時(shí)可
將數(shù)據(jù)存儲(chǔ)在文件中,利用輸入重定向功能讀入),輸入格式為:
缺課日期第幾節(jié)課課程名稱(chēng)學(xué)生姓名缺課類(lèi)型
每行一條紀(jì)錄。
例如:
2008-04-293-4C++程序設(shè)計(jì)試驗(yàn)張三遲到
2008-04-283-4C++程序設(shè)計(jì)李四曠課
2.修改某個(gè)學(xué)生的缺課記錄:可以對(duì)缺課紀(jì)錄的隨意部分進(jìn)行修改。
3.查詢(xún)某個(gè)學(xué)生的缺課狀況:查詢(xún)結(jié)果根據(jù)日期升序排序,同一天內(nèi)根據(jù)所缺課程的時(shí)間
升序排序。
4.統(tǒng)計(jì)某段時(shí)間內(nèi)(以天為單位),曠課學(xué)生姓名及曠課節(jié)數(shù),杳詢(xún)結(jié)果先按曠課節(jié)數(shù)降序
排序,曠課節(jié)數(shù)相同的學(xué)生按姓名升序排序:
5.統(tǒng)計(jì)某段時(shí)間內(nèi),有學(xué)生曠課的課程及曠課人次,按曠課人次由多到少排序,曠課人次
相同的課程按課程名稱(chēng)升序排序;
6.系統(tǒng)以菜單方式工作。
通過(guò)幾天的奮斗最終將這個(gè)設(shè)計(jì)做出來(lái)了,如下是該程序的具體過(guò)程*/
#include<algorithm>
#include<iomanip>
/include<iostream>
#indude<vector>
#include<stdexcept>
/include<string>
#indude<iterator>
#include<map>
usingnamespacestd;
structStudent_info{
intyear,month,day,lessonl,Iesson2;
std::stringcourse,name,type;
std::istream&read(std::istream&);
);
istream&Student_info::read(istream&in)
(
in?year?month?day?lessonl?lesson2?course?name?type;
returnin;
)
istream&read_record(istream&in,vector<Student_info>&s)〃第一個(gè)模塊--------輸入學(xué)生
的缺課記錄
(
Studentjnforecord;
s.clear();〃調(diào)用s.clear。來(lái)清空s的記錄
while(record.read(in))
(
s.push_back(record);
}
in.clear();〃將記錄的錯(cuò)誤狀態(tài)復(fù)原正確,以接著讀取記錄
returnin;
)
boolis_empty(vector<Student_nfo>&s)〃推斷輸入學(xué)生的記錄是否為空,為空則返回真
(
returns.emptyO;
)
boolcompare(Student_info&x,Student_info&y)〃根據(jù)時(shí)間排序,若日期相等則看課程時(shí)間
(
if(x.year==y.year&&x.month==y.month&&x.day==y.day){
returnx.lessonl<y.lessonl;
)
elseif(x.year==y.year&&x.month==y.month&&x.day!=y.day){
returnx.day<y.day;
)
elseif(x.year==y.year&&x.month!=y.month){
returnx.month<y.month;
)
else{
returnx.year<y.year;
)
}
〃篩選符合輸入時(shí)間
booltime(constStudent_info&studjntyl,intmljntdl,inty2,intm2zintd2)
段的數(shù)據(jù)
(
if({yl==stud.year&&stud.month==ml&&stud.day<dl)11(y2==stud.year&&
stud.month==m2&&stud.day>d2))
return0;
elseif((yl==stud.year&&stud.month<ml)11(y2==stud.year&&stud.month>m2))
return0;
elseif(yl>stud.year11y2<stud.year)
return0;
else
return1;
)
voidrewrite(vector<Student_info>&s)〃其次個(gè)模塊--------修改某個(gè)學(xué)生的缺課狀況
(
if(!is_empty(s))
(
intn,m,j,k;
map<string/vector<Student_info>>s_name;
map<string,vector<Student_info>>::iteratorix2;
vector<Student_info>::iteratorixjteoitera;
stringname;//--------------------定義這些參數(shù)和迭代器必需在SWITHC夕卜,不然它可能被
忽視跳過(guò)
while(true)
(
cout?"
*********************************************************”<<end卜
cout?"*1.請(qǐng)輸入你要修改缺課記錄的學(xué)生姓名*"?endl;
cout?"*
*"?endl;
cout?"*2.返回上一級(jí)菜單
*"?endl;
cout?"
**************尊**********,***毒******尊********************”<<end卜
cout<<“請(qǐng)選擇菜單選項(xiàng):
cin?n;
if(n==l)
(
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.fiid(name)!=s_name.end())
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).lessonl?"-"?(*iter).Iesson2;
cout?"\t"?(*iter).course?"\t"?(*iter).name?"\t"?(*iter;.type?endl;
)
itera=(xix2).second.begin();
cout<<,請(qǐng)輸入要更改記錄的序號(hào):
cin?j;
for(k=0;k!=j-l;++k)
(
++itera;
}
cout?'
**************************************************************************”<<en
dl;
cout?'*須要更改的項(xiàng)目
*"?endl;
cout?'*
*"?endl;
cout?'*1日期2節(jié)次3課程名稱(chēng)4姓名5缺課類(lèi)型6返回
上一級(jí)*"?endl;
cout?'*
*"?endl;
cout?'
*************—**********,****,*****,*****,*****,*************************”<<e口
dl;
cout<<,請(qǐng)選擇要更改的項(xiàng)目號(hào):“;
cin?m;
switch(m)
(
case1:
cout<<”請(qǐng)輸入更改的日期(年月日):”;
cin?(*itera).year?(*itera).month?(*itera).day;
break;
case2:
cout?"請(qǐng)輸入更改的節(jié)次(LI、L2):";
cin?(*itera).lessonl?(*itera).lesson2;
break;
case3:
cout<<”請(qǐng)輸入要更改的課程名稱(chēng):",
cin?(*itera).course;
break;
case4:
cout<<"請(qǐng)輸入要更改的學(xué)生姓名:",
cin?(*itera).name;
break;
case5:
cout<<”請(qǐng)輸入缺課類(lèi)型:”;
cin?(*itera).type;
break;
case6:
break;
default:
cout<<"你的選擇錯(cuò)了,請(qǐng)看清晰!"<<endl;
break;
}
for(ix2=s_name.begin();ix2!=s_name.end();ix2++)//^f改寫(xiě)后的數(shù)據(jù)放
入vector容器中
(
fo'(iter=ix2->second.begin();iter!-ix2->second.end();iter++)
(
s.push_back(*iter);
}
}
)
else
(
cout<<,沒(méi)有這個(gè)學(xué)生的缺課記錄"<<end;
cout?endl;
)
break;
)
elseif(n==2)
(
return;
)
else
cout<<"你的選擇錯(cuò)了,請(qǐng)看清晰!"<<endl;
)
)
else
cout<<"記錄為空,沒(méi)有學(xué)生的缺課記錄!"<<endl;
)
voidSearch_record(vector<Student_info>&s)〃第三個(gè)模塊--------查找某學(xué)生的缺課狀況
(
if(!is_empty(s))
(
inti;
vector<Student_info>::iteratoriter;
map<string,vector<Student_info>>::iteratoritl;
map<string,vector<Student_info>>s_name;
map<string,vector<Student_info>>::iteratoritera;
vector<Student_info>::iteratorit;
stringname;
while(true)
(
cout?"
**********************************************************“<<end卜
cout?"
*"?endl;
cout?"*1輸入你要查詢(xún)的學(xué)生姓名2返回上一級(jí)*"?endl;
cout?"
*"?endl;
cout?"
*****************************************************,*****<<end卜
cout<<"請(qǐng)選擇菜單:
cin?i;
if(i==l){
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)
(
sortfitera^second.beginOJtera^second.endO,compare);
)
cout<<”請(qǐng)輸入名字:";
cin?name;
cout?endl;
if(s_name.find(name)!=s_name.end())
(
itl=s_name.find(name);
for(iter=(*itl).second.begin();iter!=(*itl).second.end();++iter)
cout?(*iter).year?"-"?(*iter).month?"-"?(*iter).day?"\t";
cout?(*iter).lessonl?"-"?(*iter).lesson2;
cout?"\t"?(*iter).course?"\t"?(*iter).name?"\t"?(*iter;.type?endl;
}
)
else
(
coutcc'沒(méi)有這個(gè)學(xué)生."<<endl;
cout?endl;
)
}
elseif(i==2)
(
return;
)
else
cout<<"對(duì)不起,沒(méi)有這個(gè)選項(xiàng)l"?endl;
)
)
else
cout<<"沒(méi)有這個(gè)學(xué)生的缺課記錄"<<endl;
)
structSearch_struct{
stringname,course;
inttimes;
};〃定義另一個(gè)結(jié)構(gòu)模塊
boolcompare2(Search_struct&x,Search_struct&y)〃根據(jù)次數(shù)排序,次數(shù)相等的則根據(jù)名字排
序
(
if(x.times==y.times)
return<;
else
returnx.times>y.times;
)
voidSearch_s_t(vector<Student_info>&std)〃第四個(gè)模塊----------查找某段時(shí)間內(nèi)曠課學(xué)
生姓名及曠課節(jié)數(shù)
(
if(!is_empty(std))
(
vector<Student_info>::iteratorit;
vector<Search_struct>::iteratoritera;
map<string,int>::iteratoriter;
vector<Search_struct>vec;
intyl,ml,dl,y2,m2,d2;
map<string,int>ret;
cout<〈"請(qǐng)輸入你要查找的一個(gè)時(shí)間段(ylmldly2m2d2):"?endl;
cin?yl?ml?dl?y2?m2?d2;
for(it=std.begin();it!=std.end();++it)
(
if(time(*it,yl,ml.dl,y2,m2,d2))
(
ret[it->name]+=(it->lesson2-it->lessonl+l);
)
)
for(iter=ret.begin();iter!=ret.end();iter++)
(
Search_structtmp;
=iter->first;
tmp.times=iter->second;
vec.push_back(tmp);
)
sort(vec.begin(),vec.end(),compare2);
for(itera=vec.begin();i:era!=vec.end();itera++)
(
cout?itera->name?"\t"?itera->times?endl;
}
}
else
cout<<"對(duì)不起,沒(méi)有你要查找的記錄!"<<endl;
)
voidSearch_c_t(vector<Student_info>&std)〃第五個(gè)模塊---------查找某段時(shí)間內(nèi)曠課的課
程及曠課人次
(
if(!is_empty(std))
(
vector<Student_info>::iteratorit;
vector<Search_struct>::iteratoritera;
map<string,int>::iteratoriter;
vector<Search_struct>vec;
intyl,ml/dl,y2,m2,d2;
map<string,int>ret;
cout<<"請(qǐng)輸入你想要查找的時(shí)間段(ylmldly2m2d2):"?endl;
cin?yl?ml?dl?y2?m2?d2;
for(it=std.begin();it!=std.end();++it)〃建立map容器
(
if(time(*it,yl,ml.dl,y2,m2,d2))
(
ret[it->course]+=l;
)
)
for(iter=ret.begin();iter!=ret.end();iter++)
(
Search_structtmp;
tmp.course=iter->first;
tmp.times=iter->second;
vec.push_back(tmp);
)
sort(vec.begin(),vec.end(),compare2);
for(itera=vec.begin();i:era!=vec.end();itera++)
(
cout?itera->course?"\t"?itera->times?endl;
)
)
else
cout<<"這段時(shí)間內(nèi)沒(méi)有學(xué)生的缺課紀(jì)錄!“<<endl;
)
intmain()
{
vector<Student_info>stu;
intchoice;
while(true)
(
cout?"
*******本****************************尊****************,****京**“v<end卜
cout?"*學(xué)生考勤管理系統(tǒng)
*"?endl;
cout?H******掌*****************,***********************************
"?endl;
cout?"*1.錄入學(xué)生的缺課記錄
*"?endl;
cout?"*
*"?endl;
cout?H*2.修改某個(gè)學(xué)生的缺課記錄
*"?endl;
cout?"*
*"?endl;
cout?"*3.查找某學(xué)生的缺課狀況
*"?endl;
cout?"
溫馨提示
- 1. 本站所有資源如無(wú)特殊說(shuō)明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶(hù)所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒(méi)有圖紙預(yù)覽就沒(méi)有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫(kù)網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶(hù)上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶(hù)上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶(hù)因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。
最新文檔
- 無(wú)閥過(guò)濾器培訓(xùn)課件
- 無(wú)錫先導(dǎo)培訓(xùn)
- 籃球培訓(xùn)教學(xué)
- 錄制培訓(xùn)課件的新聞稿
- 智能縫紉機(jī):AI紡織革命
- 股票知識(shí)培訓(xùn)
- 智慧城市2026年信息安全管理記錄制度題目解析
- 人工智能:權(quán)威解讀
- 早餐店?duì)I銷(xiāo)話術(shù)
- 職業(yè)發(fā)展規(guī)劃書(shū)解析
- 二年級(jí)數(shù)學(xué)上冊(cè)100道口算題大全(每日一練共12份)
- 藥店物價(jià)收費(fèi)員管理制度
- 數(shù)據(jù)風(fēng)險(xiǎn)監(jiān)測(cè)管理辦法
- 國(guó)家開(kāi)放大學(xué)《公共政策概論》形考任務(wù)1-4答案
- 肝惡性腫瘤腹水護(hù)理
- 兒童語(yǔ)言發(fā)育遲緩課件
- 2025年河南省鄭州市中考一模英語(yǔ)試題及答案
- 《高等職業(yè)技術(shù)院校高鐵乘務(wù)專(zhuān)業(yè)英語(yǔ)教學(xué)課件》
- DB15T 3758-2024基本草原劃定調(diào)整技術(shù)規(guī)程
- 醫(yī)學(xué)類(lèi)單招入學(xué)考試題庫(kù)及答案(修正版)
- 腦機(jī)接口技術(shù)在疼痛管理中的應(yīng)用研究
評(píng)論
0/150
提交評(píng)論