?? 學(xué)生考勤管理系統(tǒng).cpp
字號(hào):
// 學(xué)生考勤管理系統(tǒng).cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include "stdlib.h"
#include <string>
#include <iostream>
#include <iomanip>
#include <fstream>
using namespace std;
const int max=100;
class record
{
public:
void set(string d,int cno,string c,string s,int type)
{
date.assign(d);
cname.assign(c);
sname.assign(s);
this->cno=cno;
this->type=type;
}
void set(record re)
{
date.assign(re.date);
cname.assign(re.cname);
sname.assign(re.sname);
this->cno=re.cno;
this->type=re.type;
}
string tostr()
{
string s;
char tmp[3];
s.assign(date);
itoa(cno,tmp,10);
s.append("#");
s.append(tmp);
s.append("#");
s.append(cname);
s.append("#");
s.append(sname);
itoa(type,tmp,10);
s.append("#");
s.append(tmp);
return s;
}
string date,cname,sname;
int cno,type;
};
class records
{
public:
records()
{
r=new record[max];
n=0;
}
void order_s()
{
string *s=new string[n];
int *c=new int [n];
s[0].assign(r[0].sname);
c[0]=1;
int k=1,flag;
for(int i=1;i<n;i++)
{
flag=0;
for(int j=0;j<k;j++)
if(r[i].sname==s[j])
{
c[j]++;
flag=1;
break;
}
if(!flag)
{
s[k]=r[i].sname;
c[k++]=1;
}
}
for(i=1;i<k;i++)
for(int j=i;j>0;j--)
{
if(c[j]>c[j-1])
{
int tmp=c[j];
c[j]=c[j-1];
c[j-1]=tmp;
string stmp=s[j];
s[j]=s[j-1];
s[j-1]=stmp;
}
}
cout<<"曠課學(xué)生姓名\t曠課次數(shù)"<<endl;
for(i=0;i<k;i++)
cout<<s[i]<<"\t\t"<<c[i]<<endl;
}
void order_c()
{
string *s=new string[n];
int *c=new int [n];
s[0].assign(r[0].cname);
c[0]=1;
int k=1,flag;
for(int i=1;i<n;i++)
{
flag=0;
for(int j=0;j<k;j++)
if(r[i].cname==s[j])
{
c[j]++;
flag=1;
break;
}
if(!flag)
{
s[k]=r[i].cname;
c[k++]=1;
}
}
for(i=1;i<k;i++)
for(int j=i;j>0;j--)
{
if(c[j]>c[j-1])
{
int tmp=c[j];
c[j]=c[j-1];
c[j-1]=tmp;
string stmp=s[j];
s[j]=s[j-1];
s[j-1]=stmp;
}
}
cout<<"課程名\t曠課人次"<<endl;
for(i=0;i<k;i++)
cout<<s[i]<<"\t"<<c[i]<<endl;
}
record *r;
int n;
};
void wt(records *r)
{
ofstream outf("data.txt");
for(int i=0;i<r->n;i++)
outf<<r->r[i].tostr()<<endl;
outf<<"!"<<endl;
}
void rd(records *r)
{
ifstream inf("data.txt");
if(inf.eof())
{
cout<<"記錄為空!"<<endl;
return;
}
string t1,t3,t4;
char tmp[30];
int t2,t5;
r->n=0;
while(true)
{
inf.getline(tmp,10,'#');
if(tmp[0]=='!')break;
t1.assign(tmp);
inf.getline(tmp,3,'#');
t2=atoi(tmp);
inf.getline(tmp,30,'#');
t3.assign(tmp);
inf.getline(tmp,30,'#');
t4.assign(tmp);
inf.getline(tmp,3);
t5=atoi(tmp);
r->r[r->n++].set(t1,t2,t3,t4,t5);
}
}
bool timechk(string t1)
{
int year=atoi(t1.substr(0,2).c_str());
int month=atoi(t1.substr(2,2).c_str());
int day=atoi(t1.substr(4,2).c_str());
if(!(t1.length()==6&&year>0&&year<99&&month>0&&month<13&&day>0&&day<32))
{
cout<<"日期錄入有誤! 請(qǐng)重新錄入: "<<endl;
return false;
}
else return true;
}
void input(records *r)
{
string t1,t3,t4;
int t2,t5,flag=0;
char yn;
cout<<"錄入一條學(xué)生缺課記錄:"<<endl;
m1:
cout<<"請(qǐng)輸入缺課日期: (例如080612) "<<flush;
cin>>t1;
if(!(timechk(t1)))goto m1;
m2:
cout<<"請(qǐng)輸入缺第幾節(jié)課: "<<flush;
cin>>t2;
if(t2<1||t2>10)
{
cout<<"節(jié)次錄入有誤! 請(qǐng)重新錄入: "<<endl;
goto m2;
}
cout<<"請(qǐng)輸入缺課名稱: "<<flush;
cin>>t3;
cout<<"請(qǐng)輸入缺課學(xué)生姓名: "<<flush;
cin>>t4;
m3:
cout<<"請(qǐng)輸入缺課類型: (1.遲到 2.早退 3.請(qǐng)假 4.曠課) "<<flush;
cin>>t5;
if(t5<1||t5>4)
{
cout<<"類型輸入有誤! 請(qǐng)重新錄入: "<<endl;
goto m3;
}
for(int i=0;i<r->n;i++)
if(r->r[i].date==t1&&r->r[i].cno==t2&&r->r[i].cname==t3&&r->r[i].sname==t4&&r->r[i].type==t5)
{
cout<<"該條記錄已存在,是否添加為新記錄? (y/n) "<<flush;
n1:
cin>>yn;
if(yn=='y')break;
else if(yn=='n')goto n2;
else goto n1;
}
r->r[r->n++].set(t1,t2,t3,t4,t5);
n2:
cout<<"是否繼續(xù)輸入? (y/n) "<<flush;
n3:
cin>>yn;
if(yn=='y')goto m1;
else if(yn=='n')
{
cout<<"保存修改? (y/n) "<<flush;
cin>>yn;
if(yn=='y')wt(r);
else return;
}
else goto n3;
}
void prione(record r)
{
cout<<r.date<<"\t\t"
<<r.cno<<"\t"
<<r.cname<<"\t\t"
<<r.sname<<"\t\t"
<<flush;
switch(r.type)
{
case 1:cout<<"遲到"<<endl;break;
case 2:cout<<"早退"<<endl;break;
case 3:cout<<"請(qǐng)假"<<endl;break;
case 4:cout<<"曠課"<<endl;break;
default:;
}
}
void pri(records *r)
{
if(r->n==0)
{
cout<<"記錄為空!"<<endl;
return;
}
cout<<"\n序號(hào)\t缺課日期 節(jié)次\t課程名稱\t學(xué)生姓名\t缺課類型"<<endl;
for(int i=0;i<r->n;i++)
{
cout<<i<<"\t"<<flush;
prione(r->r[i]);
}
}
void edt(records *r)
{
if(r->n==0)
{
cout<<"記錄為空!"<<endl;
return;
}
cout<<"請(qǐng)輸入要修改缺課記錄的學(xué)生姓名: "<<flush;
string t1,t3,t4;
char tmp[30];
int t2,t5,flag=0;
cin>>tmp;
t1.assign(tmp);
for(int i=0;i<r->n;i++)
if(r->r[i].sname==t1)
{
flag=7;
break;
}
if(!flag)
{
cout<<"查無此學(xué)生!"<<endl;
return;
}
t1=r->r[i].date;
t2=r->r[i].cno;
t3=r->r[i].cname;
t4=r->r[i].sname;
t5=r->r[i].type;
cout<<"請(qǐng)輸入要修改的項(xiàng)目:\n(1.缺課日期 2.缺課節(jié)次 3.缺課名稱 4.學(xué)生姓名 5.缺課類型 6.全部) "<<flush;
e0:
cin>>flag;
switch(flag)
{
case 1:goto e1;
case 2:goto e2;
case 3:goto e3;
case 4:goto e4;
case 5:goto e5;
case 6:goto e1;
default:goto e0;
}
e1:
cout<<"請(qǐng)輸入缺課日期: (例如080612) "<<flush;
cin>>t1;
if(flag!=6)goto e6;
e2:
cout<<"請(qǐng)輸入缺第幾節(jié)課: "<<flush;
cin>>t2;
if(flag!=6)goto e6;
e3:
cout<<"請(qǐng)輸入缺課名稱: "<<flush;
cin>>t3;
if(flag!=6)goto e6;
e4:
cout<<"請(qǐng)輸入缺課學(xué)生姓名: "<<flush;
cin>>t4;
if(flag!=6)goto e6;
e5:
cout<<"請(qǐng)輸入缺課類型: (1.遲到 2.早退 3.請(qǐng)假 4.曠課) "<<flush;
cin>>t5;
e6:
r->r[i].set(t1,t2,t3,t4,t5);
char yn;
cout<<"保存修改? (y/n) "<<flush;
cin>>yn;
if(yn=='y')wt(r);
else return;
}
void del(records *r)
{
if(r->n==0)
{
cout<<"記錄為空!"<<endl;
return;
}
cout<<"請(qǐng)輸入要?jiǎng)h除的記錄的序號(hào): (輸入-1刪除全部) "<<flush;
int flag;
cin>>flag;
if(flag>r->n-1&&flag<-1)
{
cout<<"不存在所要?jiǎng)h除的記錄!"<<endl;
return;
}
else if(flag==-1)r->n=0;
else
{
for(int i=flag;i<r->n-1;i++)
r->r[i].set(r->r[i+1]);
r->n--;
}
char yn;
cout<<"保存修改? (y/n) "<<flush;
cin>>yn;
if(yn=='y')wt(r);
else return;
}
void search(records *r)
{
if(r->n==0)
{
cout<<"記錄為空!"<<endl;
return;
}
cout<<"請(qǐng)輸入要查詢的學(xué)生姓名: "<<flush;
string str;
int j=0,flag=0;
cin>>str;
for(int i=0;i<r->n;i++)
if(r->r[i].sname==str)
{
if(!flag)cout<<"\n序號(hào)\t缺課日期 節(jié)次\t課程名稱\t學(xué)生姓名\t缺課類型"<<endl;
cout<<j++<<"\t"<<flush;
prione(r->r[i]);
flag=1;
}
if(!flag)cout<<"沒有查到該學(xué)生的缺課記錄!"<<endl;
}
void search_s(records *r)
{
if(r->n==0)
{
cout<<"記錄為空!"<<endl;
return;
}
records *r1=new records();
g1:
cout<<"請(qǐng)輸入要檢索的時(shí)間范圍: (例如080610-080612) "<<flush;
string tmp,ld,hd;
cin>>tmp;
ld.assign(tmp.substr(0,6));
hd.assign(tmp.substr(7,6));
if(!timechk(ld)||!timechk(hd))goto g1;
for(int i=0;i<r->n;i++)
if(r->r[i].date.compare(ld)>=0&&r->r[i].date.compare(hd)<=0&&r->r[i].type==4)
r1->r[r1->n++].set(r->r[i]);
cout<<"請(qǐng)選擇統(tǒng)計(jì)方式: (1.學(xué)生曠課情況降序顯示 2.課程曠課情況降序顯示)"<<flush;
g2:
cin>>i;
switch(i)
{
case 1:
cout<<"\n在"<<ld<<"到"<<hd<<"期間學(xué)生曠課情況如下:"<<endl;
r1->order_s();
break;
case 2:
cout<<"\n在"<<ld<<"到"<<hd<<"期間課程曠課情況如下:"<<endl;
r1->order_c();
break;
default:goto g2;
}
}
void main()
{
c1:
cout<<"\t\t學(xué)生考勤管理系統(tǒng) V1.0.0"<<endl
<<endl
<<"功能列表:"<<endl
<<"1.顯示所有學(xué)生缺課記錄"<<endl
<<"2.錄入學(xué)生的缺課記錄"<<endl
<<"3.查詢某個(gè)學(xué)生的缺課情況"<<endl
<<"4.修改某個(gè)學(xué)生的缺課記錄"<<endl
<<"5.刪除某個(gè)學(xué)生的缺課記錄"<<endl
<<"6.某段時(shí)間內(nèi)曠課情況的統(tǒng)計(jì)"<<endl
<<"7.退出系統(tǒng)"<<endl
<<"請(qǐng)選擇: (1/2/3/4/5/6/7) "<<flush;
int cho;
c2:
cin>>cho;
if(cho==7)exit(0);
records *r=new records();
rd(r);
switch(cho)
{
case 1:pri(r);break;
case 2:input(r);break;
case 3:search(r);break;
case 4:edt(r);break;
case 5:del(r);break;
case 6:search_s(r);break;
default:goto c2;
}
cout<<"返回功能列表? (y/n) "<<flush;
char yn;
c3:
cin>>yn;
if(yn=='y')goto c1;
else if(yn=='n')exit(0);
else goto c3;
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -