baidu_27760583
2015-07-06 07:59
采纳率: 0%
浏览 1.9k

C语言学籍管理系统,我想添加专业和家庭地址的代码,求各位大神帮帮忙!小菜鸟我感激不尽啊啊啊啊

#include
#include
#include

#define M 2
void maininterface();
void findinterface();

void choice(long sno[], char sname[][20], int sage[], float cs[], int N);
void findchoice(long sno[], char sname[][20], int sage[], float cs[], int N);

void input(long sno[], char sname[][20], int sage[], float cs[], int N);
void output(long sno[], char sname[][20], int sage[], float cs[], int N);
void snofind(long sno[], char sname[][20], int sage[], float cs[], int N);
void snamefind(long sno[], char sname[][20], int sage[], float cs[], int N);
void cssort(long sno[], char sname[][20], int sage[], float cs[], int N);
void total(long sno[], char sname[][20], int sage[], float cs[], int N);

int main(int argc, char *argv[])
{
//变量及数组定义
long sno[M];
char sname[M][20];
int sage[M];
float cs[M];
int i, j;

//显示界面
maininterface();
//选择操作
choice(sno, sname, sage, cs, M);

system("pause");
return 0;

}

void maininterface()
{
printf("\t\t*********************************************\n");
printf("\t\t* 欢迎使用学籍管理系统 \n");
printf("\t\t*1.输入学生的基本信息 2.输出学生的信息 *\n ");
printf("\t\t*3.查找学生的基本信息 4.学生成绩排序 *\n ");
printf("\t\t*5.统计学生的成绩分布 0.退出 *\n ");
printf("\t\t
********************************************\n");
printf("\t\t请输入0--5: ");
}

void findinterface()
{
printf("\t\t*********************************************\n");
printf("\t\t* 欢迎使用查找操作 \n");
printf("\t\t*1.按学号查找 *\n ");
printf("\t\t*2.按姓名查找 *\n ");
printf("\t\t*0.返回上一级 *\n ");
printf("\t\t
************************************************\n");
printf("\t\t请输入0—2:");
}

void input(long sno[], char sname[][20], int sage[], float cs[], int N)
{
int i;
//输入N个学生的基本信息

printf("输入%d个学生的信息.\n", N);
for (i = 0; i < N; i++) 
{
    printf("\n输入第%d个学生的\n", i + 1);
    printf("学号:");
    scanf("%ld", &sno[i]);
    getchar();

    printf("姓名:");
    gets(sname[i]);

    printf("年龄:");
    scanf("%d", &sage[i]);

    printf("C语言成绩:");
    scanf("%f", &cs[i]);
}

}

void output(long sno[], char sname[][20], int sage[], float cs[], int N)
{
int i;

//输出N个学生的基本信息   
printf("\n%d个学生的基本信息为\n", N);
for (i = 0; i < N; i++) 
{       
    printf("%-10ld", sno[i]);       
    printf("%-16s", sname[i]);
    printf("%-4d", sage[i]);
    printf("%-6.0f", cs[i]);
    printf("\n");       
}   

}

void snofind(long sno[], char sname[][20], int sage[], float cs[], int N)
{
int i;
long sno1;

//按学号查找
printf("请输入您要查找的学号:") ;
scanf("%ld", &sno1);
for (i = 0; i < N; i++)
{
    if (sno[i] == sno1) 
        break;
}
if (i < N)
{
    printf("学号为%ld的学生的基本信息为:\n", sno1);
    printf("%-10ld", sno[i]);       
    printf("%-16s", sname[i]);
    printf("%-4d", sage[i]);
    printf("%-6.0f", cs[i]);
    printf("\n");       
}
else
    printf("你输入的学号不存在!\n"); 

}

void snamefind(long sno[], char sname[][20], int sage[], float cs[], int N)
{
int i;
char sname1[20];

//按姓名查找
printf("请输入您要查找的姓名:") ;
getchar();
gets(sname1);
for (i = 0; i < N; i++)
{
    if (strcmp(sname[i], sname1) == 0) 
        break;
}
if (i < N)
{
    printf("姓名为%s的学生的基本信息为:\n", sname1);
    printf("%-10ld", sno[i]);       
    //printf("%-16s", sname[i]);
    printf("%-4d", sage[i]);
    printf("%-6.0f", cs[i]);
    printf("\n");       
}
else
    printf("你输入的姓名不存在!\n"); 

}

void cssort(long sno[], char sname[][20], int sage[], float cs[], int N )
{
//按成绩降序排序
int i, j, k;
long tsno;
char tsname[20];
int tsage;
float tcs;

for (i = 0; i < N - 1; i++)
{
    k = i;
    for (j = i + 1; j < N; j++)
    {
        if (cs[j] > cs[k])
            k = j;
    }
    if (k != i)
    {
                                //交换下标i与k对应学生的信息 
        tsno = sno[i];
        sno[i] = sno[k];
        sno[k] = tsno;//交换学号

        strcpy(tsname, sname[i]) ;
        strcpy(sname[i], sname[k]);
        strcpy(sname[k], tsname);

        tsage = sage[i];
        sage[i] = sage[k];
        sage[k] = tsage;

        tcs = cs[i];
        cs[i] = cs[k];
        cs[k] = tcs;                
    }
}   

}

void total(long sno[], char sname[][20], int sage[], float cs[], int N)
{
//统计
int i;

//按优,良 ,不及格的顺序打印
printf("\n优(C语言成绩>=90)的学生为:\n") ;
for (i = 0; i < N; i++) 
{
    if (cs[i] >= 90)
    {
        printf("%-10ld", sno[i]);       
        printf("%-16s", sname[i]);
        //printf("%-4d", sage[i]);
        printf("%-6.0f", cs[i]);
        printf("\n");
    }
}

printf("\n良(80<=C语言成绩<90)的学生为:\n") ;
for (i = 0; i < N; i++) 
{
    if (cs[i] >= 80 && cs[i] < 90)
    {
        printf("%-10ld", sno[i]);       
        printf("%-16s", sname[i]);
        //printf("%-4d", sage[i]);
        printf("%-6.0f", cs[i]);
        printf("\n");
    }
}
printf("\n中(70<=C语言成绩<80)的学生为:\n") ;
for (i = 0; i < N; i++) 
{
    if (cs[i] >= 70 && cs[i] < 80)
    {
        printf("%-10ld", sno[i]);       
        printf("%-16s", sname[i]);
        //printf("%-4d", sage[i]);
        printf("%-6.0f", cs[i]);
        printf("\n");
    }
}
printf("\n及格(60<=C语言成绩<70)的学生为:\n") ;
for (i = 0; i < N; i++) 
{
    if (cs[i] >= 60 && cs[i] < 70)
    {
        printf("%-10ld", sno[i]);       
        printf("%-16s", sname[i]);
        //printf("%-4d", sage[i]);
        printf("%-6.0f", cs[i]);
        printf("\n");
    }
}

printf("\n不及格(C语言成绩<60)的学生为:\n") ;
for (i = 0; i < N; i++) 
{
    if (cs[i] < 60)
    {
        printf("%-10ld", sno[i]);       
        printf("%-16s", sname[i]);
        //printf("%-4d", sage[i]);
        printf("%-6.0f", cs[i]);
        printf("\n");
    }
}   

}

void choice(long sno[], char sname[][20], int sage[], float cs[], int N)
{
int m;

while (1)
{
    scanf("%d", &m);
    switch (m)
    {
        case 1: 
            input(sno, sname, sage, cs, N); 
            maininterface(); 
            break;
        case 2: 
            output(sno, sname, sage, cs, N); 
            maininterface(); 
            break;
        case 3: 
            findinterface();
            findchoice(sno, sname, sage, cs, N);
            break;
        case 4: 
            cssort(sno, sname, sage, cs, N); 
            break;
        case 5: 
            total(sno, sname, sage, cs, N);
            maininterface(); 
            break;
        case 0: 
            exit(1);
    }
}

}

void findchoice(long sno[], char sname[][20], int sage[], float cs[], int N)
{
int m;

while (1)
{
    scanf("%d", &m);
    switch (m)
    {
        case 1: 
            snofind(sno, sname, sage, cs, N); 
            findinterface(); 
            break;
        case 2: 
            snamefind(sno, sname, sage, cs, N); 
            findinterface(); 
            break;      
        case 0: 
            break;
    }
    if (m == 0) 
        break;
}
maininterface();

}

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

6条回答 默认 最新

  • baidu_27760583 2015-07-06 08:02

    时间紧迫!我很急很急

    点赞 打赏 评论
  • 91program 2015-07-06 10:40

    你很急,和别人没什么关系。
    你急,就请自己动手。增加字段,仿现有的字段进行增加与操作,然后调试程序即可。

    虽然说我说的话可能比较难说,但这是事实!天下没有免费的午餐!!!

    点赞 打赏 评论
  • blownewbee 2015-07-06 13:57

    你看到sno, sname, sage, cs这些了么?依葫芦画瓢加上两个类似的,比如spro saddr。
    模仿这种事情又不需要智商。

    点赞 打赏 评论
  • harrypaul 2015-07-08 12:50
    #include <stdio.h>
    #include <stdlib.h>
    #include <string.h>
    #define M 2
    void maininterface();
    void choice(long sno[], char sname[][20], int sage[], float cs[],char smajor[][20], char addr[][50], int N);
    void findchoice(long sno[], char sname[][20], int sage[], float cs[],char smajor[][20], char addr[][50], int N);
    void input(long sno[], char sname[][20], int sage[], float cs[],char smajor[][20], char addr[][50], int N);
    void output(long sno[], char sname[][20], int sage[], float cs[],char smajor[][20], char addr[][50], int N);
    void snofind(long sno[], char sname[][20], int sage[], float cs[],char smajor[][20], char addr[][50], int N);
    void snamefind(long sno[], char sname[][20], int sage[], float cs[],char smajor[][20], char addr[][50], int N);
    void cssort(long sno[], char sname[][20], int sage[], float cs[],char smajor[][20], char addr[][50], int N);
    void total(long sno[], char sname[][20], int age[], float cs[],char smajor[][20], char addr[][50], int N);
    
    
    int main(int argc, char *argv[])
    {
        // 变量及数组定义
        long sno[M] = { 0 };
        char sname[M][20] = { 0 };
        int sage[M] = { 0 };
        float cs[M] = { 0 } ;
        char smajor[M][20] = { 0 };
        char saddr[M][50] = { 0 };
        int i, j;
        // 显示界面
        maininterface();
        // 选择操作
        choice(sno, sname, sage, cs, smajor, saddr, M);
    
        system("pause");
        return 0;
    }
    
    
    void maininterface()
    {
        //system("cls");
        printf("\t\t*************************************************\n");
        printf("\t\t* 欢迎使用学籍管理系统                  \t*\n");
        printf("\t\t* 1.输入学生的基本信息 2.输出学生的信息 \t*\n");
        printf("\t\t* 3.查找学生的基本信息 4.学生成绩排序   \t*\n");
        printf("\t\t* 5.统计学生的成绩分布 0.退出           \t*\n");
        printf("\t\t*************************************************\n");
        printf("\t\t 请输入 0--5: ");
    }
    
    void findinterface()
    {
        ///system("cls");
        printf("\t\t*************************************************\n");
        printf("\t\t* 欢迎使用查找操作                              *\n");
        printf("\t\t* 1.按学号查找                                  *\n");
        printf("\t\t* 2.按姓名查找                                  *\n");
        printf("\t\t* 3.按专业查找                                  *\n");
        printf("\t\t* 4.按地址查找                                  *\n");
        printf("\t\t* 0.返回上一级                                  *\n");
        printf("\t\t*************************************************\n");
        printf("\t\t 请输入 0--4 : ");
    }
    
    void input(long sno[], char sname[][20], int sage[], float cs[], char smajor[][20], char saddr[][50], int N)
    {
        int i;
        // 输入N个学生的基本信息
        printf("输入%d个学生的信息.\n", N);
        for (i=0; i<N; i++)
        {
            printf("\n输入%d个学生的\n", i+1);
            printf("学号:");
            scanf("%ld", &sno[i]);
            getchar();
    
            printf("姓名:");
            gets(sname[i]);
    
            printf("年龄:");
            scanf("%d", &sage[i]);
    
            printf("C语言成绩");
            scanf("%f", &cs[i]);
            getchar();
    
            printf("专业:");
            gets(smajor[i]);
    
            printf("地址:");
            gets(saddr[i]);
    
        }
    }
    
    void output(long sno[], char sname[][20], int sage[], float cs[], char smajor[][20], char saddr[][50],int N)
    {
        int i;
        // 输出N个学生的基本信息
        printf("\n%d个学生的基本信息为\n", N);
        for ( i = 0; i < N; i++ )
        {
            printf("%-10ld", sno[i]);
            printf("%-16s", sname[i]);
            printf("%-4d", sage[i]);
            printf("%-6.0f", cs[i]);
            printf("%-16s", smajor[i]);
            printf("%-46s", saddr[i]);
            printf("\n");
        }
    }
    
    void snofind(long sno[], char sname[][20], int sage[], float cs[], char smajor[][20], char saddr[][50],int N)
    {
        int i;
        long sno_find;
        // 按学号查找
        printf("请输入您要查找的学号:");
        scanf("%ld", &sno_find);
        for ( i = 0; i < N; i++ )
        {
            if (sno[i] == sno_find)
            {
                break;
            }
        }
    
        if (i < N)
        {
            printf("学号为%ld的学生的基本信息为: \n", sno_find);
            printf("%-10ld", sno[i]);
            printf("%-16s", sname[i]);
            printf("%-4d", sage[i]);
            printf("%-6.0f", cs[i]);
            printf("%-16s", smajor[i]);
            printf("%-46s", saddr[i]);
            printf("\n");
        }
        else
        {
            printf("你输入的学号不存在!\n");
        }
    
    }
    
    void snamefind(long sno[], char sname[][20], int sage[], float cs[],char smajor[][20], char saddr[][50], int N)
    {
        int i;
        char sname_find[20];
        // 按姓名查找
        printf("请输入您要查找的姓名:");
        getchar();
        gets(sname_find);
        for ( i = 0; i < N; i++ )
        {
            if ( strcmp(sname[i], sname_find) == 0 )
            {
                break;
            }
        }
    
        if ( i < N )
        {
            printf("姓名为%s的学生的基本信息为:\n", sname_find);
            printf("%-10ld", sno[i]);
            printf("%-16s", sname[i]);
            printf("%-4d", sage[i]);
            printf("%-6.0f", cs[i]);
            printf("%-16s", smajor[i]);
            printf("%-46s", saddr[i]);
            printf("\n");
        }
        else
        {
            printf("您输入的姓名不存在!\n");
        }
    
    }
    
    void smajorfind(long sno[], char sname[][20], int sage[], float cs[],char smajor[][20], char saddr[][50], int N)
    {
        int i;
        char smajor_find[20];
        // 按姓名查找
        printf("请输入您要查找的姓名:");
        getchar();
        gets(smajor_find);
        for ( i = 0; i < N; i++ )
        {
            if ( strcmp(smajor[i], smajor_find) == 0 )
            {
                break;
            }
        }
    
        if ( i < N )
        {
            printf("专业为%s的学生的基本信息为:\n", smajor_find);
            printf("%-10ld", sno[i]);
            printf("%-16s", sname[i]);
            printf("%-4d", sage[i]);
            printf("%-6.0f", cs[i]);
            printf("%-16s", smajor[i]);
            printf("%-46s", saddr[i]);
            printf("\n");
        }
        else
        {
            printf("您输入的专业不存在!\n");
        }
    }
    
    
    void saddrfind(long sno[], char sname[][20], int sage[], float cs[],char smajor[][20], char saddr[][50], int N)
    {
        printf("请等待系统升级,此功能暂时不能使用,谢谢!\n");
    }
    
    
    
    void cssort(long sno[], char sname[][20], int sage[], float cs[],char smajor[][20], char saddr[][50], int N)
    {
        // 按成绩降序排序
        int i = 0, j = 0, k = 0;
        long tsno;
        char tsname[20];
        int tsage;
        float tcs;
        char tsmajor[20];
        char tsaddr[50];
    
        printf("正在排序....\n");
        for ( i = 0; i < N - 1; i++ )
        {
            k = i;
            for ( j = i + 1;  j < N; j++ )
            {
                if ( cs[j]  > cs[k])
                {
                    k = j;
                }
            }
    
            if ( k != i )
            {
                // 变换下标i 与 k 对应的学生信息
                tsno = sno[i];
                sno[i] = sno[k];
                sno[k] = tsno; // 变换学号
    
                strcpy(tsname, sname[i]);
                strcpy(sname[i], sname[k]);
                strcpy(sname[k], tsname);
    
                tsage = sage[i];
                sage[i] = sage[k];
                sage[k] = tsage;
    
                tcs = cs[i];
                cs[i] = cs[k];
                cs[k] = tcs;
    
                strcpy(tsmajor, smajor[i]);
                strcpy(smajor[i], smajor[k]);
                strcpy(smajor[k], tsmajor);
    
                strcpy(tsaddr, saddr[i]);
                strcpy(saddr[i], saddr[k]);
                strcpy(saddr[k], tsaddr);
            }
        }
    }
    
    void total(long sno[], char sname[][20], int sage[], float cs[],char smajor[][20], char saddr[][50], int N)
    {
        // 统计
        int i;
        // 按优、良、不及格的顺序打印
        printf("\n优(C语言成绩>=90) 的学生为:\n");
        for ( i=0; i<N; ++i )
        {
            if( cs[i] >= 90 )
            {
                printf("%-10ld", sno[i]);
                printf("%-16s", sname[i]);
                printf("%-4d", sage[i]);
                printf("%-6.0f", cs[i]);
                printf("%-16s", smajor[i]);
                printf("%-46s", saddr[i]);
                printf("\n");
            }
        }
    
        printf("\n 良(80<=C语言成绩<90 )的学生为:\n");
        for ( i = 0;  i < N; i++ )
        {
            if ( cs[i] >=80 && cs[i] < 90 )
            {
                printf("%-10ld", sno[i]);
                printf("%-16s", sname[i]);
                printf("%-4d", sage[i]);
                printf("%-6.0f", cs[i]);
                printf("%-16s", smajor[i]);
                printf("%-46s", saddr[i]);
                printf("\n");
            }
        }
    
    
        printf("\n 中(70<=C语言成绩<80 )的学生为:\n");
        for ( i = 0;  i < N; i++ )
        {
            if ( cs[i] >=70 && cs[i] < 80 )
            {
                printf("%-10ld", sno[i]);
                printf("%-16s", sname[i]);
                printf("%-4d", sage[i]);
                printf("%-6.0f", cs[i]);
                printf("%-16s", smajor[i]);
                printf("%-46s", saddr[i]);
                printf("\n");
            }
        }
    
    
        printf("\n 及格(60<=C语言成绩<70 )的学生为:\n");
        for ( i = 0;  i < N; i++ )
        {
            if ( cs[i] >=60 && cs[i] < 70 )
            {
                printf("%-10ld", sno[i]);
                printf("%-16s", sname[i]);
                printf("%-4d", sage[i]);
                printf("%-6.0f", cs[i]);
                printf("%-16s", smajor[i]);
                printf("%-46s", saddr[i]);
                printf("\n");
            }
        }
    
        printf("\n 不及格(C语言成绩<60 )的学生为:\n");
        for ( i = 0;  i < N; i++ )
        {
            if ( cs[i] < 60 )
            {
                printf("%-10ld", sno[i]);
                printf("%-16s", sname[i]);
                printf("%-4d", sage[i]);
                printf("%-6.0f", cs[i]);
                printf("%-16s", smajor[i]);
                printf("%-46s", saddr[i]);
                printf("\n");
            }
        }
    }
    
    void choice(long sno[], char sname[][20], int sage[], float cs[],char smajor[][20], char saddr[][50], int N)
    {
        int m;
        while ( 1 )
        {
            scanf("%d", &m);    
            switch( m )
            {
                case 1:
                    input(sno, sname, sage, cs, smajor, saddr, N);
                    maininterface();
                    break;
                case 2:
                    output(sno, sname, sage, cs,smajor, saddr,  N);
                    maininterface();
                    break;
                case 3:
                    findinterface();
                    findchoice(sno, sname, sage, cs,smajor, saddr,  N);
                    break;
                case 4:
                    cssort(sno, sname, sage, cs, smajor, saddr,  N);
                    output(sno, sname, sage, cs,smajor, saddr,  N);
                    maininterface();
                    break;
                case 5:
                    total(sno, sname, sage, cs,smajor, saddr,  N);
                    maininterface();
                    break;
                case 0:
                    exit(1);
            }
        }
    }
    
    
    void findchoice(long sno[], char sname[][20], int sage[], float cs[],char smajor[][20], char saddr[][50], int N)
    {
        int m;
        while ( 1 )
        {
            scanf("%d", &m);
            switch ( m )
            {
                case 1:
                    snofind(sno, sname, sage, cs,smajor, saddr,  N);
                    findinterface();
                    break;
                case 2:
                    snamefind(sno, sname, sage, cs, smajor, saddr, N);
                    findinterface();
                    break;
                case 3:
                    smajorfind(sno, sname, sage, cs, smajor, saddr, N);
                    findinterface();
                    break;
                case 4:
                    saddrfind(sno, sname, sage, cs, smajor, saddr, N);
                    findinterface();
                    break;
                case 0:
                    break;
            }
            if ( m==0 )
            {
                break;
            }
        }
        maininterface();
    }
    
    
    
    点赞 打赏 评论
  • harrypaul 2015-07-08 12:53

    good luck! do it yourself.

    点赞 打赏 评论
  • newthguo 2015-07-09 02:32

    long sno[M];
    char sname[M][20];
    char smajor[M][20];
    char sadress[M][40];
    int sage[M];
    float cs[M];
    多定义这些变量 然后根据变量加初始化打印等等 用工具试试就知道了

    点赞 打赏 评论

相关推荐 更多相似问题