| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 2615 人关注过本帖
标题:一个学生成绩管理系统的程序
取消只看楼主 加入收藏
mdqsky
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2008-7-2
收藏
 问题点数:0 回复次数:1 
一个学生成绩管理系统的程序
#include <time.h>
#include <stdio.h>
#include <conio.h>
#include <stdlib.h>
#include <string.h>
#define MAX 80

void input();
void sort();
void display();
void insert();
void del();
void find();
void save();
void read();
void del_file();
void modify();

int now_no=0;

struct student
{
    int no;
    int classs;
    char name[20];
    float score1;
    float sort;
};
struct student stu[MAX],*p;


main()                                                                                  /*主函数*/
{
    int as;
    start: printf("\n\t\t\t * 欢迎使用学生成绩管理系统 *\n");
                                                                            /*以下为功能选择模块*/
    do
    {
        printf("\n\t\t\t\t1.录入学员信息\n\t\t\t\t2.显示学员信息\n\t\t\t\t3.成绩排序信息\n\t\t\t\t4.添加学员信息\n\t\t\t\t5.删除学员信息\n\t\t\t\t6.修改学员信息\n\t\t\t\t7.查询学员信息\n\t\t\t\t8.从文件读入学员信息\n\t\t\t\t9.删除文件中学员信息\n\t\t\t\t10.保存学员信息\n\t\t\t\t11.退出\n");
        printf("\t\t\t\t选择功能选项:");
        fflush(stdin);
        scanf("%d",&as);
        
        switch(as)
        {
            case 1:system("cls");input();break;
            case 2:system("cls");display();break;
            case 3:system("cls");sort();break;
            case 4:system("cls");insert();break;
            case 5:system("cls");del();break;
            case 6:system("cls");modify();break;
            case 7:system("cls");find();break;
            case 8:system("cls");read();break;
            case 9:system("cls");del_file();break;
            case 10:system("cls");save();break;
            case 11:system("exit");exit(0);
            default:system("cls");goto start;
        }
    }
    while(1);                                                                 /*至此功能选择结束*/
}


void input()                                                                  /*原始数据录入模块*/
{
    int i=0;
    char ch;
    do
    {
        printf("\t\t\t\t1.录入学员信息\n输入第%d个学员的信息\n",i+1);
        
        printf("\n输入学生编号:");
        scanf("%d",&stu[i].no);
        fflush(stdin);
        
        printf("\n输入学员班级(1~4):");
        fflush(stdin);
        scanf("%d",&stu[i].classs);

        printf("\n输入学员姓名:");
        fflush(stdin);
        gets(stu[i].name);
                
        printf("\n输入学员C语言成绩:");
        fflush(stdin);
        scanf("%f",&stu[i].score1);
        
        printf("\n\n");
        i++;
        now_no=i;
        
        printf("是否继续输入?(Y/N)");
        fflush(stdin);
        ch=getch();
        system("cls");
    }

    while(ch!='n'&&ch!='N');
    system("cls");
}


void sort()                                                                       /*排序数据函数*/
{
    struct student temp;
    int i,j;
    
    for(i=1;i<now_no;i++)
    {
        for(j=1;j<=now_no-i;j++)
        {
            if(stu[j-1].score1<stu[j].score1)
            {
                temp=stu[j];
                stu[j]=stu[j-1];
                stu[j-1]=temp;
            }
        }
    }
}



