在win-tc 下编辑的-----学生成绩管理系统

作者在 2006-10-05 18:26:00 发布以下内容

        学生成绩管理系统
在win-tc 下编辑的:
程序如下:

#include "stdlib.h"
#include "string.h"
#include "stdio.h"
#define NULL 0
#define Q 10
#define LEN sizeof(struct student)
struct student      /*定义一个学生考试信息的结构体*/
{char name[Q];     /*用来存放姓名的*/
  char sex[Q];      /*用来存放性别的*/
  long id;          /*用来存放准考证号的*/
  int score[4];     /*用来存放分数的*/
  int total;        /*用来存放总分数的*/
  int m_c;          /*用来存放名次的*/
  struct student *next;/*定义指向下一个结构体的指针*/
  };
int n;                /*用来统计考生人数的*/
char ch[Q];         /*用来存放姓名的*/
struct student *creat() /*定义一个指向struct student的结构体指针函数*creat()用来修改考生信息.*/
{int i;
struct student *head,*p1,*p2;/*定义三个指向struct student的结构体指针*/
p1=p2=(struct student *)malloc(LEN);/*调用malloc()函数用来开辟一个新的存储单元*/
n=0;
printf("请输入学生考试信息!\n");
printf("请在姓名处键以\"!\"结束输入。\n");
printf("姓名:");
scanf("%s",ch);
head=NULL; /*给指针head赋初值*/
while (strcmp(ch,"!")!=0) /*调用字符比较函数strcmp()用来判断是否继续输入*/
  {p1=(struct student *)malloc(LEN);/*调用malloc()函数用来开辟一个新的存储单元*/
   strcpy(p1->name,ch); /*将循环结构前面输入的姓名复制到结构体名为p1的数组name中*/
   printf("性别:");
   scanf("%s",p1->sex);
   printf("准考证号(8位):");
   scanf("%ld",&p1->id);/*将输入的准考证号存放到p1所指结构体的数组id中*/
   printf("数学成绩:");
   scanf("%d",&p1->score[0]);/*将输入的数学成绩存放到p1所指结构体的数组score中*/
   printf("物理成绩:");
   scanf("%d",&p1->score[1]);/*将输入的物理成绩存放到p1所指结构体的数组score中*/
   printf("英语成绩:");
   scanf("%d",&p1->score[2]);/*将输入的英语成绩存放到p1所指结构体的数组score中*/
   printf("C语言成绩:");
   scanf("%d",&p1->score[3]);/*将输入的C语言成绩存放到p1所指结构体的数组score中*/
   p1->total=p1->score[0]+p1->score[1]+p1->score[2]+p1->score[3];/*计算总分 */
   if(n==0)head=p1;/*如果是输入第一组学生考试信息就将指针p1赋给指针head*/
   else p2->next=p1;/*否则将p1赋给p2所指结构体的next指针*/
   p2=p1;/*将指针p1赋给指针p2*/
   n++;  /*将n的值加1*/
   printf("姓名:");
   scanf("%s",ch);/*将输入的姓名存放到字符数组ch中*/
   }
   p2->next=NULL;/*将p2所指结构体的next指针重新赋空值*/
   return (head);/*将输入的第一组学生考试信息返回*/
}
void output(struct student *head) /*定义output()函数将考生的信息从头指针所指内容开始输出*/
  {struct student *p;/*定义一个指向struct student的结构体指针p*/
   printf("-----------------------------------------------------------------------\n");
   printf("                         *学生考试成绩信息表*\n");
   printf("-----------------------------------------------------------------------\n"); /*71个“-”*/
   printf("准考证号   姓  名    性别    数学   物理   英语   C语言   平均分   总分\n");
   printf("-----------------------------------------------------------------------\n");
   p=head;/*将头指针赋给p*/
   if(head!=N

程序库 | 阅读 4280 次
文章评论,共1条
yhn613sz
2009-08-30 17:49
1
这个完事了吗?
游客请输入验证码
浏览106142次