正文

c_language实现的学生管理系统2007-03-31 00:28:00

【评论】 【打印】 【字体: 】 本文链接:http://blog.pfan.cn/ghlat520/24429.html

分享到:

#include <stdio.h>

struct student
{
 int no;       
//学号
 char name[15]; //姓名
 int score[3];  //三门课程的成绩
 double avr;    //平均成绩
};

struct student stu[50]; //声明一个结构数组变量

struct student input();
void display(struct student stud[],int count);
void sort(struct student stud[],int count);
void insert(struct student stud[],int count);
void del(struct student stud[],int count);

void main()
{
 int count;
    char ch;
 ch='y';
   
 printf("请输入学员信息。");
 printf("\n");
 count=0;
 while ((ch=='y') || (ch=='Y'))
 {

  stu[count]=input();       //调用录入信息函数
  count++;
  printf("\n 是否继续?(y or n)");
  scanf(" %c",&ch);
 }
 printf("\n排序前的学员信息如下:");
 display(stu,count);           //调用显示信息函数
 sort(stu,count);              //调用排序函数
 printf("\n排序后的学员信息如下:");
 display(stu,count); 
 
 printf("\n\n是否要插入新学员?(y or n)");
 scanf(" %c",&ch);
 if(ch=='y' || ch=='Y')
 {
  insert(stu,count);       //调用插入信息函数
  count++;
  printf("\n插入新学员后的学员信息如下:");
  display(stu,count);
 }

 printf("\n\n是否要删除某个学员?(y or n)");
 scanf(" %c",&ch);
 if(ch=='y' || ch=='Y')
 {
  del(stu,count);    //调用删除信息函数
  count--;
  printf("\n删除后学员的信息如下:");
  display(stu,count);
 }
}

struct student input()   //录入信息函数
{
  struct student studn;
     int sum,j;
     printf("\n学号:");
  scanf("%d",&studn.no);
  
  printf("\n姓名:");
  scanf("%s",studn.name);
  
  printf("\n三门成绩:");
  sum=0;
  printf("\n");
  for(j=0;j<3;j++)
  {
   printf("成绩%d: ",j+1);
   scanf("%d",&studn.score[j]);
   sum+=studn.score[j];
  }
  studn.avr=sum/3.0;
  return studn;
}

void display(struct student stud[],int count) //显示信息函数
{
 int i;
 printf("\n学号\t姓名\t\t平均成绩");
 printf("\n");
 for(i=0;i<count;i++)
 {
  printf("%-03d",stud[i].no);
  printf("\t%-15s",stud[i].name);
  printf("\t%-10.1f",stud[i].avr);
  printf("\n");
 }
}

void sort(struct student stud[],int count)  //排序函数
{
 /*  冒泡排序法*/
 struct student temp;
    int a,b;
 for(a=0;a<count;a++)
 {
   for(b=0;b<count-1-a;b++)
   {
    if (stu[b].avr<stu[b+1].avr)
       {
         temp=stu[b+1];
         stu[b+1]=stu[b];
          stu[b]=temp;
       }
   } 
 
 }
 
}

void insert(struct student stud[],int count)  //插入函数
{
 /*插入一个学员的信息,要求插入后的学员信息依然有序*/
  int x,y;
  struct student in;
   in=input();

  for(x=0;x<count;x++)
  {
    if(stu[x].avr<in.avr)
  break;
  }
   for(y=count;y>x;y--)  //为要插入的结构空出位置
   {
     stu[y]=stu[y-1];
   } 
   stu[x]=in;            //将要插入的结构保存到该位置
 

 
}

void del(struct student stud[],int count) //删除函数
{
 /*删除一个指定学号的学员信息,要求删除后的学员信息依然有序*/
  int o,p,num;
  printf("请输入您要删除的学号:");
  scanf("%d",&num);
  for(o=0;o<count;o++)
 {
    if(num==stu[o].no)
    break;
  }
  for(p=o+1;p<count;p++)
  {
   stu[o]=stu[p];
  }

}


阅读(2510) | 评论(0)


版权声明:编程爱好者网站为此博客服务提供商,如本文牵涉到版权问题,编程爱好者网站不承担相关责任,如有版权问题请直接与本文作者联系解决。谢谢!

评论

暂无评论
您需要登录后才能评论,请 登录 或者 注册