| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1292 人关注过本帖
标题:职工信息管理系统(存储方式为链表),请大神帮忙找下错误
只看楼主 加入收藏
小可爱0920
Rank: 1
等 级:新手上路
帖 子:29
专家分:0
注 册:2016-12-18
结帖率:90%
收藏
已结贴  问题点数:10 回复次数:4 
职工信息管理系统(存储方式为链表),请大神帮忙找下错误
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
struct employee{
    int num;
    char name[10];
    int age;
    double salary;
    struct employee *next;
}
void new_employee(struct employee *head, struct employee s1 );
void search_employee (struct employee *head, int num);
void update_employee (struct employee *head, int num,double salary);
void delete_employee (struct employee *head, int num);
void output_employee (struct employee *head);
int main()
{
    struct employee *head;
    int choice,num,age;
    char name[10];
    double salary;
    int size=sizeof(struct employee);
    printf("******欢迎进入职工信息管理系统******\n");
    do{
        printf("1:new  2:search  3:update  4:delete  5:output\n");
        scanf("%d",&choice);
        switch(choice){
        case 1:
            printf("输入工号、名字、年龄、工资\n");
            scanf("%d%s%d%lf",&s1.num,s1.name,&s1.age,&s1.salary);
            head=new_emlpoyee(head,s1);break;
        case 2:
            printf("输入您要查找的职工工号:\n");
            scanf("%d",&num);
            head=search_employee(head,num);
            break;
        case 3:
            printf("输入您要修改的职工的工号:\n");
            scanf("%d",&num);
            printf("输入错误的工资信息:\n");
            scanf("lf",&salary);
            head=update_employee(head,num,salary);
            break;
        case 4:
            printf("输入您要删除的职工工号:\n");
            scanf("%d",&num);
            head=delete_employee(head,num);
        case 5:
            printf("输出职工信息\n");
            head=output_employee(head);
            break;
        }
    }while(choice!=0);
    return 0;
}
void new_employee(struct employee *head, struct employee s1 ){
    struct employee *p,*tail,*head;
    head=NULL;
    int size=sizeof(struct employee);
    while(num!=0){
        p=(struct employee *)malloc(size);
        p->num=num;
        p->age=age;
        p->salary=salary;
        strcpy(p->name,name);
        p->next=head;
        head=p;
        scanf("%d%s%d%lf",&s1.num,s1.name,&s1.age,&s1.salary);
    }
}
void search_employee (struct employee *head, int num){
    struct employee *p;
    for(p=head;p!=NULL;p=p->next){
        if(num==p->num)
            printf("%d%s%d%lf",p->num,p->name,p->age,p->salary);
    }
}
void update_employee (struct employee *head, int num,double salary){
    struct employee *p;
    double s;
    for(p=head;p!=NULL;p=p->next){
        if(p->num==num){
            scanf("lf",&s);
            p->salary=s;
        }
    }

        

}
void delete_employee (struct employee *head, int num){
    struct employee *p1,*p2;
    while(head!=NULL&&head->num==num){
        p2=head;
        head=head->next;
        free(p2);
    }
    if(head==NULL)
        return;

    p1=head;
    p2=head->next;
    while(p2!=NULL){
        if(p2->num==num){
            p1->next=p1->next;
            free(p2);
        }
        else
            p1=p2;
        p2=p1->next;
    }
}


