| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 349 人关注过本帖, 1 人收藏
标题:C语言课程设计,删除模块程序求解
只看楼主 加入收藏
w737056091
Rank: 1
等 级:新手上路
帖 子:5
专家分:0
注 册:2014-5-24
结帖率:0
收藏(1)
 问题点数:0 回复次数:1 
C语言课程设计,删除模块程序求解
程序代码:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define SIZE 10
struct student
{
    char name[20];              /*姓名*/
    char num[20];               /*学号*/
    double dchinese;            /*语文*/
    double dmath;               /*数学*/
    double denglish;            /*英语*/
    double daverage;            /*平均成绩*/
};
void Del();
int i,s,j,n=0,x,y;
int main ()
{

    FILE *fp;
    char name[20],num[10];
    int dchinese,dmath,denglish;

 
    int choice1=1,choice2;
    do
    {      //主界面
        printf("\t===============欢迎进入学生管理系统=================\n");
        printf("\t|                                                  |\n");
        printf("\t|                 *输入序号选择功能                |\n");
        printf("\t|                                                  |\n");
        printf("\t|                  1、信息编辑                     |\n");
        printf("\t|                                                  |\n");
        printf("\t|                  2、信息查询                     |\n");
        printf("\t|                                                  |\n");
        printf("\t|                  3、显示全部信息                 |\n");
        printf("\t|                                                  |\n");
        printf("\t|                  4、成绩排序                     |\n");
        printf("\t|                                                  |\n");
        printf("\t|                  5、程序结束                     |\n");
        printf("\t|                                                  |\n");
        printf("\t====================================================\n");
        scanf("%d", &choice1);
        system("cls");
   
        switch (choice1)
        {
        case 1:
            printf("\t====================================================\n");
            printf("\t|                欢迎进入信息维护系统              |\n");
            printf("\t|                                                  |\n");
            printf("\t|                  1、增加学生信息                 |\n");
            printf("\t|                                                  |\n");
            printf("\t|                  2、删除学生信息                 |\n");
            printf("\t|                                                  |\n");
            printf("\t|                  3、插入学生信息                 |\n");
            printf("\t|                                                  |\n");
            printf("\t|                 请输入序号选择功能               |\n");
            printf("\t====================================================\n");
            scanf("%d", &choice2);
            system("cls");
            switch (choice2)
            {
            case 1:    //增加学生信息;
                printf("\t================================================\n");
                printf("\t|            欢迎进入增加学生信息界面          |\n");
                printf("\t|                                              |\n");
                printf("\t|    姓名    学号    语文    数学    英语      |\n");
                printf("\t|                                              |\n");
                printf("\t| 如:xxx      01      90      96      98       |\n");
                printf("\t================================================\n");
                scanf ("%d",&choice1);
                scanf ("%s %s %d %d %d",name,num,&dchinese,&dmath,&denglish);
                system("cls");
                fp = fopen("student_1.txt","a");
                fprintf(fp,"%s\t%s\t%d\t%d\t%d\n",name,num,dchinese,dmath,denglish);
                fclose (fp);
                fp = fopen ("student_2.txt","w");
                fscanf(fp,"%d",&n);
                fclose(fp);
                fp=fopen ("student_2.txt","w");
                fprintf(fp,"%d",n+1);
                fclose(fp);
                printf("\t*****************************************\n");
                printf("\t*************  信息增加成功 **************\n");
                break;
       
            case 2:       //删除学生信息
                system("cls");
                printf("\t====================================================\n");
                printf("\t|             欢迎进入删除学生信息界面             |\n");
                printf("\t|                                                  |\n");
                printf("\t|              输入您要删除学生的姓名              |\n");
                printf("\t====================================================\n");
                Del();
                break;
            case 3:  //插入学生信息
                printf("\t================================================\n");
                printf("\t***         欢迎进入插入学生信息界面        ****\n");
                printf("\t*                                              *\n");
                printf("\t*             1、按学号高低插入信息            *\n");
                printf("\t*                                              *\n");
                printf("\t*             2、按平均成绩插入高低信息        *\n");
                printf("\t*                                              *\n");
                printf("\t*              请输入序号选择功能              *\n");
                printf("\t================================================\n");
                scanf ("%d",&choice1);
                system("cls");
                break;
            }
            printf("\t================================================\n");
            printf("\t*                返回上级请按 0                *\n");
            printf("\t*                                              *\n");
            printf("\t*                退出程序请按 5                *\n");
            printf("\t================================================\n");
            scanf("%d", &choice1);
            break;
       
        case 2:            
            printf("\t================================================\n");
            printf("\t*              欢迎进入成绩查询系统            *\n");
            printf("\t|                                              |\n");
            printf("\t***             1、按学号查询信息            ***\n");
            printf("\t|                                              |\n");
            printf("\t*****           2、按姓名查询信息         ******\n");
            printf("\t|                                              |\n");
            printf("\t********            输入序号          **********\n");
            printf("\t================================================\n");
            scanf("%d", &choice2);
            system("cls");
            switch (choice2)
            {
            case 1: //按学号查询
                printf("\t================================================\n");
                printf("\t**                                            **\n");
                printf("\t**            欢迎进入成绩查询系统            **\n");
                printf("\t**                                            **\n");
                printf("\t**vv****        按学号查询信息        ****vv****\n");
                printf("\t**                                            **\n");
                printf("\t**              请输入学生学号                **\n");
                printf("\t**                                            **\n");
                printf("\t================================================\n");
                system("cls");
                break;
            case 2:  //按照姓名查询
                printf("\t================================================\n");
                printf("\t*             欢迎进入成绩查询系统             *\n");
                printf("\t*                                              *\n");
                printf("\t**vv****         按姓名查询信息         *vv*****\n");
                printf("\t*                                              *\n");
                printf("\t*                 请输入学生姓名               *\n");
                printf("\t================================================\n");
                system("cls");
                break;
            }
            printf("\t*****************************************\n");
            printf("\t*         返回上级菜单请按 0            *\n");
            printf("\t*                                       *\n");
            printf("\t*         退出程序请按 5                *\n");
            printf("\t*****************************************\n");
            scanf("%d", &choice1);
            break;
        case 3:
            /*编写输出显示所有同学信息程序*/
            break;
        case 4://成绩排序
            printf("\t================================================\n");
            printf("\t    ***    欢迎进入学生成绩排序系统    ***      \n");
            printf("\t    ***                                ***      \n");
            printf("\t    ***      * 1、按学生学号排序 *     ***      \n");
            printf("\t                                                \n");
            printf("\t    ***      * 2、按平均成绩排序 *     ***      \n");
            printf("\t                                                \n");
            printf("\t    ***      * 输入序号选择功能  *     ***      \n");
            printf("\t================================================\n");
            scanf("%d", &choice2);
            system("cls");
            printf("\tXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\n");
            printf("\t**        返回上级菜单请按 0           **\n");
            printf("\t*****************************************\n");
            printf("\t***       退出程序请按 5             ****\n");
            printf("\tXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\n");
            scanf ("%d",&choice1);
            break;
            }
            system("cls");
    }while (choice1 != 5);
    printf("\t                                                      \n");
    printf("\t********************** 程序结束 **********************\n");
    printf("\t                                                      \n");
    return 0;
}
void Del()      //删除函数
{
    struct student *p;
    char name[20];
    FILE *fp;
    fp = fopen ("student_2.txt","r+");
    fscanf(fp,"%d",&n);
    fclose (fp);
    fp = fopen ("student_1.txt","r");
    p = (struct student *)malloc (n * sizeof(struct student));
    for (i=0;i<n;i++)
    {
        fscanf (fp,"%s",p[i].name);
        fscanf (fp,"%s",p[i].num);
        fscanf (fp,"%d",&p[i].dchinese);
        fscanf (fp,"%d",&p[i].dmath);
        fscanf (fp,"%d",&p[i].denglish);
    }
    fclose (fp);
    scanf("%s",name);
    fp = fopen ("student_1.txt","w");
    for (i=0;i<n;i++)
    {
        if(strcmp(name,p[i].name) == 0 )
        {
            s=i;
            break;
        for (i=i;i<n;i++)
            {
                strcpy(p[i].name,p[i+1].name);
                strcpy(p[i].num,p[i+1].num);
                p[i].dchinese = p[i+1].dchinese;
                p[i].dmath = p[i+1].dmath;
                p[i].denglish = p[i+1].denglish;
            }
        }
    }
    for(i=0;i<n-1;i++)
    {
        if(i==s)
        {
            continue;
        }
        fprintf (fp,"%s\t%s\t%d\t%d\t%d\n",p[i].name,p[i].num,p[i].dchinese,p[i].dmath,p[i].denglish);
    }
        fclose(fp);
        fp=fopen ("student_2.txt","w");
        fprintf(fp,"%d",n-1);
        free(p);
        fclose(fp);
   
        printf("\t********* 信息删除成功 ************\n");
}

后面的删除程序可以运行,但是我的本意是删除我输入的相关内容,而程序则是删除了所有数据,
各位大神能告诉我错在哪儿吗?
搜索更多相关主题的帖子: C语言 课程 
2014-09-15 17:35
w737056091
Rank: 1
等 级:新手上路
帖 子:5
专家分:0
注 册:2014-5-24
收藏
得分:0 
有部分数据还有编好,重点是,麻烦各位帮忙看看删除为何不对,怎么修改?我看了半天了,没搞定
2014-09-15 17:36
快速回复:C语言课程设计,删除模块程序求解
数据加载中...
 
   



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

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