C++:学生考勤系统

16 篇文章 1 订阅
#include<iostream> 
#include<cstring> 
#include<windows.h> 
using namespace std;  

//时间类 
class time 
{
public: 
  time(int y=0,int m=0,int d=0) 
  {
	  year=y;month=m;day=d;
  } 
  ~time(){}
protected: 
	int year,month,day; 
}; 
 
 //信息类 
 class xinxi:public time 
 { 
 public: 
	 xinxi(){ tiaoshu++;} 
	 ~xinxi(){tiaoshu--;} 
 void setname(char *n)
 {
	 strcpy(name,n);
 } 
 void settime(int y,int m,int d)
 {
	 year=y;month=m;day=d;
 } 
 void setqklx(char *qk)
 {
	 strcpy(queke,qk);
 } 
 void setjieci(char *jc)
 {
	 strcpy(jieci,jc);} 
 void setkechen(char *kc)
 {
	 strcpy(kechen,kc);
 } 
 char *getname()
 {
	 char *n;n=name;return n;
 } 
 char *getqklx()
 {
	 char *qk=queke;return qk;
 } 
 char *getjieci()
 {
	 char *jc;jc=jieci;return jc;
 } 
 char *getkechen()
 {
	 char *gk;gk=kechen;return gk;
 } 
 int *gettime(); 
 private: 
     char name[20];//姓名 
     char jieci[3],kechen[10],queke[10]; 
     int tm[3]; 
  static int tiaoshu; 
 }; 
   
 int xinxi::tiaoshu=0; 
 
 int *xinxi::gettime() 
 {   int *t; 
     t=tm; 
  tm[0]=year; 
  tm[1]=month; 
  tm[2]=day; 
  return t; 
 } 

 //缺课课程类 
 class qk:public xinxi 
 {public: 
    qk(){kcshu++;} 
   ~qk(){kcshu--;} 
   int getrc(xinxi st1[],int n,int j); 
   char qkn[20];	//公有数据成员 
 
 private: 
   int renci; 
   static int kcshu;	//静态数据成员 
}; 
  
 int qk::kcshu=0; 
   
 int qk::getrc(xinxi st1[],int n,int j) 
 {   renci=0; 
      renci++; 
    for(int i=0;i<n;i++) 
    if(*(st1[i+1].gettime()+1)==*(st1[j].gettime()+1)&&*(st1[i+1].gettime()+2)== 
  *(st1[j].gettime()+2)) 
 if(strcmp(qkn,st1[i].getkechen())==0) 
    renci++; 
   return renci; 
 } 
 
 //缺课学生类 
  class qs:public xinxi 
 {public: 
  qs(){qst++;} 
  ~qs(){qst--;} 
  void print(xinxi &st1); 
  int getjs(xinxi st1[],int n,int j); 
  int setjs(int js=0) 
  {jieshu=js;} 
  char qstn[20]; 
  private: 
    int jieshu;  
    static int qst; //静态数据成员 
}; 
 
  int qs::qst=0;  
   
  //类的实现 
   void qs::print(xinxi &st1) 
  {  
 cout<<"| 缺课日期 |"<<" 第几节课 |"<<" 课程名称 |"<<" 缺课类型|"<<endl; 
 cout<<"|"<<*st1.gettime()<<"|"<<*(st1.gettime()+1)<<*(st1.gettime()+2)
	 <<"|"<<st1.getjieci()<<"|" <<st1.getkechen()<<"|"<<st1.getqklx()<<"|"<<endl; 
  } 
   
  int qs::getjs(xinxi st1[],int n,int j) 
  {  int i=0,js=0; 
      xinxi min;    
   if(*(st1[j].getjieci()+2)!='\0') 
    js=+2; 
   else 
    js++; 
             
   for(i=0;i<n;i++) 
   
if(*(st1[i+1].gettime()+1)==*(st1[j].gettime()+1)&&*(st1[i+1].gettime()+2)==*(st1[j].gettime()+2)) 
         if(strcmp(st1[i+1].getname(),qstn)==0) 
   {   
   if(*(st1[i].getjieci()+2)!='\0') 
    js=+2; 
   else 
    js++; 
   } 
  
  jieshu=js; 
  return jieshu; 
  } 
  
   
 // 函数声明 
