| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 679 人关注过本帖
标题:用C语言做 学生成绩管理系统
只看楼主 加入收藏
王燕虹
Rank: 1
等 级:新手上路
帖 子:4
专家分:1
注 册:2012-6-15
收藏
 问题点数:0 回复次数:0 
用C语言做 学生成绩管理系统
用C语言做    学生成绩管理系统
    用不同的文件分别保存学生信息、课程信息和学生选课成绩信息,任何一门课的成绩由平时成绩(x%)、期中成绩(y%)和期末成绩(z%)的比例关系计算成总成绩(x+y+z=100),均以100分制计算。程序要做到能对课程信息、学生信息和选课成绩信息进行增、删、改和查的功能,并能按总分进行升序或降序排列。系统以菜单方式工作。
新手求助哇!一定要用TC运行过的。 急 急
或者改如下程序也行
#include<stdio.h>
#include<stdlib.h>
#include<time.h>
#include<string.h>
#define N 100
int num=0,pl=1;
struct students
{
    char name[20];
    char sex[7];
    long int ID;
    float score[3];
    float total;
}students[N],stu;
void save()
{
    FILE *fp;
    int i;
    if((fp=fopen("E:\\students","wb"))==NULL)
    {
        printf("can not open the file:\n");
        exit(0);
    }
    fputc(num,fp);
    for(i=0;i<num;i++)
        if(fwrite(&students[i],sizeof(struct  
students),1,fp)!=1)
        {
            printf("flie can not be saved:\n");
            exit(0);
        }
        fclose(fp);
}
void load()
{
    FILE *fp;
    int i;
    if((fp=fopen("E:\\students","rb"))==NULL)
    {
        printf("can not open the file:\n");
        exit(0);
    }
    num=fgetc(fp);
    for(i=0;i<num;i++)
        if(fread(&students[i],sizeof(struct  
students),1,fp)!=1)
        {
            printf("can not read the file:\n");
            exit(0);
        }
        fclose(fp);
}
void add()
{
    FILE *fp;
    if((fp=fopen("E:\\students","ab"))==NULL)
    {
        printf("can not open the file:\n");
        exit(0);
    }
    if(fwrite(&students[pl],sizeof(struct  
students),1,fp)!=1)
    {
        printf("can not read the file:\n");
        exit(0);
    }
    fclose(fp);
}
void login()
{
    system("cls");
    int t,i,j,m;
    long int k;
    printf("\t\tPlease input to input information of the  
number of students
:");
    scanf("%d",&t);
    srand((long)time(NULL));
    for(i=0;i<t;i++)
    {
        num++;
        printf("\t\tplease input the %d student's  
message:\n",i+1);
        printf("\t\tname:");
        scanf("%s",students[i].name);
        printf("\n\t\tsex:");
        scanf("%s",students[i].sex);
        printf("\n\t\tID:");
        while(1)
        {
            m=0;
            k=rand()%1000+2011000;
            for(j=0;j<i;j++)
                if(students[j].ID==k)
                {
                    m=1;
                    break;
                }
                if(m==0)
                    break;
        }
        students[i].ID=k;
        printf("%ld",students[i].ID);
        printf("\n\t\tplease input the students  
score:\n");
        printf("\t\tEnglish\t\tMath\t\tComputer\n\t
\t");
        students[i].total=0;
        for(j=0;j<3;j++)
        {
            scanf("%f",&students[i].score[j]);
            students[i].total+=students
[i].score[j];
        }
    }
    printf("Press any key to return......");
    save();
    system("pause>null");
}
void scan()
{
    load();
    system("cls");
    int i,j;
    printf
("==========================================================
====================\n");
    printf("Name gender student id English and math  
computer


Total score
\n");
    printf
("==========================================================
====================\n");
    for(i=0;i<num;i++)
    {
        printf("%-12s%-8s%-5ld",students
[i].name,students[i].sex,students[i].ID);
        for(j=0;j<3;j++)
            printf("       %-5.2f",students
[i].score[j]);
        printf("%10.2f",students[i].total);
        printf("\n");
    }
    printf
("==========================================================
====================\n");
    printf("Press any key to return........");
    system("pause>null");
}
void find()
{
    load();
    system("cls");
    int i,j,button,ID,m=0;
    char name[20];
    printf("\t\tPlease select a inquires the way: 1.  
According to the student id inquires the \ t2. According to  
name query
:\n");
    printf("\t\t");
    scanf("%d",&button);
    switch(button)
    {
    case 1:
        {
            printf("\t\tplease input the student  
ID:\n");
            printf("\t\t");
            scanf("%d",&ID);
            for(i=0;i<num;i++)
                if(ID==students[i].ID)
                {
                    m=1;
                    printf("\t\tname:%s
\n\t\tsex:%s\n\t\tID:%d\n",students[i].name,students
[i].sex,students[i].ID);
                    printf("\n\t
\tEnglish score\t\tMath score\t\tComputer score\n");
                    for(j=0;j<3;j++)
                        printf("\t
\t%.2f\t",students[i].score[j]);
                    printf("\n");
                }
            if(m==0)
                printf("\t\tsorry, no you  
need to find the students' information!
");
        }
        break;
    case 2:
        {
            printf("\t\tplease input the student  
name:\n");
            printf("\t\t");
            scanf("%s",name);
            for(i=0;i<num;i++)
                if((strcmp(name,students
[i].name))==0)
                {
                    m=1;
                    printf("\t\tname:%s
\n\t\tsex:%s\n\t\tID:%d\n",students[i].name,students
[i].sex,students[i].ID);
                    printf("\n\t
\tEnglish score\t\tMath score\t\tComputer score\n");
                    for(j=0;j<3;j++)
                        printf("\t
\t%.2f\t",students[i].score[j]);
                    printf("\n");
                }
                if(m==0)
                    printf("\t\tsorry,  
no you need to find the students' information! ");
        }
        break;
    }
    printf("Press any key to return ......");
    system("pause>null");
}
void sort()
{
    load();
    system("cls");
    int i,j;
    for(i=0;i<num-1;i++)
        for(j=0;j<num-i-1;j++)
            if(students[j].total<students[j
+1].total)
            {
                stu=students[j];
                students[j]=students[j+1];
                students[j+1]=stu;
            }
            printf
("==========================================================
==\n");
            printf("Name gender student id  
English and math score of computer
\n");
    for(i=0;i<num;i++)
    {
        printf("%-8s%-6s%-5ld  ",students
[i].name,students[i].sex,students[i].ID);
        for(j=0;j<3;j++)
            printf("%5.2f    ",students
[i].score[j]);
        printf("  %.2f",students[i].total);
        printf("\n");
    }
    printf
("==========================================================
==\n");
    printf("Press any key to return.........");
    save();
    system("pause>null");
}
void statistics()
{
    load();
    system("cls");
    int i,key;
    float sum,average,rate,min,max;
    for(;;)
    {
        sum=0;
        float a[5]={0};
        while(1)
        {
            printf("\tPlease chioce(1-4):1.  
Statistical English grade 2. Statistical mathematics result  
3. Series


Computer program grades 4. Exit
\n");
            printf("\t\t");
            scanf("%d",&key);
            if(1<=key&&key<=4)
            {
                key--;
                break;
            }
            else
                printf("\t\tIllegale  
operation,plaese chioce(1-4)!");
        }
        if(key==3)
            break;
        for(i=0;i<num;i++)
        {
            if(90<=students[i].score[key])
                a[0]++;
            else if(80<=students[i].score[key])
                a[1]++;
            else if(70<=students[i].score[key])
                a[2]++;
            else if(60<=students[i].score[key])
                a[3]++;
            else
                a[4]++;
        sum+=students[i].score[key];
        max=min=students[0].score[key];
        if(max<students[i].score[key])
            max=students[i].score[key];
        if(min>students[i].score[key])
            min=students[i].score[key];
        }
        average=sum/num;
        a[0]=a[0]/num*100;
        a[1]=a[1]/num*100;
        a[2]=a[2]/num*100;
        a[3]=a[3]/num*100;
        a[4]=a[4]/num*100;
        rate=a[0]+a[1]+a[2]+a[3];
    printf("\t\taverage %.2f:\n",average);
    printf("\t\tpass rate %.2f:\n",rate);
    printf("\t\tmax score %.2f:\n",max);
    printf("\t\tmin score %.2f:\n",min);
    printf("\t\texcellent rate %.2f:\n",a[0]);
    printf("\t\twell done rate %.2f:\n",a[1]);
    printf("\t\tvery good rate %.2f:\n",a[2]);
    printf("\t\tgood rate %.2f:\n",a[3]);
    printf("\t\tpoor rate %.2f:\n",a[4]);
    }
    printf("Press any key to return......");
    save();
    system("pause>null");
}
void increase()
{
    add();
    system("cls");
    int j,x,k;
    srand((long)time(NULL));
    printf("\t\tplease input the student message:\n");
    printf("\t\tname:");
    scanf("%s",students[num].name);
    printf("\t\tsex:");
    scanf("%s",students[num].sex);
    printf("\t\tId:");
    while(1)
    {
        x=0;
        k=rand()%1000+2011000;
        for(j=0;j<num;j++)
            if(k==students[j].ID)
                {
                    x=1;
                    break;
                }
            if(x==0)
                break;
    }
        students[num].ID=k;
        printf("%ld\n",students[num].ID);
        printf("\n\t\tEnglish score\t\tMath score\t
\tComputer score\n");
        students[num].total=0;
        for(j=0;j<3;j++)
        {
            printf("\t\t");
            scanf("%f",&students[num].score[j]);
            students[num].total+=students
[num].score[j];
        }
    num++;
    save();
    printf("Add finished
,Press any key to return.......");
    system("pause>null");
}
void amend()
{
    load();
    system("cls");
    int i,j,key,x=1;
    char name[20];
    printf("\t\tplease input the student name:\n");
    printf("\t\t");
    scanf("%s",name);
    for(i=0;i<num;i++)
        if((strcmp(name,students[i].name))==0)
        {
            x=0;
            break;
        }
    if(x==0)
    {
        printf("\t\tname:%s",students[i].name);
        printf("\n\t\tsex:%s",students[i].sex);
        printf("\n\t\tID:%ld",students[i].ID);
        printf("\n\t\tEnglish \tMath  \tcomputer
\n");
        for(j=0;j<3;j++)
            printf("\t\t%.2f",students[i].score
[j]);
        printf("\n");
        while(1)
        {
            printf("\t\tPlease choose you to  
change the options: 1. The name 2. Gender 3. Student id 4.  
Scores
  5.out");
            printf("\t\t");
            scanf("%d",&key);
            if(key==1)
            {
                printf("\t\tplaese input the  
new name:\n");
                printf("\t\t");
                scanf("%s",students
[i].name);
            }
            else if(key==2)
            {
                printf("\t\tplease input the  
new sex:\n");
                printf("\t\t");
                scanf("%s",students[i].sex);
            }
            else if(key==3)
            {
                printf("\t\tplease input the  
new ID:\n");
                printf("\t\t");
                scanf("%ld",students[i].ID);
            }
            else if(key==4)
            {
                printf("\t\tplease input the  
new score:\n");
                printf("\t\tEnglish score\t
\tMath score\t\tComputer score\n");
                for(j=0;j<3;j++)
                    scanf
("%.2f",students[i].score[j]);
            }        
            else
                break;
            printf("The students' information  
modify success!
\n");
            save();
        }
    }
    else
        printf("\t\tNot  find  the student's  
information
:\n");
    printf("Press any key to return.....");
    system("pause>null");
}
void deal()
{
    load();
    system("cls");
    int i,j,x=1;
    char name[20],ch;
    printf("\t\tplease input the student name:\n");
    printf("\t\t");
    scanf("%s",name);
    for(i=0;i<num;i++)
        if(strcmp(name,students[i].name)==0)
        {
            x=0;
            break;
        }
    if(x==0)
    {
        printf("%8s%8s%6s%9s%9s%12s%9s","1. The name  
", "2. Student id", "3. Gender," "4. The English


Language ", "5. Mathematics," "6. Computer", "7. Total score
);
        printf("\n");
        printf("%8s%8ld%5s",students
[i].name,students[i].ID,students[i].sex);
        for(j=0;j<3;j++)
            printf("     %5.2f",students
[i].score[j]);
        printf("%9.2f",students[i].total);
        printf("\n");
        printf("are you sure delete the student's  
message:if you sure,press 'Y'or'y',or press 'N' or 'n'\n");
        getchar();
        ch=getchar();
        if(ch=='Y'||ch=='y')
        {
            for(j=i;j<num;j++)
                students[j]=students[j+1];
            printf("The students' information  
have been deleted!\n");
            num--;
            save();
        }
    }
    else
        printf("Not  find  the student's  
information!");
    printf("\n");
    printf("Press any key to return.....");
    system("pause>null");
}
void mnue()
{
    system("cls");
    printf
("**********************************************************
**************\n\n");
    printf("-------------------------------Students'  
information management system

-------------------------\n");
    Printf (" \ t \ t1. Entry information \ t \ students  
t \ t2. Browse information \ t \ students t \ n ");

Printf (" \ t \ t3. Search for students' information \ t \ t  
\ t4. To the student information sort \ t \ t \ n ");

Printf (" \ t \ t5. Statistical information \ t \ students t  
\ t6. Add student information \ t \ t \ n ");

Printf (" \ t \ t7. Modify the students information \ t \ t  
\ t8. Delete student information \ t \ t \ n ");

Printf (" \ t \ t9. Quit: \ n ")
;
    printf
("----------------------------------------------------------
----------------\n\n");
    printf
("**********************************************************
****************\n");
}
void main()
{
    int number,count=0;
    while(1)
    {
        mnue();
        printf("\t\tPlease input choose type
1--8:");
        scanf("%d",&number);
        switch(number)
        {
                case 1:login();break;
                case 2:scan();break;
                case 3:find();break;
                case 4:sort();break;
                case 5:statistics();break;
                case 6:increase();break;
                case 7:amend();break;
                case 8:deal();break;
                case 9:exit(0);
                default :printf("\nThe  
illegal operation:
\n");break;
        }
    }
}
搜索更多相关主题的帖子: 信息 include 期末成绩 C语言 
2012-06-15 17:33
快速回复:用C语言做 学生成绩管理系统
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.024454 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved