#include<iostream>
#include<fstream>
#include<stdlib.h>
#include<string>
using namespace std;
const char *cha="D:\\wtm.txt";
struct Student{
int year,month,day,lesson1,lesson2;//日期(年,月,日),第几节课(始,终)
string course,name,type; //课程名,学生姓名,缺课类型
struct Student *next;
};
class Student_info
{
private:
Student* first;
public:
Student_info();
~Student_info();//虚构
Student *getfirst();
void add();//增加一个学生出勤信息
bool change(int,int,int);//修改一个学生出勤信息
void remove(string);//删除某学生的缺课记录
void search_student(string&);//查找某学生的缺课情况
void search_std_t(int,int,int);//查找某日旷课学生姓名及旷课人次
void search_kemu_t(int,int,int);//查找某日旷课的课程及旷课人次
void readfile(fstream &file,Student_info &data){
file.open(cha,ios::in);
while(!file.eof()){
Student *temp=new Student;
file>>temp->year>>temp->month>>temp->day>>temp->lesson1>>temp->lesson2>>temp->course>>temp->name>>temp->type;
if((temp->year)>0&&(temp->month)>0&&(temp->day)>0&&(temp->lesson1)>0&&(temp->lesson2)>(temp->lesson1)){
temp->next=first;
first=temp;
}
}
file.clear();
file.close();
}
};
Student_info::Student_info(){
first=NULL;
}
Student_info::~Student_info(){
Student *p;
while(p!=NULL){
p=first;
first=first->next;
delete p;
}
}
Student*Student_info::getfirst(){
return first;
}
void Student_info::add(){
Student *temp=new Student;
cout<<"请输入日期:";
cin>>temp->year>>temp->month>>temp->day;
cout<<"请输入始末节数:";
cin>>temp->lesson1>>temp->lesson2;
cout<<"请输入课程名称:";
cin>>temp->course;
cout<<"请输入学生姓名:";
cin>>temp->name;
cout<<"请输入缺课类型:";
cin>>temp->type;
temp->next=first;
first=temp;
}
bool Student_info::change(int i,int j,int k){
Student *temp=first;
while(temp!=NULL){
if((temp->year==i)&&(temp->month)==j&&(temp->day==k)){
int m;
cout<<" **************************************************************************"<<endl;
cout<<" * 需要更改的项目 *"<<endl;
cout<<" * *"<<endl;
cout<<" * 1 节次 2 课程名称 3 姓名 4 缺课类型 5 返回上一级 *"<<endl;
cout<<" * *"<<endl;
cout<<" **************************************************************************"<<endl;
cout<<"请选择要更改的项目号: ";
cin>>m;
switch(m)
{
case 1:
cout<<"请输入更改的节次(L1,L2):";
cin>>temp->lesson1>>temp->lesson2;
break;
case 2:
cout<<"请输入更改的课程名称:";
cin>>temp->course;
break;
case 3:
cout<<"请输入更改的姓名:";
cin>>temp->name;
break;
case 4:
cout<<"请输入更改的缺课类型:";
cin>>temp->type;
break;
case 5:
break;
}
cout<<temp->year<<"-"<<temp->month<<"-"<<temp->day<<" -"<<temp->lesson1<<"-"<<temp->lesson2<<" "<<temp->course<<" "<<temp->name<<" "<<temp->type;
return true;
}
temp=temp->next;
}
return false;
}
void Student_info::remove(string s){
Student *temp=NULL;
if(first->name==s){
temp=first;
first=first->next;
}
else{
for(Student *t=first;t->next;t=t->next){
temp=t->next;
t->next=temp->next;
break;
}
}
if(temp)
delete temp;
cout<<"删除成功!";
}
void Student_info::search_student(string &s){
int i=0;
for(Student *t=first;t->next;t=t->next){
if(t->name==s){
cout<<t->year<<"-"<<t->month<<"-"<<t->day<<" -"<<t->lesson1<<"-"<<t->lesson2<<" "<<t->course<<" "<<t->name<<" "<<t->type;
i++;
}
}
if(i==0)
cout<<"无该学生的记录!";
else
cout<<"一共有"<<i<<"条该学生的记录";
}
void Student_info::search_std_t(int i,int j,int k){
int count=0;
for(Student *t=first;t->next;t=t->next){
if((t->year)==i&&(t->month)==j&&(t->day)==k){
cout<<t->name;
count++;
}
}
if(count==0){
cout<<"该天无缺课记录!";
}
}
void Student_info::search_kemu_t(int i,int j,int k){
int count=0;
for(Student *t=first;t->next;t=t->next){
if((t->year)==i&&(t->month)==j&&(t->day)==k){
cout<<t->course;
count++;
}
}
if(count==0)
cout<<"该天无缺课记录!";
}
void writefile(fstream &file,Student_info&data)
{
file.open(cha,ios::out);
Student * temp=data.getfirst();
while(temp!=NULL)
{
file<<temp->year<<" "<<temp->month<<" "<<temp->day<<" "<<temp->lesson1<<" "<<temp->lesson2<<" "<<temp->course<<" "<<temp->name<<" "<<temp->type;
temp=temp->next;
cout<<"OK "<<endl;
}
file.clear();
file.close();
cout<<endl;
}
int main()
{
int choice;
fstream file;
Student_info system;
system.readfile(file,system);
cout<<" *************************************************************"<<endl;
cout<<" * 学生考勤管理系统 *"<<endl;
cout<<" ************************************************************ "<<endl;
cout<<" * 1. 录入学生的缺课记录 *"<<endl;
cout<<" * *"<<endl;
cout<<" * 2. 修改某个学生的缺课记录 *"<<endl;
cout<<" * *"<<endl;
cout<<" * 3. 删除某日的缺课记录 *"<<endl;
cout<<" * *"<<endl;
cout<<" * 4. 查找某个学生的缺课记录 *"<<endl;
cout<<" * *"<<endl;
cout<<" * 5. 查找某日旷课学生姓名及旷课人次 *"<<endl;
cout<<" * *"<<endl;
cout<<" * 6. 查找某日旷课的课程及旷课人次 *"<<endl;
cout<<" * *"<<endl;
cout<<" * 7. 退出系统 *"<<endl;
cout<<" *************************************************************"<<endl;
cout<<"请选择菜单选项: ";
while(choice!=0){
int i,j,k;
string s;
cin>>choice;
switch(choice){
case 1:
cout<<"请输入数据:"<<endl;
system.add();
writefile(file,system);
break;
case 2:
cout<<"请输入要修改的日期:";
cin>>i>>j>>k;
system.change(i,j,k);
cout<<endl;
break;
case 3:
cout<<"请输入学生姓名:";
cin>>s;
system.remove(s);
cout<<endl;
break;
case 4:
cout<<"请输入学生姓名:";
cin>>s;
system.search_student(s);
cout<<endl;
break;
case 5:
cout<<"请输入日期:";
cin>>i>>j>>k;
system.search_std_t(i,j,k);
cout<<endl;
break;
case 6:
cout<<"请输入日期:";
cin>>i>>j>>k;
system.search_kemu_t(i,j,k);
cout<<endl;
break;
case 7:
exit(0);
default:
cout<<"对不起,没有这个菜单项!"<<endl;
}
}
return 0;
}