| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 535 人关注过本帖
标题:C语言写了个学生成绩管理系统,有些小问题想请教一下
取消只看楼主 加入收藏
minkii
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2015-7-2
结帖率:0
收藏
已结贴  问题点数:20 回复次数:0 
C语言写了个学生成绩管理系统,有些小问题想请教一下
有很多小问题,能运行,但是菜单那些功能都不能实现,希望能有高手指点一下,万分感谢!


#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <windows.h>
#include <conio.h>
#include <ctype.h>


typedef struct _Node
{
    char szNo[3];
    char szName[32];
    char szSex[8];  //"man" or "woman"
    int nChinese;
    int nEnglish;
    int nMath;
    int nDesign;
    int nJava;
    int nTotal;
    float nAvg;
    struct _Node *next;
}Node, *pNode;

pNode head = NULL;

void gotoxy(int x, int y)             //移动光标位置函数
{
    COORD pos;
    pos.X = x - 1;
    pos.Y = y - 1;
    SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE),pos);
}


void load(void)        //开始及登陆界面
{
    int n = 0;
    FILE *fp1, *fp2;
    char name[20];
    char loadingname[20];
    char password[20];                    
    char loadingpassword[20];
    gotoxy(20, 3);
    printf("---------欢迎使用学生成绩管理系统---------");    //开始界面
    fp1 = fopen("d:\\用户名.txt", "r");            //打开用户名文件
    fp2 = fopen("d:\\密码.txt", "r");            //打开密码文件
    if (fp1 == NULL || fp2 == NULL)        //打开文件有错
    {
        system("cls");
        gotoxy(33, 8);
        printf("打开文件出错");        
        gotoxy(33,10);
        printf("程序将自动结束");
        gotoxy(33,12);
        exit(1);
    }
    else
    {        
        gotoxy(32, 9);                    //开始用户名输入
        printf("请输入用户名和密码");
        gotoxy(25, 13);
        printf("用户名:");
        gotoxy(25, 15);
        printf("密  码:");
        gotoxy(36, 13);
        scanf("%s", name);
        gotoxy(36, 15);            //完成对密码和用户名的输入
        while(n < 10 && password[n - 1] != '\r')
        {
               
            password[n++] = getch();               
            if (password[n-1] != '\b')  //如果输入的不是退格
            {
                putchar('*');
            }
            else
            {
                if (n > 1)                //当有输入密码时退格
                {
                    printf("\b \b");        //把光标往回移动一格,打印一个空格,再往回移动一格
                }
                n = n - 2;
                if (n < 0)
                {
                    n = 0;
                }
            }
        }
        password[n - 1] = '\0';   
        n = 0;   
        fscanf(fp1, "%s", loadingname);
        fscanf(fp2, "%s", loadingpassword);
        if ((strcmp(name, loadingname) == 0) &&(strcmp(password, loadingpassword) == 0))
        {
            gotoxy(25, 17);
            printf("用户名和密码输入正确,按回车键进入菜单");
            fflush(stdin);                                                                //清空输入缓冲
            getchar();
            system("cls");
               
        }
        else
        {
            system("cls");
            gotoxy(34, 10);   
            printf("用户名或密码错误!");
            gotoxy(39, 12);   
            printf("程序关闭");
            gotoxy(30, 14);   
            exit(0);
        }
   

            system("cls");
        
    }
   
   
    fclose(fp1);
    fclose(fp2);
}

void CreateNode(Node data)
{
    char szData[1024] = "\0";
    FILE *fp = NULL;
    pNode temp = (pNode)malloc(sizeof(Node));
   
    strcpy(temp->szNo, data.szNo);
    strcpy(temp->szName, data.szName);
    strcpy(temp->szSex, data.szSex);
    temp->nChinese = data.nChinese;
    temp->nEnglish = data.nEnglish;
    temp->nMath = data.nMath;
    temp->nDesign = data.nDesign;
    temp->nJava = data.nJava;
   
    temp->nTotal = temp->nChinese + temp->nEnglish + temp->nMath + temp->nDesign + temp->nJava;
    temp->nAvg = (float)temp->nTotal / 5;
    temp->next = NULL;

    sprintf(szData, "%s|%s|%s|%d|%d|%d|%d|%d|%d|%f\r\n", data.szNo, data.szName, data.szSex,
        data.nChinese, data.nMath, data.nEnglish, data.nDesign, data.nJava, temp->nTotal, temp->nAvg);

    fp = fopen("D:\\Data.txt", "ab+");
    fputs(szData, fp);
    fclose(fp);
   
    if(NULL == head)
    {
        head = temp;
    }
    else
    {
        pNode p = head->next;
        while(p != NULL)
        {
            p = p->next;
        }
        p->next = temp;
    }
    system("cls");
}