void display()                                                                    /*显示数据函数*/
{
    int i;
    int j;
    int mark;
    char as;
    char ch;
    
    printf("输入所查班级(1~4):");
    scanf("%d",&j);

    do
    {
        printf("\t\t\t\t%d班学员信息列表\n",j);
        printf("   \t\t\t编号\t姓名\tC语言\n");
        
        for(i=0;i<now_no&&stu[i].name[0];i++)
        {
            if(stu[i].classs==j)
                printf("   \t\t\t%d\t%s\t%.2f\n",stu[i].no,stu[i].name,stu[i].score1);
        }
        printf("按任意键继续.\n");
        fflush(stdin);
        as=getch();
    }
    while(!as);

    printf("是否按分数段查看学生成绩?(Y/N)");
    ch=getchar();
    if(ch!='n'&&ch!='N')
    {
        printf("\t\t\t\t 90~100分学员信息列表\n");
        printf("   \t\t\t班级\t编号\t姓名\tC语言值\n");
        for(i=0;i<now_no&&stu[i].name[0];i++)
        {
            mark=stu[i].score1/10;

            if(mark>=9)
            {
              printf("   \t\t\t%d\t%d\t%s\t%.2f\n",stu[i].classs,stu[i].no,stu[i].name,stu[i].score1);    
            }
        }
        
        printf("\t\t\t\t 80~90分学员信息列表\n");
        printf("   \t\t\t班级\t编号\t姓名\tC语言值\n");         
        for(i=0;i<now_no&&stu[i].name[0];i++)
        {
            mark=stu[i].score1/10;

            if(mark<9&&mark>=8)
            {
              printf("   \t\t\t%d\t%d\t%s\t%.2f\n",stu[i].classs,stu[i].no,stu[i].name,stu[i].score1);    
            }
        }    
        
        printf("\t\t\t\t 70~80分学员信息列表\n",j);
        printf("   \t\t\t班级\t编号\t姓名\tC语言值\n");         
        for(i=0;i<now_no&&stu[i].name[0];i++)
        {
            mark=stu[i].score1/10;

            if(mark<8&&mark>=7)
            {
              printf("   \t\t\t%d\t%d\t%s\t%.2f\n",stu[i].classs,stu[i].no,stu[i].name,stu[i].score1);    
            }
        }
        
        printf("\t\t\t\t 60~70分学员信息列表\n",j);
        printf("   \t\t\t班级\t编号\t姓名\tC语言值\n");         
        for(i=0;i<now_no&&stu[i].name[0];i++)
        {
            mark=stu[i].score1/10;

            if(mark<7&&mark>=6)
            {
              printf("   \t\t\t%d\t%d\t%s\t%.2f\n",stu[i].classs,stu[i].no,stu[i].name,stu[i].score1);    
            }
        }
        
        printf("\t\t\t\t 不及格学员信息列表\n",j);
        printf("   \t\t\t班级\t编号\t姓名\tC语言值\n");         
        for(i=0;i<now_no&&stu[i].name[0];i++)
        {
            mark=stu[i].score1/10;

            if(mark<6)
            {
              printf("   \t\t\t%d\t%d\t%s\t%.2f\n",stu[i].classs,stu[i].no,stu[i].name,stu[i].score1);    
            }
           }
    }
    printf("按任意键继续.\n");
    fflush(stdin);
    as=getch();
    system("cls");
}


void insert()                                                                     /*插入数据函数*/
{
    char ch;
    do
    {
        printf("\n\t\t输入新插入学员队信息\n");
        
        printf("\n输入学生编号:");
        fflush(stdin);
        scanf("%d",&stu[now_no].no);
        
        printf("\n输入学员班级:");
        fflush(stdin);
        scanf("%d",&stu[now_no].classs);
        
        printf("\n输入学员姓名:");
        fflush(stdin);
        gets(stu[now_no].name);
                
        printf("\n输入学员C语言成绩:");
        fflush(stdin);
        scanf("%f",&stu[now_no].score1);
        
        printf("\n\n");
        now_no=now_no+1;
        sort();
        printf("是否继续输入?(Y/N)");
        fflush(stdin);
        ch=getch();
        system("cls");
    }
    while(ch!='n'&&ch!='N');
}


