ACCP4.0 [项目实战2]学员成绩管理系统

 用C语言编写一个程序实现学员管理,每个学员包括3门课的成绩。从键盘输入学员信息,包括学号、姓名、三门课成绩,计算出学员的平均成绩,按照学员平均成绩由大到小排序。另外需要增加下面的管理功能。
插入功能:在排序后的学员成绩表中插入一个学员的信息,要求插入后仍然保持成绩表原有排序。
删除功能:要求输入指定的学号,从学员信息表中删除该学员,删除后的成绩保持原有排序。

#include  < stdio.h >
#include
< stdlib.h >
#include 
< windows.h >
int  count = 0 ;
struct  student
{
    
int num;        
    
char name[20]; 
    
float score;  
    
double ave;    
}
stu[ 50 ], in ();
void  display( struct  student stu[]);
void  sort( struct  student stu[]);
void  insert( struct  student stu[]);
void  del( struct  student stu[]);
struct  student  in ();
void  Loading();
void  main()
{
    
char Inans,Deans,ch;
    Loading();
    printf(
" 学员成绩管理系统 ");
    printf(
"请输入学员信息: ");

    
do{
        stu[count]
=in();
        printf(
"是否继续 (y/n)");
        fflush(stdin);
        ch
=getchar();
        count
++;
    }
while(ch=='y'||ch=='Y');
    printf(
" 排序前的学员信息 ");
    display(stu);
    printf(
" 排序后的学员信息 ");
    sort(stu);
    display(stu);
    printf(
" 是否插入新学员?(y/n)");
    fflush(stdin);
    Inans
=getchar();
    
if(Inans=='Y' || Inans =='y'){
        insert(stu);
    }

    printf(
" 是否要删除某个学员?(y/n)");
    fflush(stdin);
    Deans
=getchar();
    
if(Deans=='y'||Deans=='Y')
    
{
        del(stu);
    }

    system(
"pause");
    system(
"cls");
}


struct  student  in () // 输入学员信息
{
    
float sum=0;
    
int i;
    printf(
" 学号:");
    fflush(stdin);
    scanf(
"%d",&stu[count].num);
    printf(
" 姓名:");
    fflush(stdin);
    gets(stu[count].name);
    printf(
" 三门成绩: "); 
    
for(i=0;i<3;i++)
    
{
        printf(
"成绩%d:",i+1);
        scanf(
"%f",&stu[count].score);
        sum 
+= stu[count].score;
    }

    stu[count].ave
=sum/3.0;
    
return stu[count]; 
}


void  display( struct  student stu[]) // 显示学员信息
{
    
int i; 
    printf(
" 学号 姓名 平均成绩 ");
    
for(i=0;i<count;i++)
    
{
        printf(
"%d ",stu[i].num);
        printf(
"%s ",stu[i].name);
        printf(
"%.1f ",stu[i].ave);
    }

}


void  sort( struct  student stu[]) // 冒泡排序
{
    
int i,j;
    
struct student temp;
    
for(i=0;i<count;i++)
    
{
        
for(j=0;j<count-1-i;j++)
        
{
            
if(stu[j].ave<stu[j+1].ave)
            
{
                temp
=stu[j];
                stu[j]
=stu[j+1];
                stu[j
+1]=temp;
            }

        }

    }

}

void  insert( struct  student stu[]) // 插入学员信息
{
    
int i,j;
    
struct student temp;
    printf(
"请输入要插入的学员信息: ");
    temp
=in();
    
for(i=0;i<count;i++)
    
{
        
if(stu[i].ave>temp.ave)
            
break;
    }

    
for(j=count;j>i;j--)
    
{
        stu[j]
=stu[j-1];
    }

    stu[i]
=temp;
    count
++;
    printf(
"插入新学员后的信息如下:");
    sort(stu);
    display(stu);
}


void  del( struct  student stu[]) // 删除学员信息
{
    
int i,j;
    
int x;
    printf(
"请输入要删除的学号:");
    scanf(
"%d",&x);
    
for(i=0;i<count;i++)
    
{
        
if(stu[i].num==x)
            
break;
    }

    
for(j=i;j<count;j++)
    
{
        stu[j]
=stu[j+1];
    }

    count
--;
    printf(
" 删除后学员的信息如下:");
    sort(stu);
    display(stu);
}


void  Loading()
{
    
const M=30;
    
int i;
    printf(
"【程序装载中 ");
    
for(i=1;i<=M;i++)
    
{
        printf(
"");
        Sleep(
200);        
    }

    printf(
"");
    printf(
" ");
    system(
"cls");
    printf(
"【载入完成】a ");
    printf(
"   欢迎使用【Mark】学生成绩管理系统,本程序启动代码为arron原创... ");  
    fflush(stdin);
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值