c语言程序设计 使用链表 学生管理系统
发布网友
发布时间:2022-05-01 03:23
我来回答
共1个回答
热心网友
时间:2022-06-23 05:02
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
#include<string.h>
#define maxsize 1000
#define addsize 50
struct stu{
int number;
char name[20];
char sex[5];
int Chinese;
int English;
int Match;
float average;
struct stu *next;
};
struct stu *create(int n){
struct stu *head=NULL,*p;
int i=1,j;
p=(struct stu *)malloc(maxsize*sizeof(struct stu));
if(n>maxsize)
{
p=(struct stu *)realloc(p,(maxsize+addsize)*sizeof(struct stu));
}
head=p+1;
while(i<=n){
printf("请输入学号:");
scanf("%d",&(p+i)->number);
if((p+i)->number<0)
{
printf("\n学号不能为小于零!");
printf("\n请重新输入学号:");
scanf("%d",&(p+i)->number);
}
for(j=0;j<i;j++)
{
if((p+i)->number==(p+j)->number)
{
printf("输入学号已存在!");
printf("\n请重新输入学号:");
scanf("%d",&p->number);
}
}
if(j==i)
{
printf("请输入姓名:");
scanf("%s",(p+i)->name);
printf("请输入性别:");
scanf("%s",(p+i)->sex);
printf("请输入语文成绩:");
scanf("%d",&(p+i)->Chinese);
while((p+i)->Chinese>100||(p+i)->Chinese<0){
getchar();
printf("输入错误,请重新输入!\n");
printf("请输入语文成绩:");
scanf("%d",&(p+i)->Chinese);
}
printf("请输入英语成绩:");
scanf("%d",&(p+i)->English);
while((p+i)->English>100||(p+i)->English<0){
getchar();
printf("输入错误,请重新输入!\n");
printf("请输入英语成绩:");
scanf("%d",&(p+i)->English);
}
printf("请输入数学成绩:");
scanf("%d",&(p+i)->Match);
while((p+i)->Match>100||(p+i)->Match<0){
getchar();
printf("输入错误,请重新输入!\n");
printf("请输入数学成绩:");
scanf("%d",&(p+i)->Match);
}
(p+i)->average=(float)(((p+i)->Chinese+(p+i)->Match+(p+i)->English)/3);
}
i++;
}return head;
}