马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
这个代码不知道为什么第一个指令只能运行2次。
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>
struct Student
{
char name[40];
int num;
int English_mark;
int Math_mark;
int c_mark;
int avermark;
};
struct Line
{
struct Student student;
struct Line *next;
};
struct Line *head;
void getInput(struct Line *student)
{
printf("该学生的名字为:");
scanf("%s",student->student.name);
getchar();
printf("该学生的学号为:");
scanf("%d",&student->student.num);
getchar();
printf("该学生的英语成绩为:");
scanf("%d",&student->student.English_mark);
getchar();
printf("该学生的高数成绩为:");
scanf("%d",&student->student.Math_mark);
getchar();
printf("该学生的c语言程序设计成绩为:");
scanf("%d",&student->student.c_mark);
getchar();
student->student.avermark=(student->student.c_mark+student->student.English_mark+student->student.Math_mark)/3;
}
void addStudent(struct Line **head)
{
struct Line *student,*temp,*previous,*current;
student=(struct Line*)malloc(sizeof(struct Line));
if(student==NULL)
{
printf("内存分配失败!!");
exit(1);
}
getInput(student);
if(*head==NULL)
{
*head=student;
student->next=NULL;
}
else
{
current=*head;
previous=NULL;
while(current->next!=NULL&¤t->student.avermark<student->student.avermark)
{
previous=current;
current=current->next;
}
if(current==NULL)
{
current->next=student;
student->next=NULL;
}
else
{
student->next=current;
previous->next=student;
}
}
}
/*struct Line *searchStudent(struct Line *head,char input)
{
struct Line *student;
student=head;
while(student!=NULL)
{
if(!strcmp(student->student.name,input)||!strcmp(student->student.c_mark,input)||!strcmp(student->student.English_mark,input)||!strcmp(student->student.Math_mark,input)||!strcmp(student->student.num,input))
{
break;
}
student=student->next;
}
return student;
}*/
void printStudent(struct Line *head)
{
printf("姓名:%s\n",head->student.name);
printf("学号:%d\n",head->student.num);
printf("高数成绩:%d\n",head->student.Math_mark);
printf("英语成绩:%d\n",head->student.English_mark);
printf("c语言程序设计成绩:%d",head->student.c_mark);
printf("三科平均分为:%d",head->student.avermark);
}
void heart()
{printf(" **** ****\n");
printf(" ********* *********\n");
printf("************* *************\n");
int i,j;
for(i=0;i<3;i++)
{
for(j=0;j<29;j++)
{
printf("*");
}
printf("\n");
}
for(i=0;i<7;i++)
{
for(j=0;j<2*(i+1)-1;j++)
{
printf(" ");
}
for(j=0;j<27-i*4;j++)
{
printf("*");
}
printf("\n");
}
for(i=0;i<14;i++)
{
printf(" ");
}
printf("*\n") ;
}
void menu()
{
printf("************************\n");
printf("1.添加学生信息\n");
printf("2.查看成绩表\n");
printf("3.查询成绩信息\n");
printf("4.删除学生信息\n");
printf("5.修改学生信息\n");
printf("0.退出程序\n");
printf("*************************\n");
}
int main()
{
char ch;
struct Line *head;
char sh[20];
struct Line *student;
heart();
printf("欢迎使用学生成绩管理系统 \n");
printf("welcome to student manage system\n");
printf("====power by swaggy boi!!!====\n");
while(1)
{
menu();
printf("选哪个程序xd:");
scanf("%d",&ch);
getchar();
switch(ch)
{
case 1: addStudent(&head);
char ch;
while(1)
{
printf("学生信息录入成功!!!\n");
printf("是否继续输入(Y/N):");
ch=getchar();
getchar();
if(ch=='Y'||ch=='y')
{
addStudent(&head);
printf(" 学生信息录入成功!!!\n");
}
else if(ch=='N'||ch=='n')
{
break ;
}
}
break;
case 2:;
case 3:;
case 4:;
case 5:;
case 0:;
}
}
return 0;
}
还有两处也需要修改
第一处是第 63 行 while(current->next!=NULL&¤t->student.avermark<student->student.avermark)
应该改为: while(current != NULL && current -> student . avermark < student -> student . avermark)
第二处是第 156 行 必须改为: struct Line * head = NULL ;
|