| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 745 人关注过本帖, 2 人收藏
标题:学完数据结构编的课程设计
取消只看楼主 加入收藏
树上月
Rank: 3Rank: 3
等 级:论坛游侠
威 望:1
帖 子:114
专家分:154
注 册:2010-1-6
结帖率:87.5%
收藏(2)
 问题点数:0 回复次数:0 
学完数据结构编的课程设计
// 学生管理系统.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include "stdio.h"
#include "string.h"
#include "stdlib.h"



//定义结构体
//学生成绩信息
 struct Stud_grade{
    int Math;                     //高数
    int English;                 //英语
    int Physics;                 //大学物理
    int Data_structure;          //数据结构
    int sum;                     //总分
};

// 学生基本信息
 typedef struct Stud_information{
    char telephone[13];                   //电话号码
    char number[13];                      //学号
    char name[15];                       //姓名
    char sex[10];                        //性别
    char birthday[15];                   //生日
    Stud_grade  grade;                  //成绩信息
    struct Stud_information *next;
 }*Stud_im;

//定义单链表头结点
typedef struct Node{
    int data;                                         
    struct Stud_information * next;      //指针域,链接节点
}*Slist;



//定义全局变量
Slist sl,sk;                              
Stud_im st;
char *p = "xsglxt1.txt";                   //定义字符指针
char *q = "xsglxt2.txt";                   //定义字符指针
FILE * fp, * fq;                          //定义文件指针


//初始化,生成表头
void InitNode(Slist &sl)
{
    sl = (Slist)malloc(sizeof(Node));
    sl->data = 0;
    sl->next = NULL;
}


//函数声明
void Insert_stud_number(Slist &sl,Stud_im l);          //声明插入函数
void Preserve_stud(Slist &sl);                         //声明保存函数
void Delets_stud(Slist &sl);                           //声明删除函数
void Revise_stud(Slist &sl);                           //声明修改函数


//输入学生信息
void Create_stud(Slist &sl)
{
    if((fp=fopen(p,"r"))==NULL){                //打开文件                  
        printf("打开失败!!!!\n");
        exit(0);
    }
    while(!feof(fp)){
        Stud_im l = (Stud_im)malloc(sizeof(Stud_information));         //定义节点,作为学号插入

        //从文件中录入学生信息
        fscanf(fp,"%s%s%s%s%s",&l->name,&l->number,&l->sex,&l->birthday,&l->telephone);
        fscanf(fp,"%d%d%d%d",&l->grade.English,&l->grade.Math,&l->grade.Physics,&l->grade.Data_structure);
        l->grade.sum = l->grade.Math + l->grade.English + l->grade.Data_structure + l->grade.Physics;
        l->next = NULL;
        Insert_stud_number(sl,l);                         //调用学号插入函数
    }
    if(fclose(fp)){                                       //关闭文件
        printf("关闭失败!!!!!\n");
        exit(0);
    }
    Preserve_stud(sl);                   //保存学生信息
    printf("已成功录入学生信息,按回车键开始操作!!!!......\n");
    getchar();
    system("cls");                                        //清屏函数
}


//判断是否为空
//为空返回0,否则返回1
int Judge_stud(Stud_im s)
{
    if(s==NULL){
        printf("内存为空!!!!....请先新建学生信息.......\n");
        printf("按回车键返回主菜单...");
        getchar();
        getchar();
        system("cls");
        return 0;
    }
    else
        return 1;
}



//选择函数,供删除时使用
void choose_Delet_stud(Slist &sl)
{
    while(1){
        printf("*******************1:删除学生信息           2:返回上级菜单**********************\n");
        int ch;
        scanf("%d",&ch);
        switch(ch){
        case 1:
            Delets_stud(sl);
            break;
        case 2:
            system("cls");
            return ;
        default :
            printf(">>>>>>>输入错误,请重新输入......\n");
            break;
        }
        if(ch==1||ch==2)
            break;
        }
}



