我把全部的贴出来吧,我还得改的。#include<stdio.h>
#include<dos.h>
#include<string.h>
#include "stddef.h"
#include <stdlib.h>
//#include "stdafx.h"
#include <conio.h>
#define MAX 10
typedef struct student /*定义结构体*/
{
char name[MAX]; /*姓名*/
int num[MAX]; /* 学号*/
char sex[MAX]; /*性别*/
float chinese; /*语文*/
float mathematic; /* 数学*/
float english; /*英语*/
float computer; /*计算机*/
struct student *next; /*结构体指针*/
}stu;
stu *head;
void cin(stu *p1) /*输入相关数据的函数*/
{
printf("Enter name:\n");
scanf("%s",&p1->name);
printf("Enter num:\n");
scanf("%d",&p1->num);
printf("Enter sex:\n");
scanf("%s",&p1->sex);
printf("Enter score:\n");
printf("Enter chinese:\n");
scanf("%d",&p1->chinese);
printf("Enter math:\n");
scanf("%d",&p1->mathematic);
printf("Enter English:\n");
scanf("%d",&p1->english);
printf("Enter Computer:\n");
scanf("%d",&p1->computer);
}
stu *cindata() /*其他数据是否继续输入的函数*/
{
stu *p1,*p2;
int i=1;
char ch;
p1=(stu *)malloc(sizeof(stu));
head=p1;
while(i)
{
cin(p1);
printf("Do you Want to Continue?yes or no"); /*是否继续输入数据*/
ch=getchar();
ch=getchar();
if(ch=='n'||ch=='N')
{
i=0;
p1->next=NULL;
}
else
{
p2=p1;
p1=(stu *)malloc(sizeof(stu));
p2->next=p1;
}
}
return(p1->next);
}
/*自定义print()函数,实现菜单选择功能*/
void print()
{
system("cls");
printf("\n\n\n\n\n");
printf("\t\t|
STUDENT
|\n");
printf("\t\t|\t0.退出系统
|\n");
printf("\t\t|\t1.输入记录
|\n");
printf("\t\t|\t2.查询记录
|\n");
printf("\t\t|\t3.新生插入
|\n");
printf("\t\t|\t4.显示所有
|\n");
printf("\t\t|
|\n");
printf("\t\t\tchoose(0-4):");
}
void insert() /*通过比较学号来插入数据的函数*/
{
stu *p1,*p3,*p2;
p1=head;
p3=(stu *)malloc(sizeof(stu));
p3->next=NULL;
if(head==NULL){ head=p3; return;}
cin(p3);
while(p1!=NULL&&(p1->num<p3->num))
{
/*通过学号的比较来插入*/
p2=p1;p1=p1->next;
}
if(p2==head) {p3->next=head; head=p3; return;}
p3->next=p1;
p2->next=p3;
}
void search()
{
stu *p2;
int nums[10];
int b=0;
printf("Enter the num of the student you want to find:");/*通过学号查看*/
scanf("%s",&nums);
while(p2!=NULL)
{
if(nums==p2->num)
{
printf("The data you want has be found\n");
printf(" Name:%s\t",p2->name);
printf("Num:%d\t",p2->num);
printf("sex%s\t",p2->sex);
printf("\n");
printf("Chinese:%d\t",p2->chinese);
printf("Math:%d\t",p2->mathematic);
printf("English:%d\t",p2->english);
printf("Computer:%d\t",p2->computer);
printf("\n");
b=1;
}
else if(b==0)
{
printf("sorry not find data!");
p2=p2->next;
}
if(b==1)
{
print();
printf("Find one\n");
}
else
{
print();
printf("Not find\n");
}
}
}
void caverage() /*求各学生语文平均分、最高和最低分成绩的函数*/
{
stu *p1;
int i;
float max=0.0,min=200.0;
float sum=0.0,aver=0;
p1=head;
if(p1==NULL)
printf("not data!");
else
{
for(i=0;p1!=NULL;i++,p1=p1->next)
sum+=p1->chinese;
aver=sum/i;
p1=head;
for(i=0;p1!=NULL;i++,p1=p1->next)
{
if(max<p1->chinese)
max=p1->chinese;
}
p1=head;
for(i=0;p1!=NULL;i++,p1=p1->next)
if(min>p1->chinese)
min=p1->chinese;
}
printf("Chinese Average:%f",aver);
printf("Chinese Max:%f",max);
printf("Chinese Min:%f",min);
}
void maverage() /*求各学生数学平均分、最高和最低分成绩的函数*/
{
stu *p1;
int i;
float max=0.0,min=200.0;
float sum=0.0,aver=0;
p1=head;
if(p1==NULL)
printf("not data!");
else
{
for(i=0;p1!=NULL;i++,p1=p1->next)
sum+=p1->mathematic;
aver=sum/i;
p1=head;
for(i=0;p1!=NULL;i++,p1=p1->next)
{
if(max<p1->mathematic)
max=p1->mathematic;
}
p1=head;
for(i=0;p1!=NULL;i++,p1=p1->next)
if(min>p1->mathematic)
min=p1->mathematic;
}
printf("Mathe Average:%f",aver);
printf("Mathe Max:%f",max);
printf("Mathe Min:%f",min);
}
void eaverage() /*求各学生英语平均分、最高和最低分成绩的函数*/
{
stu *p1;
int i;
float max=0.0,min=200.0;
float sum=0.0,aver=0;
p1=head;
if(p1==NULL)
printf("not data!");
else
{
for(i=0;p1!=NULL;i++,p1=p1->next)
sum+=p1->english;
aver=sum/i;
p1=head;
for(i=0;p1!=NULL;i++,p1=p1->next)
{
if(max<p1->english)
max=p1->english;
}
p1=head;
for(i=0;p1!=NULL;i++,p1=p1->next)
if(min>p1->english)
min=p1->english;
}
printf("English Average:%f",aver);
printf("English Max:%f",max);
printf("English Min:%f",min);
}
void comaverage() /*求各学生计算机平均分、最高和最低分成绩的函数*/
{
stu *p1;
int i;
float max=0.0,min=200.0;
float sum=0.0,aver=0;
p1=head;
if(p1==NULL)
printf("not data!");
else
{
for(i=0;p1!=NULL;i++,p1=p1->next)
sum+=p1->computer;
aver=sum/i;
p1=head;
for(i=0;p1!=NULL;i++,p1=p1->next)
{
if(max<p1->computer)
max=p1->computer;
}
p1=head;
for(i=0;p1!=NULL;i++,p1=p1->next)
if(min>p1->computer)
min=p1->computer;
}
printf("Computer Average:%f",aver);
printf("Computer Max:%f",max);
printf("Computer Min:%f",min);
}
/*自定义Showsystem()函数,实现打印系统的主界面输出*/
void Showsystem()
{
system("cls");
/*清屏*/
/*打印系统主界面*/
printf("#=================================================================#\n");
printf("#=================================================================#\n");
printf("#
欢迎使用学生成绩管理系统!
#\n");
printf("#-----------------------------------------------------------------#\n");
printf("#
copyright @ 2010-7-1
#\n");
printf("#=================================================================#\n");
}/*Showsystem()函数结束*/
void main()
{
int n;
Showsystem(); /*按系统界面
*/
getch();
print();
scanf("%d",&n);
while(n)
{
switch(n)
{
case 1:
cin(head);
break;
case 2:
search();
break;
case 3:
insert();
break;
default:
break;
}
print();
scanf("%d",&n);
}
}
里面的search函数,我还得改,没查询到学号的输出平均分,最高和最低分。