void output_employee (struct employee *head){
    struct employee *p;
    if(head==NULL){
        printf("\nNo Records\n");
        return;
    }
    for(p=head;p!=NULL;p=p->next)
        printf("%d\t%s\t%d\t%g\n",p->num,p->name,p->age,p->salary);
}


        
搜索更多相关主题的帖子: employee 管理系统 include double 信息 
2017-04-13 20:30
小可爱0920
Rank: 1
等 级:新手上路
帖 子:29
专家分:0
注 册:2016-12-18
收藏
得分:0 
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
struct employee{
    int num;
    char name[10];
    int age;
    double salary;
    struct employee *next;
}
void new_employee (struct employee *head, struct employee s1);
void search_employee (struct employee *head, int num);
void update_employee (struct employee *head, int num,double salary);
void delete_employee (struct employee *head, int num);
void output_employee (struct employee *head);
int main()
{
    struct employee *head,s1;
    int choice,num,age;
    char name[10];
    double salary;
    int size=sizeof(struct employee);
    printf("******欢迎进入职工信息管理系统******\n");
    do{
        printf("1:new  2:search  3:update  4:delete  5:output\n");
        scanf("%d",&choice);
        switch(choice){
        case 1:
            printf("输入工号、名字、年龄、工资\n");
            scanf("%d%s%d%lf",&s1.num,s1.name,&s1.age,&s1.salary);
            new_employee(head,s1);break;
        case 2:
            printf("输入您要查找的职工工号:\n");
            scanf("%d",&num);
            search_employee(head,num);
            break;
        case 3:
            printf("输入您要修改的职工的工号:\n");
            scanf("%d",&num);
            printf("输入错误的工资信息:\n");
            scanf("lf",&salary);
            update_employee(head,num,salary);
            break;
        case 4:
            printf("输入您要删除的职工工号:\n");
            scanf("%d",&num);
            delete_employee(head,num);
            break;
        case 5:
            printf("输出职工信息\n");
            output_employee(head);
            break;
        }
    }while(choice!=0);
    return 0;
}
void new_employee(struct employee *head, struct employee s1 ){
    struct employee *p,*tail;
    head=NULL;
    int size=sizeof(struct employee);
    while(s1.num!=0){
        p=(struct employee *)malloc(size);
        p->num=s1.num;
        p->age=s1.age;
        p->salary=s1.salary;
        strcpy(p->name,s1.name);
        p->next=head;
        head=p;
        scanf("%d%s%d%lf",&s1.num,s1.name,&s1.age,&s1.salary);
    }
}
void search_employee (struct employee *head, int num){
    struct employee *p;
    for(p=head;p!=NULL;p=p->next){
        if(num==p->num)
            printf("%d%s%d%lf",p->num,p->name,p->age,p->salary);
    }
}
void update_employee (struct employee *head, int num,double salary){
    struct employee *p;
    double s;
    for(p=head;p!=NULL;p=p->next){
        if(p->num==num){
            scanf("lf",&s);
            p->salary=s;
        }
    }

        

}
void delete_employee (struct employee *head, int num){
    struct employee *p1,*p2;
    while(head!=NULL&&head->num==num){
        p2=head;
        head=head->next;
        free(p2);
    }
    if(head==NULL)
        return;

    p1=head;
    p2=head->next;
    while(p2!=NULL){
        if(p2->num==num){
            p1->next=p1->next;
            free(p2);
        }
        else
            p1=p2;
        p2=p1->next;
    }
}


void output_employee (struct employee *head){
    struct employee *p;
    if(head==NULL){
        printf("\nNo Records\n");
        return;
    }
    for(p=head;p!=NULL;p=p->next)
        printf("%d\t%s\t%d\t%g\n",p->num,p->name,p->age,p->salary);
}


        
目前改到这里。
2017-04-13 20:51
lmlm1001
Rank: 7Rank: 7Rank: 7
等 级:黑侠
威 望:4
帖 子:107
专家分:550
注 册:2015-3-1
收藏
得分:7 
编译能通过么
尤其是第十行的分号
2017-04-14 00:36
小可爱0920
Rank: 1
等 级:新手上路
帖 子:29
专家分:0
注 册:2016-12-18
收藏
得分:0 
不能,编译显示还有三个错误
2017-04-14 07:11
小可爱0920
Rank: 1
等 级:新手上路
帖 子:29
专家分:0
注 册:2016-12-18
收藏
得分:0 
第十行加分号后编译能通过,但是运行不对
2017-04-14 07:14
快速回复:职工信息管理系统(存储方式为链表),请大神帮忙找下错误
数据加载中...
 
   



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

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