//插入操作
void Insert_stud_number(Slist &sl,Stud_im l)
{
    Stud_im s = sl->next;

    //插入
    //表头为空,直接插入
    if(s==NULL)               
        sl->next = l;

    //表不为空
    //若该学生学号小于第一个学生,插入为第一节点
    else if(strcmp(l->number,sl->next->number)<0){
        l->next = sl->next;
        sl->next = l;
    }                                                     
   
    //学号大于链表第一个学生的学号      
    else{
        while(1){
            if(s->next==NULL)
                break;
            if(strcmp(l->number,s->next->number)<0){
                l->next = s->next;
                s->next = l;
                break;
            }
            s = s->next;
        }
        //若为最后一个节点,直接插入
        if(s->next==NULL)
            s->next = l;
    }
}



//显示操作
void Printf_stud_number_grade(Slist &sl)
{
    Stud_im s = sl->next;

    if(!Judge_stud(s))     //判空
        return ;

    printf("按学号先后顺序显示为:\n");
    int i = 1;                        // 显示学生信息
    while(1){
        if(s->next==NULL)
            break;
        getchar();
        printf("第%d个学生的信息:\n",i);
        printf("该生的姓名是:%s\n",s->name);
        printf("该生的学号是:%s\n",s->number);
        printf("该生的性别是:%s\n",s->sex);
        printf("该生的出生年月日是:%s\n",s->birthday);
        printf("该生的手机号码是:%s\n",s->telephone);
        printf("该生的高数成绩是:%d\n",s->grade.Math);
        printf("该生的英语成绩是:%d\n",s->grade.English);
        printf("该生的数据结构成绩是:%d\n",s->grade.Data_structure);
        printf("该生的物理成绩是:%d\n",s->grade.Physics);
        printf("该生的总分是:%d\n",s->grade.sum);
        printf("********************************************************************************");
        s = s->next;
        i++;
    }
    printf("显示完毕.......\n");
    printf("按回车键返回主菜单......\n");
    getchar();
    system("cls");                                                                     
}


//删除操作
void Delets_stud(Slist &sl)
{
    Stud_im s = sl->next;
    Stud_im p = s;
    char name[13],number[13];

    if(Judge_stud(s)==0)           //判空
        return ;

    while(1){
        printf("********************1:按学号删除            2:按姓名删除************************\n");
        int ch;   
        scanf("%d",&ch);
        switch(ch){
        case 1:
            printf("请输入你要删除学生的学号(09408400xxx):");
            scanf("%s",&number);
            break;
        case 2:
            printf("请输入你要删除学生的姓名:");
            scanf("%s",&name);
            break;
        default :
            printf(">>>>>>>输入错误,请重新输入......\n");
            break;
        }
        if(ch==1||ch==2)
            break;
    }

    //寻找学生,删除学生信息
    while(1){
        if(s->next==NULL)
            break;
        if((strcmp(name,s->name)==0)||(strcmp(number,s->number)==0)){
            printf("该生的信息是:\n");
            printf("姓名:%s\n学号:%s\n性别:%s\n",s->name,s->number,s->sex);
            printf("出生年月日:%s\n手机号码:%s\n",s->birthday,s->telephone);
            printf("高数成绩:%d\n英语成绩:%d\n",s->grade.Math,s->grade.English);
            printf("数据结构成绩:%d\n该生的物理成绩:%d\n总分:%d\n",s->grade.Data_structure,s->grade.Physics,s->grade.sum);
            printf("你是否确定删除该生信息......\n");
            while(1){
                printf("1:是......\n2:否........\n");
                int ch;
                scanf("%d",&ch);
                switch(ch){
                case 1:                               //删除学生信息
                    if((sl->next->name==s->name)||(sl->next->number==s->number))     //删除第一个学生的信息
                        sl->next=s->next;
                    else
                        p->next=s->next;                                                                                    
                    printf("已成功删除该生信息......\n");
                    Preserve_stud(sl);                                           //保存学生信息
                    choose_Delet_stud(sl);                                      //调用选择函数                                         
                    break;
                case 2:               
                    choose_Delet_stud(sl);
                    break;
                default :
                    printf(">>>>>>>输入错误,请重新输入......\n");
                    break;
                }
                if(ch==1||ch==2)
                    break;
            }
            break;
        }
        p = s;
        s = s->next;
    }

    //无该生信息
    if(s->next==NULL){
        printf("没有该生的信息!!!!!!.........\n");
        choose_Delet_stud(sl);
        }
}