void del()                                                                        /*删除数据函数*/
{
    int inum,i,j;
    printf("输入要删除学员的编号:");
    fflush(stdin);
    scanf("%d",&inum);
    
    for(i=0;i<now_no;i++)
    {
        if(stu[i].no==inum)
        {
            if(i==now_no)now_no-=1;
            else
            {
                stu[i]=stu[now_no-1];
                now_no-=1;
            }
            sort();
            break;
        }
    }
    
    system("cls");
}


void save()                                                                       /*保存数据函数*/
{
    FILE *fp;
    int i;
    char filepath[20];
    
    printf("输入要保存的文件路径:");
    fflush(stdin);
    gets(filepath);
    
    if((fp=fopen(filepath,"w"))==NULL)
    {
        printf("\n保存失败!");
        exit(0);
    }
    for(i=0;i<now_no;i++)
    {
        fprintf(fp,"\t%d\t%d\t%s\t%.2f\n",stu[i].no,stu[i].classs,stu[i].name,stu[i].score1);
    }
    fclose(fp);
    printf("学生信息已保存在%s中!\n",filepath);
    system("pause");
    system("cls");
}


void find()                                                                           /*查询函数*/
{
    int i;
    char str[20],as;
    do
    {
        printf("输入要查询的学生姓名:");
        fflush(stdin);
        gets(str);
        for(i=0;i<now_no;i++)
            if(!strcmp(stu[i].name,str))
            {
                printf("\t编号\t班级\t姓名\tC语言成绩\n");
                printf("\t%d\t%d\t%s\t%.2f\n",stu[i].no,stu[i].classs,stu[i].name,stu[i].score1);
            }
            printf("\t\t按任意键返回主菜单.");
            fflush(stdin);
            as=getch();
    }
    while(!as);
    
    system("cls");
}



void modify()                                                                     /*修改数据函数*/
{
    int i;
    char str[20],as;
    printf("输入要修改的学生姓名:");
    fflush(stdin);
    gets(str);
    
    for(i=0;i<now_no;i++)
        if(!strcmp(stu[i].name,str))
        {
            system("cls");
            printf("\n\t\t输入新插入学员队信息\n");
            
            printf("\n输入学生编号:");
            fflush(stdin);
            scanf("%d",&stu[i].no);
            
            printf("\n输入学员班级:");
            fflush(stdin);
            scanf("%d",&stu[i].classs);
            
            printf("\n输入学员C语言成绩:");
            fflush(stdin);
            scanf("%f",&stu[i].score1);
            
            printf("\n\n");
            sort();
            break;
        }
        
    system("cls");
}

void read()                                                                   /*读入文件数据函数*/
{
    FILE *fp;
    int i;
    char filepath[20];
    printf("输入要读入的文件路径:");
    fflush(stdin);
    gets(filepath);
    
    if((fp=fopen(filepath,"r"))==NULL)
    {
        printf("找不到%s文件!\n",filepath);
        system("pause");
        exit(0);
    }
    now_no=0;
    
    for(i=0;i<MAX&&!feof(fp);i++)
    {
        fscanf(fp,"\t%d\t%d\t%s\t%f\n",&stu[i].no,stu[i].classs,stu[i].name,&stu[i].score1);
        now_no++;
    }
    fclose(fp);
    printf("保存的在文件%s中的所有信息已经读入!\n",filepath);
    system("pause");
    system("cls");
}

