c语言学生系统简易编码
#include <stdio.h>#include <stdlib.h>
#include <string.h>
struct score
{
int chinese;
int math;
int english;
};
struct student
{
char name;
int num;
struct score all;
struct student *next;
};
struct student *head,*stu;
int key;
void main()
{
struct student *create();
struct student *insert(struct student *head);
struct student *delate(struct student *head);
struct student *revise(struct student *head);
void print(struct student *head);
void seek(struct student *head);
void write(struct student *head);
void control();
void FREE(struct student *head);
printf("欢迎来到学生管理系统!\n");
system("pause");
system("cls");
while(1)
{
control();
if(key==1)
{
stu=create();
}
else if(key==2)
{
insert(stu);
}
else if(key==3)
{
delate(stu);
}
else if(key==4)
{
revise(stu);
}
else if(key==5)
{
seek(stu);
}
else if(key==6)
{
print(stu);
}
else if(key==7)
{
write(stu);
}
else if(key==0)
{
FREE(stu);
exit(0);
}
system("pause");
system("cls");
}
}
struct student *create()
{
struct student *head,*temp,*p,*s;
int m,n;
printf("请输入需要输入学生的个数!\n");
scanf("%d",&n);
temp=p=head=(struct student *)malloc(sizeof(struct student));
for(m=0;m<n;m++)
{
printf("请输入第%d名学生姓名:\n",m+1);;
scanf("%s",&temp->name);
printf("请输入第%d名学生学号:\n",m+1);
scanf("%d",&temp->num);
printf("请输入第%d名学生 语文 英语 数学 分数:\n",m+1);
scanf("%d%d%d",&temp->all.chinese,&temp->all.english,&temp->all.math);
temp=(struct student *)malloc(sizeof(struct student));
s=p;
p->next=temp;
p=temp;
}
s->next=NULL;
return head;
}
void print(struct student *head)
{
struct student *temp;
temp=head;
printf("学生学号语文英语数学\n");
while(temp!=NULL)
{
printf("%s %d %d %d %d\n",temp->name,temp->num,temp->all.chinese,temp->all.english,temp->all.math);
temp=temp->next;
}
}
struct student *insert(struct student *head)
{
struct student *temp,*ins;
temp=head;
ins=(struct student *)malloc(sizeof(struct student ));
printf("请输入插入学生姓名:\n");;
scanf("%s",&ins->name);
printf("请输入插入学生学号:\n");
scanf("%d",&ins->num);
printf("请输入插入学生 语文 英语 数学 分数:\n");
scanf("%d%d%d",&ins->all.chinese,&ins->all.english,&ins->all.math);
while(temp->next!=NULL)
{
temp=temp->next;
}
temp->next=ins;
ins->next=NULL;
return head;
}
struct student *delate(struct student *head)
{
struct student *temp,*p;
char name;
int m;
temp=head;
printf("请输入需要删去的学生姓名:\n");
scanf("%s",&name);
while(temp!=NULL)
{
m=strcmp(temp->name,name);
if(m==0)
{
p->next=temp->next;
break;
}
p=temp;
temp=temp->next;
}
return head;
}
struct student *revise(struct student *head)
{
struct student *temp;
char name;
int m,n;
temp=head;
printf("请输入需要修改信息的学生姓名:\n");
scanf("%s",&name);
while(temp!=NULL)
{
m=strcmp(temp->name,name);
if(m==0)
{
break;
}
temp=temp->next;
}
printf("修改学号按(1)\n修改语文成绩按(2)\n修改英语成绩按(3)\n修改数学成绩按(4)\n");
scanf("%d",&n);
if(n==1)
{
printf("请输入修改后的学号:\n");
scanf("%d",&temp->num);
}
else if(n==2)
{
printf("请输入修改后的语文成绩:\n");
scanf("%d",&temp->all.chinese);
}
else if(n==3)
{
printf("请输入修改后英语成绩:\n");
scanf("%d",&temp->all.english);
}
else if(n==4)
{
printf("请输入修改后的数学成绩:\n");
scanf("%d",&temp->all.math);
}
return head;
}
void seek(struct student *head)
{
struct student *temp;
char name;
int m;
temp=head;
printf("请输入需要查找信息的学生姓名:\n");
scanf("%s",&name);
while(temp!=NULL)
{
m=strcmp(temp->name,name);
if(m==0)
{
break;
}
temp=temp->next;
}
if(temp==NULL)
{
printf("未找到学生信息!\n");
}
else
{
printf("学生学号语文英语数学\n");
printf("%s %d %d %d %d\n",temp->name,temp->num,temp->all.chinese,temp->all.english,temp->all.math);
}
}
void write(struct student *head)
{
FILE *fp;
if((fp=fopen("studentscore.txt","w"))==NULL)
{
printf("error!\n");
exit(0);
}
else
{
fprintf(fp,"学生学号语文英语数学\n");
while(head!=NULL)
{
fprintf(fp,"%s %d %d %d %d\n",head->name,head->num,head->all.chinese,head->all.english,head->all.math);
head=head->next;
}
}
fclose(fp);
}
void control()
{
printf("新建学生目录按(1)\n插入学生按(2)\n删去学生按(3)\n修改学生信息按(4)\n查找学生按(5)\n打印目录按(6)\n保持到文件按(7)\n结束按(0)\n");
scanf("%d",&key);
system("cls");
}
void FREE(struct student *head)
{
free(head);
head=NULL;
}
556 学习学习 我我我我哦
888866666 好好学习天天向上 6666 查看 好好学习 好好学习
xuexi ! 我来瞅瞅 666 556 1 学习 aa 好好学习天天向上 去参加竞赛
看看