//查询操作
void search_stud(Slist &sl)
{
    char name[13],number[13];

    Stud_im s = sl->next;
    if(!Judge_stud(s))
        return ;

    while(1){
        printf("********************1:按学号查询           2:按姓名查询 ************************\n");
        int ch;
        scanf("%d",&ch);
        switch(ch){
        case 1:
            printf("请输入你要查询的学生的学号(09408400xxx):");
            scanf("%s",&number);
            break;
        case 2:
            printf("请输入你要查询的学生的姓名:");
            scanf("%s",&name);
            break;
        default :
            printf(">>>>>>>输入错误,请重新输入......\n");
            break;
        }
        if(ch==1||ch==2)
            break;
    }

    while(1){
        if(s->next==NULL)
            break;
        if((strcmp(name,s->name)==0)||(strcmp(number,s->number)==0)){
            printf("该生的信息是:\n");
            printf("姓名:%s\n学号:%s\n性别:%s\n",s->name,s->number,s->sex);
            printf("出生年月日:%s\n手机号码:%s\n",s->birthday,s->telephone);
            printf("高数成绩:%d\n英语成绩:%d\n",s->grade.Math,s->grade.English);
            printf("数据结构成绩:%d\n该生的物理成绩:%d\n总分:%d\n",s->grade.Data_structure,s->grade.Physics,s->grade.sum);
            while(1){
                printf("********************1:继续查询            2:返回主菜单 *************************\n");
                int ch;
                scanf("%d",&ch);
                switch(ch){
                case 1:
                    search_stud(sl);
                    break;
                case 2:
                    system("cls");                                 
                    return;
                default :
                    printf(">>>>>>>输入错误,请重新输入......\n");
                    break;
                }
                if(ch==1||ch==2)
                    break;
            }
            break;
        }
        s = s->next;
    }

    if(s->next==NULL){
        printf("没有该生的信息!!!!!.......\n");
        while(1){
            printf("********************1:继续查询            2:返回主菜单 *************************\n");
            int ch;
            scanf("%d",&ch);
            switch(ch){
            case 1:
                search_stud(sl);
                break;
            case 2:
                system("cls");                                 
                return;
            default :
                printf(">>>>>>>输入错误,请重新输入......\n");
                break;
            }
            if(ch==1||ch==2)
                break;
        }
    }
}





//统计学生成绩,统计学生中单科成绩最高的,总分最高
void Vital_stud(Slist &sl)
{
    Stud_im s = sl->next;
    if(!Judge_stud(s)){
        printf("按回车键返回主菜单........\n");
        getchar();
        system("cls");
        return ;
    }
    Stud_im p,q,k,l,j;
    p = q = k = l = j = s;           //将第一个学生的信息复制给各个变量

    //统计学生成绩
    while(1){
        if(s->next==NULL)
            break;
        if(s->grade.Math > p->grade.Math)
            p = s;                                
        if(s->grade.English > q->grade.English)
            q = s;
        if(s->grade.Data_structure > k->grade.Data_structure)
            k = s;
        if(s->grade.Physics > l->grade.Physics)
            l = s;
        if(s->grade.sum > j->grade.sum)
            j = s;
        s = s->next;
    }
    printf("总分成绩最高的学生是:%s\t\t总分是:%d\n",j->name,j->grade.sum);
    printf("高等数学成绩最高的学生是:%s\t成绩是:%d\n",p->name,p->grade.Math);
    printf("大学英语成绩最高的学生是:%s\t成绩是:%d\n",q->name,q->grade.English);
    printf("数据结构成绩最高的学生是:%s\t成绩是:%d\n",k->name,k->grade.Data_structure);
    printf("大学物理成绩最高的同学是:%s\t成绩是:%d\n",l->name,l->grade.Physics);
    printf(">>>>>>>>>>>统计信息完毕..........\n按回车键返回主菜单.......\n");
    getchar();
    system("cls");                                 
}