//返回1表示不存在更改的这个节点
int UpdateNode(Node data)
{
    char szData[1024] = "\0";
    pNode temp = NULL;
    if(NULL == head)
        return 1;

    temp = head;
    while(0 != strcmp(temp->szNo, data.szNo) && NULL != temp)
    {
        temp = temp->next;
    }

    if(NULL == temp)
    {
        return 1;
    }

    strcpy(temp->szNo, data.szNo);
    strcpy(temp->szName, data.szName);
    strcpy(temp->szSex, data.szSex);
    temp->nChinese = data.nChinese;
    temp->nEnglish = data.nEnglish;
    temp->nMath = data.nMath;
    temp->nDesign = data.nDesign;
    temp->nJava = data.nJava;
   
    temp->nTotal = temp->nChinese + temp->nEnglish + temp->nMath + temp->nDesign + temp->nJava;
    temp->nAvg = temp->nTotal / 5;
    system("cls");
    return 0;
}

int DeleteNode(char *pNo)
{
    char szData[1024] = "\0";
    pNode back = NULL;
    pNode temp = NULL;
    if(NULL == head)
        return 1;

    if(0 == strcmp(head->szNo, pNo))
    {
        if(NULL == head->next)
        {
            free(head);
            head = NULL;
            return 0;
        }
        else
        {
            temp = head;
            head = head->next;
            free(temp);
            return 0;
        }
    }
    back = head;
    temp = head->next;
    while(0 == strcmp(temp->szNo, pNo) && NULL != temp)
    {
        back = back->next;
        temp = temp->next;
    }

    if(NULL == temp)
        return 1;

    back->next = temp->next;
    free(temp);
    temp = NULL;
    system("cls");
    return 0;
}

pNode QueryForNo(char *pNo)
{
    pNode temp = NULL;
    if(NULL == head)
        return NULL;
   
    if(0 == strcmp(head->szNo, pNo))
    {
        return head;
    }

    temp = head->next;
    while(0 == strcmp(temp->szNo, pNo) && NULL != temp)
    {
        temp = temp->next;
    }
   
    if(NULL == temp)
        return NULL;

    return temp;
}

void Input(pNode data)
{
    printf("Number:");
    scanf("%s", data->szNo);

    printf("Name:");
    scanf("%s", data->szName);

    printf("Sex:");
    scanf("%s", data->szSex);

    printf("Chinese:");
    scanf("%d", &data->nChinese);

    printf("Math:");
    scanf("%d", &data->nMath);

    printf("English:");
    scanf("%d", &data->nEnglish);

    printf("Design:");
    scanf("%d", &data->nDesign);

    printf("Java:");
    scanf("%d", &data->nJava);
}

void Print()
{
    printf("|%8s", "Number");
    printf("|%8s", "Name");
    printf("|%5s", "Sex");
    printf("|%s", "Chinese");
    printf("|%s", "Math");
    printf("|%s", "English");
    printf("|%s", "Design");
    printf("|%s", "Java");
    printf("|%s", "Total");
    printf("|%s", "Avg");
    printf("\n");
}

void Output(pNode data)
{
    printf("|%8s", data->szNo);
    printf("|%8s", data->szName);
    printf("|%5s", data->szSex);
    printf("|%7d", data->nChinese);
    printf("|%4d", data->nMath);
    printf("|%7d", data->nEnglish);
    printf("|%6d", data->nDesign);
    printf("|%4d", data->nJava);
    printf("|%5d", data->nTotal);
    printf("|%f", data->nAvg);
    printf("\n");
}

void OutputLowAvg()
{
    int nTotalChinese = 0;
    int nTotalMath = 0;
    int nTotalEnglish = 0;
    int nTotalDesign = 0;
    int nTotalJava = 0;

    int nCount = 0;

    float avgChinese = 0.0;
    float avgMath = 0.0;
    float avgEnglish = 0.0;
    float avgDesign = 0.0;
    float avgJava = 0.0;

    pNode temp = head;

    if(temp == NULL)
    {
        printf("无信息!\n");
        return;
    }

    while(NULL != temp)
    {
        nTotalChinese += temp->nChinese;
        nTotalMath += temp->nMath;
        nTotalEnglish += temp->nEnglish;
        nTotalDesign = temp->nDesign;
        nTotalJava = temp->nJava;
        nCount ++;
        temp = temp->next;
    }

    avgChinese = (float)nTotalChinese/nCount;
    avgMath = (float)nTotalMath/nCount;
    avgEnglish = (float)nTotalEnglish/nCount;
    avgDesign = (float)nTotalDesign/nCount;
    avgJava = (float)nTotalJava/nCount;

    temp = head;
    while(NULL != temp)
    {
        if(temp->nChinese < (int)avgChinese ||
            temp->nEnglish < (int)avgEnglish ||
            temp->nMath < (int)avgMath ||
            temp->nDesign < (int)avgDesign ||
            temp->nJava < (int)avgJava)
        {
            Output(temp);
        }

        temp = temp->next;
    }
}