void del_file()                                                               /*删除文件数据函数*/
{
    FILE *fp;
    char filepath[20];
    
    printf("输入要删除的文件路径:");
    fflush(stdin);
    gets(filepath);
    fp=fopen(filepath,"w");
    fclose(fp);
    
    printf("保存的在文件%s中的所有信息已经删除!\n",filepath);
    system("pause");
    system("cls");
}
搜索更多相关主题的帖子: void include 系统 学生 
2008-07-02 17:34
mdqsky
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2008-7-2
收藏
得分:0 
补充
void display()                                                                    /*显示数据函数*/
{
    int i;
    int j;
    int mark;
    char as;
    char ch;
    
    printf("输入所查班级(1~4):");
    scanf("%d",&j);

    do
    {
        printf("\t\t\t\t%d班学员信息列表\n",j);
        printf("        \t\t\t编号\t姓名\tC语言\n");
        
        for(i=0;i<now_no&&stu[i].name[0];i++)
        {
            if(stu[i].classs==j)
                printf("   \t\t\t%d\t%s\t%.2f\n",stu[i].no,stu[i].name,stu[i].score1);
        }
        printf("按任意键继续.\n");
        fflush(stdin);
        as=getch();
    }
    while(!as);

    printf("是否按分数段查看学生成绩?(Y/N)");
    ch=getchar();
    if(ch!='n'&&ch!='N')
    {
        for(i=1;i<now_no&&stu[i].name[0];i++)
        {
            mark=stu[i].score1/10;
        
            switch (mark)
            {
                case 10:
                case 9:
                    do
                    {
                        printf("\t\t\t\t 90~100分学员信息列表\n");
                        printf("        \t\t\t班级\t编号\t姓名\tC语言\n");
            
                        for(i=0;i<now_no&&stu[i].name[0];i++)
                            printf("   \t\t\t%d\t%d\t%s\t%.2f\n",stu[i].classs,stu[i].no,stu[i].name,stu[i].score1);
                        printf("按任意键继续.\n");
                        fflush(stdin);
                        as=getch();
                    }
                    while(!as);
                    break;   
                case 8:
                    do
                    {
                        printf("\t\t\t\t  80~90分学员信息列表\n");
                        printf("   \t\t\t班级\t编号\t姓名\tC语言\n");
            
                        for(i=0;i<now_no&&stu[i].name[0];i++)
                            printf("   \t\t\t%d\t%d\t%s\t%.2f\n",stu[i].classs,stu[i].no,stu[i].name,stu[i].score1);
                        printf("按任意键继续.\n");
                        fflush(stdin);
                        as=getch();
                    }
                    while(!as);
                    break;   
                case 7:
                    do
                    {
                        printf("\t\t\t\t  70~80分学员信息列表\n");
                        printf("   \t\t\t班级\t编号\t姓名\tC语言\n");
                        
                        for(i=0;i<now_no&&stu[i].name[0];i++)
                            printf("   \t\t\t%d\t%d\t%s\t%.2f\n",stu[i].classs,stu[i].no,stu[i].name,stu[i].score1);
                        printf("按任意键继续.\n");
                        fflush(stdin);
                        as=getch();
                    }
                    while(!as);
                    break;   
                case 6:
                    do
                    {
                        printf("\t\t\t\t  60~70分学员信息列表\n");
                        printf("   \t\t\t班级\t编号\t姓名\tC语言\n");
                        
                        for(i=0;i<now_no&&stu[i].name[0];i++)
                            printf("   \t\t\t%d\t%d\t%s\t%.2f\n",stu[i].classs,stu[i].no,stu[i].name,stu[i].score1);
                        printf("按任意键继续.\n");
                        fflush(stdin);
                        as=getch();
                    }
                    while(!as);
                    break;   
                case 5:
                case 4:
                case 3:
                case 2:
                case 1:
                case 0:
                    do
                    {
                        printf("\t\t\t\t  不及格学员信息列表\n");
                        printf("   \t\t\t班级\t编号\t姓名\tC语言\n");
            
                        for(i=0;i<now_no&&stu[i].name[0];i++)
                            printf("   \t\t\t%d\t%d\t%s\t%.2f\n",stu[i].classs,stu[i].no,stu[i].name,stu[i].score1);
                        printf("按任意键继续.\n");
                        fflush(stdin);
                        as=getch();
                    }
                    while(!as);
                    break;
                default:
                    printf("Input error!\n");
            }
        }
        fflush(stdin);
        system("cls");
    }
}
2008-07-02 17:47
快速回复:一个学生成绩管理系统的程序
数据加载中...
 
   



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

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