//添加学生信息
void Add_stud(Slist &sl)
{

    //输入信息
    Stud_im l = (Stud_im)malloc(sizeof(Stud_information));

    printf("请输入你要添加的学生的姓名:");
    scanf("%s",&l->name);
    printf("请输入你要添加的学生的学号(09408400xxx):");
    scanf("%s",&l->number);
    printf("请输入你要添加的学生的性别(男:M;女:W):");
    scanf("%s",&l->sex);
    printf("请输入你要添加的学生的出生年月日(xxxx.xx.xx):");
    scanf("%s",&l->birthday);
    printf("请输入你要添加的学生的手机号码:");
    scanf("%s",&l->telephone);
    printf("请输入你要添加的学生的高数成绩:");
    scanf("%d",&l->grade.Math);
    printf("请输入你要添加的学生的英语成绩:");
    scanf("%d",&l->grade.English);
    printf("请输入你要添加的学生的数据结构成绩:");
    scanf("%d",&l->grade.Data_structure);
    printf("请输入你要添加的学生的物理成绩:");
    scanf("%d",&l->grade.Physics);
    l->grade.sum=l->grade.Math+l->grade.English+l->grade.Data_structure+l->grade.Physics;
    Insert_stud_number(sl,l);            //调用插入函数
    printf("添加完毕!!!!!........\n");
    Preserve_stud(sl);                 //保存学生信息
    while(1){
        printf("********************1:继续添加            2:返回主菜单 *************************\n");
        int ch;
        scanf("%d",&ch);
        switch(ch){
        case 1:
            Add_stud(sl);
            break;
        case 2:
            system("cls");                                 
            break;
        default :
            printf(">>>>>>>输入错误,请重新输入......\n");
            break;
        }
        if(ch==1||ch==2)
            break;
    }
        
}

//保存学生信息   
void Preserve_stud(Slist &sl)
{
    Stud_im p = sl->next;

    if((fq=fopen(q,"w"))==NULL){                      //新建文件
        printf("打开失败!!!.......\n");
        exit(0);
    }

    fprintf(fq,"  姓名         学号       性别    出生日期       手机号码     ");
    fprintf(fq,"高等数学    大学英语     数据结构    大学物理    总 分\n");
    while(1){
        if(p->next==NULL)
            break;

        //向文件中录入信息
        fprintf(fp,"  %s      ",p->name);
        fprintf(fp,"%s    ",p->number);
        fprintf(fp,"%s    ",p->sex);
        fprintf(fp,"%s    ",p->birthday);
        fprintf(fp,"%s      ",p->telephone);
        fprintf(fp,"%d          ",p->grade.Math);
        fprintf(fp,"%d          ",p->grade.English);
        fprintf(fp,"%d          ",p->grade.Data_structure);
        fprintf(fp,"%d        ",p->grade.Physics);
        fprintf(fp,"%d\n",p->grade.sum);
        p=p->next;
    }
     if(fclose(fp)){                                    //关闭文件
        printf("关闭失败!!!!........\n");
        exit(0);
    }
    printf(">>>>>>>>>>保存成功(保存在xsglxt2.txt文档中)........\n");
}