void OutputUp90orLow60()
{
    pNode temp = head;
    if(temp == NULL)
    {
        printf("无信息!\n");
        return;
    }
    while(NULL != temp)
    {
        if(temp->nChinese > 90 || temp->nChinese < 60 ||
            temp->nMath > 90 || temp->nMath < 60 ||
            temp->nEnglish > 90 || temp->nEnglish < 60 ||
            temp->nDesign > 90 || temp->nDesign < 60 ||
            temp->nJava > 90 || temp->nJava < 60)
        {
            Output(temp);
        }
        temp = temp->next;
    }
}

void CreateList()
{
    char szData[1024] = "\0";
    pNode temp = NULL, p = NULL;
    FILE *fp = fopen("D:\\Data.txt", "r");
    if(NULL == fp)
        return ;

    while(fgets(szData, 1024, fp))
    {
        temp = (pNode)malloc(sizeof(Node));
        sscanf(szData, "%[^|]|%[^|]|%[^|]|%d|%d|%d|%d|%d|%d|%f", temp->szNo, temp->szName, temp->szSex,
            &temp->nChinese, &temp->nMath, &temp->nEnglish, &temp->nDesign, &temp->nJava, &temp->nTotal, &temp->nAvg);
        temp->next = NULL;
        if(NULL == head)
        {
            head = temp;
            p = head;
            continue;
        }

        p->next = temp;
        p = temp;
    }

    fclose(fp);
}

int main ()
{
    char szUserName[128] = "\0";
    char szPassword[128] = "\0";
    char szUser[128] = "\0";
    char szPass[128] = "\0";
    char szChoose[8] = "\0";
    Node data;
    char szNo[32] = "\0";
    int nChoose = 0;
    pNode temp = NULL;
    load();

    while(1)
    {
        memset(&data, 0, sizeof(data));
        gotoxy(27,3);
        printf("菜          单\n");
        printf("\n\t*************************************************\n");
        printf("\t\t1 增加学生信息\n");
        printf("\t\t2 修改学生信息\n");
        printf("\t\t3 删除学生信息\n");
        printf("\t\t4 查找学生信息\n");
        printf("\t\t5 输出统计数据\n");
        printf("\t\t6 输出低于平均分的学生信息\n");
        printf("\t\t7 输出高于90分和低于60分的学生信息\n");
        printf("\t\t8 退出\n");
        printf("\t*************************************************\n");
        printf("\n请选择:");
        scanf("%s", szChoose);
        nChoose = atoi(szChoose);
        if(nChoose < 1 || nChoose > 8)
        {
            printf("输入有误!\n请选择:");
            continue;
        }
        switch(nChoose)
        {
        case 1:
            Input(&data);
            CreateNode(data);
            break;
        case 2:
            Input(&data);
            if(1 == UpdateNode(data))
                printf("无该学生信息!\n");
            else
                printf("修改成功!\n");
            break;
        case 3:
            printf("请输入要修改的学生学号:");
            scanf("%s", szNo);
            if(1 == DeleteNode(szNo))
                printf("无该学生信息!\n");
            else
                printf("删除成功!\n");
            szNo[0] = '\0';
            break;
        case 4:
            printf("请输入要查找的学生学号:");
            scanf("%s", szNo);
            temp = QueryForNo(szNo);
            if(temp == NULL)
                printf("无该学生信息!\n");
            else
                Output(temp);
            temp = NULL;
            break;
        case 5:
            Print();
            temp = head;
            while(NULL != temp)
            {
                Output(temp);
                temp = temp->next;
            }
            break;
        case 6:
            Print();
            OutputLowAvg();
            break;
        case 7:
            Print();
            OutputUp90orLow60();
            break;
        }

        printf("\n\n");
    }   
   
    system( "pause");
    return 0;
}
图片附件: 游客没有浏览图片的权限,请 登录注册
搜索更多相关主题的帖子: 管理系统 include C语言 
2015-07-03 03:53
快速回复:C语言写了个学生成绩管理系统,有些小问题想请教一下
数据加载中...
 
   



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

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