上传代码

master
shine56 6 years ago
parent f31c8199c4
commit 6b82697da2

236
main.c

@ -22,6 +22,7 @@ int LEN = sizeof(struct AbRecord); //
void AddStu(Record *head); //录入学生缺课信息
void ChangeStu(Record *head); //修改学生缺课信息
void LookupStu(Record *head); //查找某个学生缺课记录
void DeleteStu(Record *head);
void CountStuRecord(Record suit[100], int m); //统计某段时间旷课的学生
void CountClassRecord(Record suit[100], int m); //统计某段时间有学生旷课的课程
void gotoxy(int x, int y); //设置光标
@ -29,7 +30,6 @@ void ShowRecord(Record *p); //
Record* Fread(); //将文件信息写进链表
void Fwrite(Record* head); //将链表写入文件
void SuitTime(Record *head, char ch); //符合条件时间段的记录
int main()
{
//创建相关文件
@ -47,14 +47,15 @@ int main()
printf("\t\t\t\t\t --------【1】录入缺课信息-----------\n\n");
printf("\t\t\t\t\t --------【2】修改缺课信息-----------\n\n");
printf("\t\t\t\t\t --------【3】查询缺课记录-----------\n\n");
printf("\t\t\t\t\t --------【4】学生缺课情况-----------\n\n");
printf("\t\t\t\t\t --------【5】课程缺课情况-----------\n\n");
printf("\t\t\t\t\t --------【4】删除缺课记录-----------\n\n");
printf("\t\t\t\t\t --------【5】学生缺课情况-----------\n\n");
printf("\t\t\t\t\t --------【6】课程缺课情况-----------\n\n");
printf("\t\t\t\t\t --------【0】退出系统----------------\n\n");
printf("\t\t\t\t\t■--------考--勤--管--理--系--统---------■\n\n\n");
printf("\t\t\t\t\t\t\t【 】");
//获取用户选择
gotoxy(_X+24, _Y+16);
gotoxy(_X+24, _Y+18);
fflush(stdin);
char ch = getch();
@ -73,16 +74,20 @@ int main()
LookupStu(head);
break;
case '4' :
SuitTime(head, ch);
DeleteStu(head);
break;
case '5':
SuitTime(head, ch);
break;
case '6':
SuitTime(head, ch);
break;
}
}
return 0;
}
void gotoxy(int x, int y) //设置光标
//设置光标
void gotoxy(int x, int y)
{
HANDLE handle = GetStdHandle(STD_OUTPUT_HANDLE);
COORD pos;
@ -90,6 +95,51 @@ void gotoxy(int x, int y) //
pos.Y = y;
SetConsoleCursorPosition(handle, pos);
}
//将文件数据写入链表
Record* Fread()
{
Record *head =NULL, *last, *p;
FILE *fa;
if((fa = fopen("record.txt", "r")) == NULL)
printf("创建文件失败");
while(!feof(fa))
{
if((p = (Record*)malloc(LEN)) == NULL)
printf("申请内存出错!");
if(fread(p, LEN, 1, fa) == 1)
{
if(head == NULL)
{
head = p;
last = p;
}
else{
last->next = p;
last = p;
last->next = NULL;
}
}
}
fclose(fa);
return head;
}
//数据存盘
void Fwrite(Record* head)
{
Record *p;
FILE *fb;
if((fb = fopen("record.txt", "w")) == NULL)
printf("创建文件失败");
for(p=head; p; p=p->next)
{
if(fwrite(p, LEN, 1, fb) != 1)
printf("写入文件错误!");
}
fclose(fb);
}
//录入学生缺课记录
void AddStu(Record *head)
{
@ -112,14 +162,40 @@ void AddStu(Record *head)
printf("\n\n\t\t\t\t 【 】");
printf("\n\n\t\t\t\t【0】取消录入返回菜单 【其他键】确认录入");
//输入缺课信息
//************************************输入缺课信息***************************
Record *p = (Record*)malloc(LEN), *q = head; //增加一个新节点
gotoxy(_X+7, _Y-1); scanf("%s", p->StuName);
gotoxy(_X+7, _Y+2); scanf("%d", &p->Y);
gotoxy(_X+16, _Y+2); scanf("%d", &p->M);
gotoxy(_X+24, _Y+2); scanf("%d", &p->D);
gotoxy(_X+7, _Y+5); scanf("%s", p->LNum);
gotoxy(_X+7, _Y+8); scanf("%s", p->LName);
gotoxy(_X+7, _Y-1); scanf("%s", p->StuName); //姓名
gotoxy(_X+7, _Y+2); scanf("%d", &p->Y); //年
while(1)
{
gotoxy(_X+16, _Y+2); scanf("%d", &p->M); //月
if(p->M>0 && p->M<13)
{
printf("\t\t\t\t\t\t\t\t\t\t\t ");
break;
}
else{
printf("\t\t\t\t\t\t\t\t\t\t\t月份输入有误!");
gotoxy(_X+16, _Y+2); printf(" ");
}
}
while(1)
{
gotoxy(_X+24, _Y+2); scanf("%d", &p->D); //日
if(p->D>0 && p->D<32)
{
printf("\t\t\t\t\t\t\t\t\t\t\t ");
break;
}
else
{
printf("\t\t\t\t\t\t\t\t\t\t\t日份输入有误!");
gotoxy(_X+24, _Y+2); printf(" ");
}
}
gotoxy(_X+7, _Y+5); scanf("%s", p->LNum); //课程节次
gotoxy(_X+7, _Y+8); scanf("%s", p->LName); //课程名称
while(1)
{
gotoxy(_X+14, _Y+11); char typee = getch(); //选择缺课类型
@ -153,7 +229,7 @@ void AddStu(Record *head)
printf("\n\t\t\t\t信息录入成功........【1】继续录入信息 任意键返回菜单");
gotoxy(_X+18, _Y+16); ch1 = getch();
}
if(ch1 != '1')
if(ch1 != '1') //确认是否继续循环
return;
}
}
@ -196,7 +272,8 @@ void ChangeStu(Record *head)
printf("\n\n\t【1】学生姓名 【2】缺课日期 【3】缺课节次 【4】科目名称 【5】缺课类型 【0】返回菜单");
gotoxy(_X+18, _Y+13); char ch = getch(); //选择修改的项目
gotoxy(_X+18, _Y+13); printf("%c", ch);
//输入修改的信息
//*********************输入修改的信息*********************
switch(ch)
{
@ -248,8 +325,8 @@ void ChangeStu(Record *head)
}
}
}
else{
printf("该学生有%d条缺课记录", num);
else{ //无该学生的记录
printf("\n\t\t\t\t\t该学生有%d条缺课记录", num);
printf("\n\n\t\t\t\t【任意键】并返回菜单........ ");
getch();
}
@ -284,51 +361,6 @@ void ShowRecord(Record *p)
printf("\n\t\t\t\t\t  ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄");
return;
}
//将文件数据写入链表
Record* Fread()
{
Record *head =NULL, *last, *p;
FILE *fa;
if((fa = fopen("record.txt", "r")) == NULL)
printf("创建文件失败");
while(!feof(fa))
{
if((p = (Record*)malloc(LEN)) == NULL)
printf("申请内存出错!");
if(fread(p, LEN, 1, fa) == 1)
{
if(head == NULL)
{
head = p;
last = p;
}
else{
last->next = p;
last = p;
last->next = NULL;
}
}
}
fclose(fa);
return head;
}
//数据存盘
void Fwrite(Record* head)
{
Record *p;
FILE *fb;
if((fb = fopen("record.txt", "w")) == NULL)
printf("创建文件失败");
for(p=head; p; p=p->next)
{
if(fwrite(p, LEN, 1, fb) != 1)
printf("写入文件错误!");
}
fclose(fb);
}
//查询学生记录
void LookupStu(Record *head)
{
@ -336,7 +368,7 @@ void LookupStu(Record *head)
{
char stuName[25];
system("cls");
printf("\n\t\t\t\t\t\t修改学生缺课信息");
printf("\n\t\t\t\t\t\t查询学生缺课信息");
printf("\n\n\t\t\t\t输入学生姓名:");
printf("\n\t\t\t\t\t  ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄");
gotoxy(_X+11, _Y-2); scanf("%s", stuName);
@ -347,8 +379,8 @@ void LookupStu(Record *head)
{
if(strcmp(q->StuName, stuName) == 0)
{
key =1;
printf("\n\t\t\t\t*********************************************************************");
key++;
printf("\n\t\t\t\t***************************第%d条****************************", key);
ShowRecord(q);
}
}
@ -362,6 +394,76 @@ void LookupStu(Record *head)
return;
}
}
//删除学生记录
void DeleteStu(Record *head)
{
char ch1; //确认是否删除
char stuName[25];
system("cls");
printf("\n\t\t\t\t\t\t修改学生缺课信息");
printf("\n\n\t\t\t\t输入学生姓名:");
printf("\n\t\t\t\t\t  ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄");
gotoxy(_X+11, _Y-2); scanf("%s", stuName);
Record *q, *p;
int num=0, count=0; //该学生缺课记录有多少条
for(q=head; q; q=q->next)
if(strcmp(q->StuName, stuName) == 0)
{
num++;
printf("\n\t\t\t\t******************第%d条******************", num); //找到记录并输出
ShowRecord(q);
}
if(num>0)
{
printf("\n\t\t\t\t输入您要修改该学生缺课条次:");
char No = getch();
for(q=head; q; q = q->next) //查找目标人名
{
if(strcmp(q->StuName, stuName) == 0)
{
count++;
if(count == No-'0') //找到该节点
{
system("cls");
ShowRecord(q);
printf("\n\t\t\t\t【0】取消并返回菜单 ,其它键确认删除........");
ch1 = getch();
if(q == head) //要删除节点在头
{
printf("*******************头");
head = q->next;
free(q);
break;
}
if(q->next == NULL) //要删除节点在尾
{
printf("***************尾巴");
p->next =NULL;
free(q);
break;
}
p->next = q->next;
free(q);
break;
}
}
p = q;
}
if(ch1!='0')
{
Fwrite(head); //保存修改后链表到文件
printf("\n\t\t\t\t删除成功! 任意键返回..........");
getch();
}
}
else{
printf("\n\t\t\t\t\t该学生有%d条缺课记录", num); //没找到要删除的信息
printf("\n\n\t\t\t\t【任意键】并返回菜单........ ");
getch();
}
}
//统计某段时间旷课的学生,
void SuitTime(Record *head, char ch)
{
@ -408,9 +510,9 @@ void SuitTime(Record *head, char ch)
}
}
}
if(ch == '4')
CountStuRecord(suit, m);
if(ch == '5')
CountStuRecord(suit, m);
if(ch == '6')
CountClassRecord(suit, m);
}
//按照学生旷课次数排序

Loading…
Cancel
Save