//修改操作
//修改学生信息
void Revise_stud(Slist &sl)
{
    char name[10],number[13];
    while(1){
        printf("********************1:按学号修改           2:按姓名修改*************************\n");
        int ch;
        scanf("%d",&ch);
        switch(ch){
        case 1:
            printf("请输入你要修改学生的学号:");
            scanf("%s",&number);
            break;
        case 2:
            printf("请输入你要修改学生的姓名:");
            scanf("%s",&name);
            break;
        default :
            printf(">>>>>>>输入错误,请重新输入......\n");
            break;
        }
        if(ch==1||ch==2)
            break;
    }

    //修改学生信息
    Stud_im s = sl->next;
    while(1){
        if(s==NULL)
            break;
        if((strcmp(name,s->name)==0)||(strcmp(number,s->number)==0)){
            printf("请输入修改后的姓名(原姓名是:%s):",s->name);
            scanf("%s",&s->name);
            printf("请输入修改后的学号(原学号是:%s):",s->number);
            scanf("%s",&s->number);
            printf("请输入修改后的性别(原性别是:%s):",s->sex);
            scanf("%s",&s->sex);
            printf("请输入修改后的出生年月日(原出生年月日是:%s):",s->birthday);
            scanf("%s",&s->birthday);
            printf("请输入修改后的手机号码(原手机号码是:%s):",s->telephone);
            scanf("%s",&s->telephone);
            printf("请输入修改后的高数成绩(原高数成绩是:%d):",s->grade.Math);
            scanf("%d",&s->grade.Math);
            printf("请输入修改后的英语成绩(英语成绩是:%d):",s->grade.English);
            scanf("%d",&s->grade.English);
            printf("请输入修改后的数据结构成绩(原数据结构成绩是:%d):",s->grade.Data_structure);
            scanf("%d",&s->grade.Data_structure);
            printf("请输入修改后的物理成绩(物理成绩是:%d):",s->grade.Physics);
            scanf("%d",&s->grade.Physics);
            s->grade.sum = s->grade.Math + s->grade.English + s->grade.Data_structure + s->grade.Physics;

            printf(">>>>>>>>>>修改完毕!!!!.........\n");
            while(1){
                printf("********************1:继续修改            2:返回主菜单 *************************\n");
                int ch;
                scanf("%d",&ch);
                switch(ch){
                case 1:
                    Revise_stud(sl);
                    break;
                case 2:
                    system("cls");                                 
                    return;
                default :
                    printf(">>>>>>>输入错误,请重新输入......\n");
                    break;
                }
                if(ch==1||ch==2)
                    break;
            }
        }
        s = s->next;
    }
   
    if(s==NULL){
        printf("没有该学生!!!!.......\n");
        while(1){
            printf("********************1:继续修改            2:返回主菜单 **************************\n");
            int ch;
            scanf("%d",&ch);
            switch(ch){
            case 1:
                Revise_stud(sl);
                break;
            case 2:
                system("cls");                                 
                return;
            default :
                printf(">>>>>>>输入错误,请重新输入......\n");
                break;
            }
            if(ch==1||ch==2)
                break;
        }
    }
}

//操作函数 ,提供主选菜单
int menu(Slist &sl)         
{     
    printf("********************************************************************************");
    printf("*                            欢迎进入学生管理系统                             *\n");
    printf("*                                                     ____网络091班     陈明  *\n");
    printf("********************************************************************************");
    printf("*\t1:删除学生信息\t\t\t\t\t2:查询学生信息        *\n");
    printf("*\t3:修改学生信息\t\t\t\t\t4:显示学生信息        *\n");
    printf("*\t5:添加学生信息\t\t\t\t\t6:统计学生成绩        *\n");  
    printf("*\t0:退出系统    \t\t\t\t\t                      *\n");
    printf("********************************************************************************\n");
    int choice;
    printf("输入你的选择:");
       scanf("%d",&choice);
    getchar();
       switch(choice){
       case 1:
           Delets_stud(sl);
           return 1;
       case 2:
           search_stud(sl);
        return 2;
       case 3:
           Revise_stud(sl);
        return 3;
    case 4:
        Printf_stud_number_grade(sl);
        return 4;
       case 5:
           Add_stud(sl);
         return 5;
    case 6:
        Vital_stud(sl);
        return 6;
       case 0:
        return 0;
    default:
        printf("无此项操作,请重新输入.....\n");
        return 7;
    }   
}

//主函数
int main(int argc, char* argv[])
{
    InitNode(sl);           //初始化单链表sl
    Create_stud(sl);        //录入学生信息
              
    while(1)
    {
        if(menu(sl)==0)   //操作函数 ,函数入口
            break;
    }
    printf("                   ________谢谢使用此软件!!!!.....\n");
    return 0;   
}
搜索更多相关主题的帖子: 数据结构 课程 设计 
2010-10-21 17:43
快速回复:学完数据结构编的课程设计
数据加载中...
 
   



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

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