| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 466 人关注过本帖
标题:成绩管理系统
只看楼主 加入收藏
black1234
Rank: 1
等 级:新手上路
帖 子:5
专家分:0
注 册:2014-6-17
结帖率:100%
收藏
 问题点数:0 回复次数:1 
成绩管理系统
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <malloc.h>
enum
{
    TypeFind,
    TypeAdd,
    TypeUpdate_Name,
    TypeUpdate_Tel,
    TypeDelete,
};

struct Student
{
    char ID[10];
    char name[20];
    int c1;
    int c2;
    int c3;
    struct Student*next;
};
typedef struct Student Stu,*pStu;
void input(char *name,char *ID,int *c1,int *c2,int *c3,int type)
{
    switch(type)
    {
        case TypeAdd:
            printf("[Add] input[name] [ID] [数学] [语文] [英语]: \n");
            break;
        case TypeFind:
            printf("[Find] input telbook name: ");
            break;
        case TypeDelete:
            printf("[Delete] input telbook name: ");
            break;
        default:
            break;
    }   
    if(name!=NULL)
    {
        scanf("%s",name);
    }
    if(ID!=NULL)
    {
        scanf("%s",ID);
    }
    if(c1!=NULL)
    {
        scanf("%d",c1);
    }
    if(c2!=NULL)
    {
        scanf("%d",c2);
    }
    if(c3!=NULL)
    {
        scanf("%d",c3);
    }
   
}
//显示
 void show(pStu head)
{
    while(head)
    {
        printf("学号  姓名     数学  语文 英语 均分\n");
        printf("%s %s %d %d %d %d\n",head->ID,head->name,head->c1,head->c2,head->c3,(head->c1+head->c2+head->c3)/3);
        head=head->next;
    }
   
}
//头插法输入
void push_front(pStu *head,char *name,char *ID,int *c1,int *c2,int *c3)
{
    pStu pt=NULL;
    //input(name,ID,c1,c2,c3,TypeAdd);
    pt=malloc(sizeof(Stu));
    strcpy(pt->name,name);
    strcpy(pt->ID,ID);
    pt->c1=*c1;
    pt->c2=*c2;
    pt->c3=*c3;
    pt->next=*head;
    *head=pt;
    return;
}
/*void insert()
{

}
*/
void sort(pStu head)
{
    Stu temp;
    pStu pr=head,p=head;
    int i=1,j,k;
    while(p->next!=NULL)
    {
        p=p->next;
        i++;
    }
    for(j=1;j<i;j++)
    {
        for(k=0;k<(i-j);k++)
        {
            if((pr->c1+pr->c2+pr->c3)/3<(p->c1+p->c2+p->c3))
            {
                temp=*pr;
                temp.next=p->next;
                *pr=*p;
                *p=temp;
                pr->next=p;
            }
            p=p->next;
            pr=pr->next;
        }
        p=head;
        pr=head;
    }
    return;
}
void delete(pStu *head,char *name,char*ID)
{
    input(name,ID,NULL,NULL,NULL,TypeDelete);
    pStu p=*head;
    pStu q=NULL;
    int flag=0;
    while(p)
    {
        if(strcmp(p->name,name)==0)
        {   
            if(strcmp(p->ID,ID)==0)
            {
                if(p==*head)
                {
                    *head=p->next;
                }
                else
                {
                    q->next=p->next;
                }
                free(p);
                flag=1;
            }   
            q=p;
            p=p->next;
        }
    }
    if(flag==0)
        printf("error,no record!\n");
    return;
}
void find(pStu head,char *name,char *ID)
{
    input(name,ID,NULL,NULL,NULL,TypeFind);
    while(head)
    {
        if(strcmp(head->name,name)==0||strcmp(head->ID,ID)==0)
        {
            printf("%s: %d\n",name,ID);
            return;
        }
        head=head->next;
    }
    printf("error,no record!\n");
    return;
}
pStu read(pStu *head)
{
    Stu *p=NULL;
    Stu *ptr=*head;
    Stu temp;
    FILE *fp=fopen("grade.txt","r");   
    if(fp==NULL)
        return *head;
    while(5==fscanf(fp,"%s %s %d %d %d\n",temp.ID,temp.name,&temp.c1,&temp.c2,&temp.c3))
    {
        push_front(head,temp.name,temp.ID,&temp.c1,&temp.c2,&temp.c3);
    }
    fclose(fp);
    return *head;
}
void save(pStu *head)
{
    FILE *fp=fopen("grade.txt","w");
    Stu *p=*head;
    if(fp==NULL)
    {
        printf("save faild!\n");
        return;
    }
    while(p!=NULL)
    {
        fprintf(fp,"%s %s %d %d %d\n",p->ID,p->name,p->c1,p->c2,p->c3);
        p=p->next;
    }
    fclose(fp);
    printf("save success!\n");
   
}
int main(int argc,char *argv[])
{
    int a;
    int n=1;
    pStu head=NULL;
    char name[20];
    char ID[10];
    int c1;
    int c2;
    int c3;
    head=read(&head);
    while(n)
    {
        printf("1 添加数据\n");
        //printf("2 插入数据\n");
        printf("3 删除数据\n");
        printf("4 数据排序\n");
        printf("5 显示数据\n");
        printf("6 查询数据\n");
        printf("7 退出\n");
        printf("选择:");
        scanf("%d",&a);
        switch(a)
        {
            case 1:
                push_front(&head,name,ID,&c1,&c2,&c3);
                break;
            /*case 2:
                insert();
                break;
            */
            case 3:
                delete(&head,name,ID);
                break;
            case 4:
                sort(head);
                break;
            case 5:
                show(head);
                break;
            case 6:
                find(head,name,ID);
                break;
            case 7:
                n=0;
                break;
            default:
                printf("重新输入!!");
        }
    }
    save(&head);
   
    return 0;
}
搜索更多相关主题的帖子: 管理系统 include 
2014-06-23 11:12
wp231957
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
来 自:神界
等 级:贵宾
威 望:423
帖 子:13688
专家分:53332
注 册:2012-10-18
收藏
得分:0 
成绩管理系统

DO IT YOURSELF !
2014-06-23 13:54
快速回复:成绩管理系统
数据加载中...
 
   



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

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