标题:一个学生成绩管理系统的程序
只看楼主
mdqsky
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2008-7-2
 问题点数:0 回复次数:8 
一个学生成绩管理系统的程序
#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
死了都要C
Rank: 4
来 自:四川成都
等 级:贵宾
威 望:13
帖 子:1582
专家分:116
注 册:2006-12-7
得分:0 
/*****************************************************************
** HighlightCodeV3.1 software by yzfy(雨中飞燕) [url=http://]http://[/url] **
*****************************************************************/


void display()                                                                    /*显示数据函数*/
{
   
char ch ;

    printf("是否按分数段查看学生成绩?(Y/N)");
    ch=getchar();
   
    if( ch != 'n' && ch != 'N' )
    {
        
int times = 5 , scorel ;
        
        for( scorel = 100 ; times-- ; scorel /= 10 )
        {
            
#define FMT1 printf("\t\t\t\t ") ;
            
#define FMT2(l , u) if(s>=70) printf("%d~%d分" , l , u ); else printf("不及格");
            
#define FMT3 printf("学员信息列表\n        \t\t\t班级\t编号\t姓名\tC语言\n");
            
            
#define FMT (l , u) FMT1 FMT2(l , u) FMT3
            
            
int i ;
            
            for( i=1 ; i<now_no && stu[i].name[0] ; i++ )
            {
               
FMT( scorel/10 ,scorel ) ;
               
                if ( ( stu[i].score1 >= scorel/10 ) && ( stu[i].score1 <= scorel ) )
                    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);
                getch();
            }
        }
            
        
fflush(stdin);
        system("cls");
    }
}


[[it] 本帖最后由 死了都要C 于 2008-7-4 00:35 编辑 [/it]]

[[it] 本帖最后由 死了都要C 于 2008-7-4 00:40 编辑 [/it]]

女施主``我给你``送茶来了```师太``你就从了老衲吧``
代码本天成~~~妙头偶得之```
2008-07-04 00:33
死了都要C
Rank: 4
来 自:四川成都
等 级:贵宾
威 望:13
帖 子:1582
专家分:116
注 册:2006-12-7
得分:0 
对分数段单纯的修改``没有调试过的``不知道可以不可以

女施主``我给你``送茶来了```师太``你就从了老衲吧``
代码本天成~~~妙头偶得之```
2008-07-04 00:36
robert0415
Rank: 1
等 级:禁止访问
帖 子:29
专家分:0
注 册:2008-7-3
得分:0 
好东西顶
2008-07-04 12:30
akkabc
Rank: 1
来 自:信宜
等 级:新手上路
帖 子:6
专家分:0
注 册:2010-3-1
得分:0 
那个display好像没有声明耶~~
2010-03-03 19:16
luquanzhang
Rank: 1
等 级:新手上路
帖 子:11
专家分:0
注 册:2010-3-17
得分:0 
程序叫我们重定义DISPLAY
2010-03-18 21:03
stldsm
Rank: 1
等 级:新手上路
帖 子:5
专家分:0
注 册:2010-5-9
得分:0 
强大的人
2010-05-23 10:14



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-222297-1-1.html




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

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