int shuru(xinxi st1[]); 
void chaxun(xinxi st1[],qs qt[]); 
void xiugai(xinxi st1[],int n); 
void tongji1(xinxi st1[],qs qt1[]); 
void tongji2(xinxi st1[],qk qk1[]); 
void caidan(); 
void xiansi(xinxi &st1); 
void setqstn(xinxi st1[],qs qt1[],int n); 
void setqkn(xinxi st1[],qk qk[],int n); 
  
//全局变量 
int g,k=1,b=1; 
int q=-1; 
char name[20],kechen[10],queke[10],jieci[3]; 
int y,m,d;   
    
//主函数 
int main() 
  {   xinxi tl[15];//定义15条信息类对象 
   qs qt[10]; 
   qk qk[6]; 
      int ch; 
  while(1) 
 {
	  cout<<"********欢迎进入学生考勤管理系统*********"<<endl; 
   caidan(); 
      cout<<"--------请选择菜单项:"<<endl; 
      cin>>ch; 
  switch(ch) 
  {case 1: g=shuru(tl); break; 
  case 2: xiugai(tl,g); break; 
  case 3: chaxun(tl,qt); break; 
  case 4: tongji1(tl,qt); break; 
  case 5: tongji2(tl,qk); break; 
  case 6: exit(0); 
  } 
 } 
  return 0; 
}     
    
   //菜单函数 
     void caidan() 
{ 
		 
cout<<"******************************************************"<<endl; 
cout<<"*               学生考勤管理系统                     *"<<endl; 
cout<<"******************************************************"<<endl; 
cout<<"*			1.录入学生的缺课记录					*"<<endl; 
cout<<"*			2.修改学生的缺课记录					*"<<endl; 
cout<<"*			3.查询学生的缺课情况					*"<<endl; 
cout<<"*			4.统计某段时间内旷课学生姓名及旷课节数	*"<<endl;  
cout<<"*			5.统计某段时间内旷课的课程及旷课人次	*"<<endl; 
cout<<"*			6.退出系统								*"<<endl; 
 } 
     
  //输入函数 
  int shuru(xinxi st1[]) 
	  { char a; 
  cout<<"------输入开始----"<<endl; 
  do{ q++; 
  cout<<"请输入学生姓名"<<endl; 
     cin>>name; 
  st1[q].setname(name); 
   cout<<"请输入课程名称"<<endl; 
  cin>>kechen; 
  st1[q].setkechen(kechen); 
  cout<<"请输入缺课日期"<<endl; 
  cin>>y>>m>>d; 
  st1[q].settime(y,m,d); 
  cout<<"请输入缺课类型"<<endl; 
     cin>>queke; 
  st1[q].setqklx(queke); 
  cout<<"请输入缺课节次"<<endl; 
  cin>>jieci; 
  st1[q].setjieci(jieci); 
  cout<<"是否还要继续输入:(y/n)"<<endl; 
  cin>>a; 
 }while(a=='y'); 
  return q+1; 
} 
     //修改函数 
  void xiugai(xinxi st1[],int n) 
  {    
      int k=1,j=0,a[10]; 
   int flgh; 
         int h; 
        while(k==1)    
  { cout<<"请输入你要修改缺课记录的学生姓名"<<endl; 
          cin>>name; 
    flgh=0; 
    for(int i=0;i<n;i++) 
    if(strcmp(name,st1[i].getname())==0) 
    do{ a[j]=i; 
     cout<<"1.修改日期2.修改节次3.修改课程名称4.修改缺课类型"<<endl; 
     cout<<"请输入要选择的数值(1,2,3,4)"<<endl; 
     int b; 
        cin>>b; 
        if(b==1) 
     { cout<<"请输入新日期"<<endl; 
     cin>>y>>m>>d; 
    st1[i].settime(y,m,d); 
	 } 
     else if(b==2) 
     {cout<<"请输入新节次"<<endl; 
                   cin>>jieci; 
      st1[i].setjieci(jieci); 
     } 
     else if(b==3) 
     {cout<<"请输入新课程名称"<<endl; 
      cin>>kechen; 
     st1[i].setkechen(kechen); 
     } 
              else if(b==4) 
     { cout<<"请输入新缺课类型"<<endl; 
     cin>>queke; 
     st1[i].setqklx(queke); 
     }  
     flgh=1;j++; 
   }while(b<1||b>4); 
    if(flgh==0) 
    {cout<<"没有你要找的学生姓名请重试要退出请按0"<<endl; 
                 cin>>k; 
    } 
     else 
     {cout<<"还要继续吗(1\0)退出请按0"<<endl; 
            cin>>k; 
     } 
   } 
            for(int i=0;i<j;i++) 
      {   h=a[i]; 
      xiansi(st1[h]); 
      } 
      } 
 
 
  // 查询函数 
 void chaxun(xinxi st1[],qs qt[]) 
{    
     char n='y'; 
  int u[10]; 
  while(n=='y') 
  {      int j=0; 
  cout<<"输入你要查询的学生姓名:"<<endl; 
         cin>>name;  
  int i=0; 
  for(;i<g;i++) 
     if(strcmp(name,st1[i].getname())==0) 
  {  u[j]=i; 
            j++; 
  } 
         if(j==0) 
   {   cout<<"没有你所要的学生名字!";//没有找到 
       cout<<"是否退出退出请按n\n"; 
    cin>>n; 
   } 
  for(int a=0;a<j;a++) 
  {   //只有一条信息 
   if(j<2) 
           { i=u[a]; 
             cout<<"| 缺课日期 |"<<" 第几节课 |"<<" 课程名称 |"<<" 缺课类型|"<<endl; 
             cout<<"| "<<*st1[i].gettime()<<"| "<<*(st1[i].gettime()+1)<<"|"<<*(st1[i].gettime()+2)<<"| "<<st1[i].getjieci()<<"| " 
             <<st1[i].getkechen()<<"| "<<st1[i].getqklx()<<"| "<<endl; 
   }       
         //两条信息以上排序 
                  else 
                { 
                 i=u[a]; 
           if(*(st1[i].gettime()+1)<*(st1[i+1].gettime()+1)) 
           qt[i].print(st1[i]); 
           else 
if(*(st1[i].gettime()+1)==*(st1[i+1].gettime()+1)&&*(st1[i].gettime()+2)<*(st1[i+1].gettime()+2)) 
                 qt[i].print(st1[i]); 
else 
if(*(st1[i].gettime()+1)==*(st1[i+1].gettime()+1)&&*(st1[i].gettime()+2)==*(st1[i+1].gettime()+2)) 
            if(strcmp(st1[i].getjieci(),st1[i+1].getjieci())==-1) 
            qt[i].print(st1[i]); 
     } 
              
                  cout<<"是否继续查询(y/n)继续请按y退出按n"<<endl; 
             cin>>n; 
  } 
 }    
}    
     //统计某段时间内旷课学生姓名及旷课节数 
  void tongji1(xinxi st1[],qs qt1[]) 
 {   int d1=0,js=0; 
  xinxi min; 
  if(g==0) 
	  cout<<"没有你要统计的学生信息请返回菜单录入学生缺课信息"<<endl; 
    else if(g==1) 
  { cout<<"姓名:"<<st1[0].getname()<<endl; 
           if(*(st1[0].getjieci()+2)!='\0') 
    js=+2; 
         else 
    js++; 
   cout<<"节数:"<<js<<endl; 
  }   
  else 
  //信息按时间排序 
 {int i=0; 
  for(;i<(g-1);i++) 
  {  
   if(*(st1[i].gettime()+1)<*(st1[i+1].gettime()+1)) 
   {min=st1[i];st1[i]=st1[i+1];st1[i+1]=st1[i];} 
   else 
if(*(st1[i].gettime()+1)==*(st1[i+1].gettime()+1)&&*(st1[i].gettime()+2)<*(st1[i+1].gettime()+2)) 
   {min=st1[i];st1[i]=st1[i+1];st1[i+1]=st1[i];}  
   else 
if(*(st1[i].gettime()+1)==*(st1[i+1].gettime()+1)&&*(st1[i].gettime()+2)==*(st1[i+1].gettime()+2)) 
   d1++; 
  } 
   
                   for(int j=0;j<(g-d1);j++) 
    { 
      cout<<*st1[j].gettime()<<*(st1[j].gettime()+1)<<*(st1[j].gettime()+2)<<endl; 
            for(i=0;i<k;i++) 
   { setqstn(st1,qt1,g); 
     cout<<"姓名:"<<qt1[i].qstn<<endl; 
      cout<<"节数:"<<qt1[i].getjs(st1,g,i)<<endl; 
   } 
    } 
  } 
          
 } 
  
      //统计某段时间内旷课的课程及旷课人次  
      void tongji2(xinxi st1[],qk qk1[]) 
 { int d1=0,rc=0; 
        xinxi min; 
        if(g==0) 
   cout<<"没有你要统计的学生信息请返回菜单录入学生缺课信息"<<endl; 
  else if(g==1) 
	    { cout<<"课程名:"<<st1[0].getkechen()<<endl; 
    rc++; 
          cout<<"人数:"<<rc<<endl; 
  }   
  else 
 { 
  int i=0; 
     for(;i<g;i++) 
  {  
   if(*(st1[i].gettime()+1)<*(st1[i+1].gettime()+1)) 
   {min=st1[i];st1[i]=st1[i+1];st1[i+1]=st1[i];} 
   else 
if(*(st1[i].gettime()+1)==*(st1[i+1].gettime()+1)&&*(st1[i].gettime()+2)<*(st1[i+1].gettime()+2)) 
   {min=st1[i];st1[i]=st1[i+1];st1[i+1]=st1[i];}  
   else 
if(*(st1[i].gettime()+1)==*(st1[i+1].gettime()+1)&&*(st1[i].gettime()+2)==*(st1[i+1].gettime()+2)) 
           d1++; 
   } 
    for(int j=0;j<(g-d1);j++) 
    { 
   cout<<*st1[j].gettime()<<*(st1[j].gettime()+1)<<*(st1[j].gettime()+2)<<endl; 
        for(i=0;i<b;i++) 
     { setqkn(st1,qk1,g); 
        cout<<"课程名:"<<qk1[i].qkn<<endl; 
        cout<<"人数:"<<qk1[i].getrc(st1,g,i)<<endl; 
     }  
    } 
  } 
         
} 
  
  //显示函数 
  void xiansi(xinxi &st1) 
{        cout<<"| 缺课日期 |"<<" 第几节课 |"<<" 课程名称 |"<<" 学生姓名|"<<" 缺课类型 |"<<endl; 
cout<<"|"<<*(st1.gettime())<<"|"<<*(st1.gettime()+1)<<*(st1.gettime()+2)<<"|"<<st1.getjieci()<<"|"<<st1.getkechen()<<"|"<<st1.getname()<<"|"<<st1.getqklx()<<"|"<<endl;   
} 
     
  //设置缺课学生名 
  void setqstn(xinxi st1[],qs qt1[],int n) 
 {  
     int i=0; 
     for(;i<n;i++) 
		  {if(i==0) 
       strcpy(qt1[0].qstn,st1[i].getname()); 
          else if(strcmp(st1[i].getname(),st1[i+1].getname())!=0) 
    {strcpy(qt1[i].qstn,st1[i].getname()); 
       k++; 
    } 
  } 
  } 
   
 //设置有缺课学生的课程名 
  void setqkn(xinxi st1[],qk qk[],int n) 
 {    
   int i=0; 
  for(;i<n;i++) 
  {      if(i==0) 
        strcpy(qk[0].qkn,st1[i].getkechen()); 
        else if(strcmp(st1[i].getkechen(),st1[i+1].getkechen())!=0) 
     {strcpy(qk[i].qkn,st1[i+1].getkechen()); 
           b++; 
     } 
  } 
 } 


评论 6
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值