|
|
#include<stdio.h>
|
|
|
#include<string.h>
|
|
|
#include<malloc.h>
|
|
|
#include<windows.h>
|
|
|
#include<conio.h>
|
|
|
#include<stdlib.h>
|
|
|
#define num2 age
|
|
|
FILE *fp1;
|
|
|
FILE *fp2;
|
|
|
struct Student
|
|
|
{
|
|
|
int num1;
|
|
|
float score;
|
|
|
char name[20];
|
|
|
int age;
|
|
|
char sex[2];
|
|
|
char address[20];
|
|
|
char major [20];
|
|
|
char beness[20];
|
|
|
char _class[20];
|
|
|
char change[10];
|
|
|
struct Student *next;
|
|
|
};
|
|
|
typedef struct Student stu;
|
|
|
stu *create_list();
|
|
|
void show_list(stu * head);
|
|
|
bool insert(stu *head);
|
|
|
bool _delete(stu*head);
|
|
|
bool search(char name[20],stu*head);
|
|
|
void welcome();
|
|
|
int color(int c );
|
|
|
void menu(stu ** phead) ;
|
|
|
int login_in();
|
|
|
void sort_list(stu*head);
|
|
|
void keep(stu *head);
|
|
|
stu *fetch();
|
|
|
void assigne1(int * i,int * j);
|
|
|
void assigne2(char ch1[20],char ch2[20]);
|
|
|
void size(int s);
|
|
|
int main()
|
|
|
{
|
|
|
stu *head;
|
|
|
welcome();
|
|
|
login_in();
|
|
|
menu (&head);
|
|
|
}
|
|
|
stu *create_list()
|
|
|
{
|
|
|
|
|
|
stu *head,*p,*q;//p为原指针,q为指向结构体指针
|
|
|
int age;
|
|
|
char address[20];
|
|
|
char major [20];
|
|
|
char beness[20];
|
|
|
char _class[20];
|
|
|
char change[10];
|
|
|
char sex[20];
|
|
|
int num1,n;
|
|
|
float score;
|
|
|
char name[20];
|
|
|
head=p=(stu*)malloc(sizeof(stu));
|
|
|
printf("班级总人数为:\n");
|
|
|
scanf("%d",&n);
|
|
|
while(n--)
|
|
|
{
|
|
|
printf("请依次输入学号 年龄 成绩 姓名 性别 专业 系别 班级 学籍变化情况 籍贯\n");
|
|
|
scanf("%d%d%f%s%s%s%s%s%s%s",&num1,&age,&score,name,sex,major,beness,_class,change,address);
|
|
|
q = (stu*)malloc(sizeof(stu));
|
|
|
q->next=NULL;
|
|
|
q->num1=num1;
|
|
|
q->age =age;
|
|
|
q->score=score;
|
|
|
strcpy(q->name,name);
|
|
|
strcpy(q->address,address);
|
|
|
strcpy(q->major,major);
|
|
|
strcpy(q->beness,beness);
|
|
|
strcpy(q->_class,_class);
|
|
|
strcpy(q->change,change);
|
|
|
strcpy(q->sex,sex);
|
|
|
p->next=q;
|
|
|
p=q;
|
|
|
}
|
|
|
return head;
|
|
|
}
|
|
|
void show_list(stu *head)
|
|
|
{
|
|
|
stu*p=head;
|
|
|
while(p->next!=NULL)
|
|
|
{
|
|
|
p = p->next;
|
|
|
printf("学号:%d年龄:%d成绩:%.2f姓名:%s性别%s籍贯:%s专业:%s系别:%s班级:%s学籍变化情况:%s\n",p->num1,p->age,p->score,p->name,p->sex,p->address,p->major,p->beness,p->_class,p->change);
|
|
|
}
|
|
|
}
|
|
|
bool insert(stu *head)
|
|
|
{
|
|
|
stu * q;
|
|
|
q = (stu*)malloc(sizeof(stu));
|
|
|
q->next = head->next;
|
|
|
head->next = q;
|
|
|
scanf("%d%d%f%s%s%s%s%s%s",&q->num1,&q->age,&q->score,q->name,q->address,q->major,q->beness,q->_class,q->change,q->sex);
|
|
|
}
|
|
|
bool _delete(stu*head)
|
|
|
{
|
|
|
stu *p,*q;
|
|
|
p =head;
|
|
|
q = p->next;
|
|
|
int num1;
|
|
|
scanf("%d",&num1);
|
|
|
while (p->next!=NULL)
|
|
|
{
|
|
|
if(num1==q->num1)
|
|
|
{
|
|
|
if(p->next==NULL)
|
|
|
{
|
|
|
p->next=NULL;
|
|
|
free(q);
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
p->next=q->next;
|
|
|
free(q);
|
|
|
}
|
|
|
return true ;
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
p=p->next;
|
|
|
q = q->next;
|
|
|
}
|
|
|
}
|
|
|
return false;
|
|
|
}
|
|
|
bool search(char name[20],stu*head)
|
|
|
{
|
|
|
int t;
|
|
|
while(head!=NULL)
|
|
|
{
|
|
|
t =strcmp(name,head->name);
|
|
|
if(t==0)
|
|
|
{
|
|
|
printf("学号:%d年龄:%d成绩:%.2f姓名:%s性别%s籍贯:%s专业:%s系别:%s班级:%s学籍变化情况:\n",head->num1,head->age,head->score,head->name,head->sex,head->address,head->major,head->beness,head->_class,head->change);
|
|
|
return true;
|
|
|
}
|
|
|
head= head->next;
|
|
|
}
|
|
|
return false;
|
|
|
}
|
|
|
void welcome()
|
|
|
{
|
|
|
int i;
|
|
|
printf("\t\t\t\t");
|
|
|
char ch[]={"学生学籍管理系统!"};
|
|
|
for(i=0;ch[i];i++)
|
|
|
{
|
|
|
printf("%c",ch[i]);
|
|
|
system("color 08");
|
|
|
Sleep(40);
|
|
|
}
|
|
|
printf("\n") ;
|
|
|
color (6);
|
|
|
}
|
|
|
int color(int c)
|
|
|
{
|
|
|
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),c);
|
|
|
return 0;
|
|
|
}
|
|
|
void menu(stu ** phead)
|
|
|
{
|
|
|
color(12);
|
|
|
color(30);
|
|
|
system("cls"); //清屏
|
|
|
printf("\n");
|
|
|
printf("\t\t\t+------------------------------+\n");
|
|
|
printf("\t\t\t|******************************|\n");
|
|
|
printf("\t\t\t|* *|\n");
|
|
|
printf("\t\t\t|* 学生学籍管理系统 *|\n");
|
|
|
printf("\t\t\t|* *|\n");
|
|
|
printf("\t\t\t|* *|\n");
|
|
|
printf("\t\t\t|* [0] 退出 *|\n");
|
|
|
printf("\t\t\t|* *|\n");
|
|
|
printf("\t\t\t|* [1] 输入所有学生信息 *|\n");
|
|
|
printf("\t\t\t|* *|\n");
|
|
|
printf("\t\t\t|* [2] 查看学生所有信息 *|\n");
|
|
|
printf("\t\t\t|* *|\n");
|
|
|
printf("\t\t\t|* [3] 插入遗漏同学数据 *|\n");
|
|
|
printf("\t\t\t|* *|\n");
|
|
|
printf("\t\t\t|* [4] 删除学生信息 *|\n");
|
|
|
printf("\t\t\t|* *|\n");
|
|
|
printf("\t\t\t|* [5] 按学号查询学生学籍 *|\n");
|
|
|
printf("\t\t\t|* *|\n");
|
|
|
printf("\t\t\t|* [6] 按学号循序查看信息 *|\n");
|
|
|
printf("\t\t\t|* *|\n");
|
|
|
printf("\t\t\t|* [7] 保存数据 *|\n");
|
|
|
printf("\t\t\t|* *|\n");
|
|
|
printf("\t\t\t|* [8] 读档 *|\n");
|
|
|
printf("\t\t\t|* *|\n");
|
|
|
printf("\t\t\t|******************************|\n");
|
|
|
printf("\t\t\t+------------------------------+\n");
|
|
|
color(8);
|
|
|
int x;
|
|
|
char name[20];
|
|
|
while (~scanf("%d",&x))
|
|
|
{
|
|
|
color(12);
|
|
|
color(30);
|
|
|
system("cls"); //清屏
|
|
|
printf("\n");
|
|
|
printf("\t\t\t+------------------------------+\n");
|
|
|
printf("\t\t\t|******************************|\n");
|
|
|
printf("\t\t\t|* *|\n");
|
|
|
printf("\t\t\t|* 学生学籍管理系统 *|\n");
|
|
|
printf("\t\t\t|* *|\n");
|
|
|
printf("\t\t\t|* *|\n");
|
|
|
printf("\t\t\t|* [0] 退出 *|\n");
|
|
|
printf("\t\t\t|* *|\n");
|
|
|
printf("\t\t\t|* [1] 输入所有学生信息 *|\n");
|
|
|
printf("\t\t\t|* *|\n");
|
|
|
printf("\t\t\t|* [2] 查看学生所有信息 *|\n");
|
|
|
printf("\t\t\t|* *|\n");
|
|
|
printf("\t\t\t|* [3] 插入遗漏同学数据 *|\n");
|
|
|
printf("\t\t\t|* *|\n");
|
|
|
printf("\t\t\t|* [4] 删除学生信息 *|\n");
|
|
|
printf("\t\t\t|* *|\n");
|
|
|
printf("\t\t\t|* [5] 按学号查询学生学籍 *|\n");
|
|
|
printf("\t\t\t|* *|\n");
|
|
|
printf("\t\t\t|* [6] 按学号循序查看信息 *|\n");
|
|
|
printf("\t\t\t|* *|\n");
|
|
|
printf("\t\t\t|* [7] 保存数据 *|\n");
|
|
|
printf("\t\t\t|* *|\n");
|
|
|
printf("\t\t\t|* [8] 读档 *|\n");
|
|
|
printf("\t\t\t|* *|\n");
|
|
|
printf("\t\t\t|******************************|\n");
|
|
|
printf("\t\t\t+------------------------------+\n");
|
|
|
color(8);
|
|
|
if(x==0)
|
|
|
{
|
|
|
printf("exit!");
|
|
|
exit(0);
|
|
|
}
|
|
|
switch(x)
|
|
|
{
|
|
|
case 1: *phead = create_list();break;
|
|
|
case 2: show_list(*phead);break;
|
|
|
case 3: if(insert(*phead))
|
|
|
{
|
|
|
printf("插入成功!\n");
|
|
|
}
|
|
|
else
|
|
|
printf("插入失败!\n");
|
|
|
break;
|
|
|
case 4: printf("你要删除的人是:\n");
|
|
|
if(_delete(*phead))
|
|
|
{
|
|
|
printf("删除成功\n");
|
|
|
}
|
|
|
else
|
|
|
printf("查无此人\n");
|
|
|
break;
|
|
|
case 5:
|
|
|
printf("请输入你要查找人的名字\n");
|
|
|
scanf("%s",name);
|
|
|
if(search(name,*phead));
|
|
|
else
|
|
|
printf("查无此人\n");
|
|
|
break;
|
|
|
case 6 :sort_list(*phead);
|
|
|
break;
|
|
|
case 7 :keep(*phead);
|
|
|
break;
|
|
|
case 8 :*phead = fetch();
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
int login_in()
|
|
|
{
|
|
|
printf("\t\t\t|******************************|\n");
|
|
|
printf("\t\t\t|*\t 管理员登陆按1 *|\n");
|
|
|
printf("\t\t\t|* *|\n");
|
|
|
printf("\t\t\t|*\t 注册账号请按2 *|\n");
|
|
|
printf("\t\t\t|* *|\n");
|
|
|
printf("\t\t\t|*\t 学生登录请按3 *|\n");
|
|
|
printf("\t\t\t|******************************|\n");
|
|
|
char mima1[20],mima2[20]={'a','b','c','d'};
|
|
|
int t,x;
|
|
|
scanf("%d",&x);
|
|
|
if(x==1)
|
|
|
{
|
|
|
printf("请输入密码!\n");
|
|
|
while(~scanf("%s",mima1))
|
|
|
{
|
|
|
t =strcmp(mima1,mima2);
|
|
|
if(t==0)
|
|
|
{
|
|
|
printf("密码正确!\n");
|
|
|
break;
|
|
|
}
|
|
|
else
|
|
|
printf("密码错误!\n");
|
|
|
}
|
|
|
return 0;
|
|
|
}
|
|
|
else if (x==2)
|
|
|
{
|
|
|
char ch[10];
|
|
|
if((fp1=fopen("E:\\test.txt","w"))==NULL)
|
|
|
{
|
|
|
printf("The file can not be opened.\n");
|
|
|
exit(1);
|
|
|
}
|
|
|
scanf("%s",ch);
|
|
|
fputs(ch,fp1);
|
|
|
printf("注册成功!\n");
|
|
|
fclose(fp1);
|
|
|
}
|
|
|
rewind(fp1);
|
|
|
char str1[10],str2[10];
|
|
|
scanf("%s",str2);
|
|
|
if((fp1=fopen("E:\\test.txt","r"))==NULL)
|
|
|
{
|
|
|
exit(0);
|
|
|
}
|
|
|
fgets(str1,sizeof(str1),fp1);
|
|
|
puts(str1);
|
|
|
while(strcmp(str1,str2)!=0)
|
|
|
{
|
|
|
printf("密码错误!\n");
|
|
|
gets(str2);
|
|
|
}
|
|
|
printf("密码正确!\n");
|
|
|
}
|
|
|
void sort_list(stu * head)
|
|
|
{
|
|
|
stu *q;//q为原指针,p为新指针
|
|
|
int j,i,len=0;
|
|
|
float score;
|
|
|
q = head;
|
|
|
while(q->next!=NULL)
|
|
|
{
|
|
|
len++;
|
|
|
q=q->next;
|
|
|
}
|
|
|
q = head->next;
|
|
|
for(i=0;i<len-1;i++)
|
|
|
{
|
|
|
q = head->next;
|
|
|
for(j=0;j<len-i-1;j++,q=q->next)
|
|
|
{
|
|
|
if(q->num1>q->next->num1)
|
|
|
{
|
|
|
score = q->score;
|
|
|
q->score=q->next->score;
|
|
|
q->next->score=score;
|
|
|
assigne1(&q->num1,&q->next->num1);
|
|
|
assigne1(&q->age,&q->next->age);
|
|
|
assigne2(q->name,q->next->name);
|
|
|
assigne2(q->sex,q->next->sex);
|
|
|
assigne2(q->major,q->next->major);
|
|
|
assigne2(q->_class,q->next->_class);
|
|
|
assigne2(q->beness,q->next->beness);
|
|
|
assigne2(q->address,q->next->address);
|
|
|
assigne2(q->change,q->next->change);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
void keep(stu *head)
|
|
|
{
|
|
|
if((fp2=fopen("E:\\test1.dat","wb"))==NULL)
|
|
|
{
|
|
|
exit(0);
|
|
|
}
|
|
|
while(head->next!=NULL)
|
|
|
{
|
|
|
fwrite(head->next,sizeof(stu),1,fp2);
|
|
|
head = head->next;
|
|
|
}
|
|
|
fclose(fp2);
|
|
|
printf("成功");
|
|
|
}
|
|
|
stu * fetch()
|
|
|
{
|
|
|
stu *head,*p,*q;
|
|
|
head = p = (stu*)malloc(sizeof(stu));
|
|
|
rewind(fp2);
|
|
|
if((fp2=fopen("E:\\test1.dat","rb"))==NULL)
|
|
|
{
|
|
|
exit(0);
|
|
|
}
|
|
|
while(!feof(fp2))
|
|
|
{
|
|
|
q = (stu*)malloc(sizeof(stu));
|
|
|
q->next=NULL;
|
|
|
fread(q,sizeof(stu),1,fp2);
|
|
|
p->next = q;
|
|
|
p = q;
|
|
|
}
|
|
|
p->next=NULL;
|
|
|
free(p);
|
|
|
fclose(fp2);
|
|
|
printf("查找成功!");
|
|
|
return head;
|
|
|
}
|
|
|
void assigne1(int * i,int * j)
|
|
|
{
|
|
|
int x;
|
|
|
x = *i,
|
|
|
*j = *i;
|
|
|
*i = x;
|
|
|
}
|
|
|
void assigne2(char ch1[20],char ch2[20])
|
|
|
{
|
|
|
char ch3[20];
|
|
|
strcpy(ch3,ch1);
|
|
|
strcpy(ch1,ch2);
|
|
|
strcpy(ch2,ch3);
|
|
|
}
|