注册 登录
编程论坛 数据结构与算法

小型学生管理系统

wbajieng 发布于 2010-04-21 16:32, 758 次点击
#include<stdio.h>
#include<malloc.h>
#include<stdlib.h>
#include<string.h>
typedef struct stu{
    char Name[15];
    char Id[15];
    int Com;
    int Math;
    int Eng;
    int Phy;
    stu * next;
}stu;
stu* s;
stu* Luru(void);
void Xiugai(stu* head);
void Delete(stu* head);
void Chaxun(stu* head);
int main()
{
    int n;
    printf("录入学生信息按1\n修改学生信息按2\n删除学生信息按3\n查询学生信息按4\n退出按0\n");
    scanf("%d",&n);
    while(n!=0){
            if(n==1) s=Luru();
            if(n==2) Xiugai(s);
            if(n==3) Delete(s);
            if(n==4) Chaxun(s);
            scanf("%d",&n);
            }
            system("pause");
            return 0;
}
stu* Luru(void){
    struct stu * head,*p,*q;
    int i,m;
    printf("请输入学生个数:");
        scanf("%d",&m);
    p=( stu * ) malloc(sizeof( stu));
    if(p==NULL) {
        printf("分配空间失败");
        exit(0);
    }        
        head=p;
    for(i=1;i<=m;i++){
        q=(struct stu * )malloc(sizeof(struct stu));
        if(q==NULL) {
        printf("分配空间失败");
        exit(0);
        }
            printf("姓名 学号 计算机 数学 英语 物理:");
            scanf("%s %s %d %d %d %d",q->Name,q->Id,&q->Com,&q->Math,&q->Eng,&q->Phy);
            p->next=q;
            p=q;
    }
    p->next=NULL;
    return head;
}
void Xiugai(stu* head){
    char a[15];
    stu* p;
    int k,i;
    printf("请输入要修改的学生数:");
    scanf("%d",&k);
    for(i=1;i<=k;i++){
        printf("请输入要修改的学生的学号:");
        scanf("%s",a);
        p=head;
        p=p->next;
        while(strcmp(a,p->Id)!=0)
        p=p->next;
        if(strcmp(a,p->Id)==0){
        printf("请重新输入该学生的信息:");
        scanf("%s %s %d %d %d %d",p->Name,p->Id,&p->Com,&p->Math,&p->Eng,&p->Phy);
        }
        else printf("学号有误,未找到");
        
    }
   
}
void Chaxun(stu* head){
        char a[15];
        stu* p;
        printf("请输入要查询学生的学号:(退出按0)");
        scanf("%s",a);
        while(strcmp(a,"0")!=0){
            p=head;
             p=p->next;
            while(strcmp(a,p->Id)!=0)
            p=p->next;
            if(strcmp(a,p->Id)==0)
                printf("姓名:%s 学号:%s 计算机:%d 数学:%d 英语:%d 物理:%d",p->Name,p->Id,p->Com,p->Math,p->Eng,p->Phy);
             else printf("学号有误。");
            scanf("%s",a);
        }
}
void Delete(stu* head){
    char a[15];
    stu* p;
    stu* q;
    printf("请输入要删除学生的学号:(退出按0)");
    scanf("%s",a);
    while(strcmp(a,"0")!=0){
        p=head;
        while(strcmp(a,p->next->Id)!=0)
            p=p->next;
        if(strcmp(a,p->next->Id)==0){
            q=p->next;
            p->next=p->next->next;
            free(q);
        }
        scanf("%s",a);
    }
}



   
   


   

4 回复
#2
寒风中的细雨2010-04-22 06:50
干什么?
#3
wbajieng2010-04-24 00:26
录入、修改、删除和查询学生信息
#4
寒风中的细雨2010-04-27 07:32
#include <stdio.h>
#include <malloc.h>
#include <stdlib.h>
#include <string.h>

typedef struct stu
{
    char Name[15];
    char Id[15];
    int Com;
    int Math;
    int Eng;
    int Phy;
    stu * next;
}stu;
stu* s = NULL;
stu* Luru(void);
void Xiugai(stu* head);
void Delete(stu* head);
void Chaxun(stu* head);
int main()
{
    int n;
    printf("录入学生信息按1\n修改学生信息按2\n删除学生信息按3\n查询学生信息按4\n退出按0\n");
    scanf("%d",&n);
    while(n!=0){
            if(n==1) s=Luru();
            if(n==2) Xiugai(s);
            if(n==3) Delete(s);
            if(n==4) Chaxun(s);
            scanf("%d",&n);
            }
            system("pause");
            return 0;
}

stu* Luru(void)
{
    struct stu * head = NULL,*p,*q;
    int i,m;
    printf("请输入学生个数:");
        scanf("%d",&m);
    p=( stu * ) malloc(sizeof( stu));
    if(p==NULL) {
        printf("分配空间失败");
        exit(0);
    }        
    head=p;
    for(i=1;i<=m;i++){
        q=(struct stu * )malloc(sizeof(struct stu));
        if(q==NULL) {
        printf("分配空间失败");
        exit(0);
        }
            printf("姓名 学号 计算机 数学 英语 物理:");
            scanf("%s %s %d %d %d %d",q->Name,q->Id,&q->Com,&q->Math,&q->Eng,&q->Phy);
            p->next=q;
            p=q;
    }
    p->next=NULL;
    printf("信息添加成功!\n");
    return head;
}
void Xiugai(stu* head)
{
    if( !head )
    {
        printf("No students msg!\n");
        return;
    }
    char a[15];
    stu* p;
    int k,i;
    printf("请输入要修改的学生数:");
    scanf("%d",&k);
    for(i=1;i<=k;i++){
        printf("请输入要修改的学生的学号:");
        scanf("%s",a);
        p=head;
        p=p->next;
        while(strcmp(a,p->Id)!=0)
        p=p->next;
        if(strcmp(a,p->Id)==0){
        printf("请重新输入该学生的信息:");
        scanf("%s %s %d %d %d %d",p->Name,p->Id,&p->Com,&p->Math,&p->Eng,&p->Phy);
        }
        else printf("学号有误,未找到");
        
    }
   
}
void Chaxun(stu* head)
{
    if( !head )
    {
        printf("No students msg!\n");
        return;
    }
        char a[15];
        stu* p;
        printf("请输入要查询学生的学号:(退出按0)");
        scanf("%s",a);
        while(strcmp(a,"0")!=0){
            p=head;
             p=p->next;
            while(strcmp(a,p->Id)!=0)
            p=p->next;
            if(strcmp(a,p->Id)==0)
                printf("姓名:%s 学号:%s 计算机:%d 数学:%d 英语:%d 物理:%d",p->Name,p->Id,p->Com,p->Math,p->Eng,p->Phy);
             else printf("学号有误。");
            scanf("%s",a);
        }
}
void Delete(stu* head){
    if( !head )
    {
        printf("No students msg!\n");
        return;
    }
    char a[15];
    stu* p;
    stu* q;
    printf("请输入要删除学生的学号:(退出按0)");
    scanf("%s",a);
    while(strcmp(a,"0")!=0){
        p=head;
        while(strcmp(a,p->next->Id)!=0)
            p=p->next;
        if(strcmp(a,p->next->Id)==0){
            q=p->next;
            p->next=p->next->next;
            free(q);
        }
        scanf("%s",a);
    }
}

#5
新绿2010-05-11 16:38
有什么不一样的?
1