| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 417 人关注过本帖
标题:求大神知道 关于链表问题
只看楼主 加入收藏
qq951534697
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2013-7-2
结帖率:0
收藏
已结贴  问题点数:20 回复次数:3 
求大神知道 关于链表问题
#include<stdio.h>
#include<stdlib.h>

#define LEN sizeof(struct member)

struct member
{
    int num;
    char name[20];
    char sex[1];
    double basePay;
    double postPay;
    double housePay;
    double incomeTax;
    double waterCost;
    double reayPay;
    struct member *next;
   
};

 

int menu();
void LookThrough(struct member *head);     //浏览信息
void FindInform();                        //查找指定员工
void Delete();                            //删除员工信息
void AddInform();                         //添加新员工
void AmendInform();                       //修改员工信息
void Calaulate();                         //计算工资
void Statistic();                         //统计
void SaveInform();                        //保存信息

struct member *creat()                    // ID号、姓名、基础工资、职务工资、住房公积金、个人收入所得税,水电费、实发工资。
{

    int temp = 0;
    struct member *head;
    struct member *p1, *p2;
    p1 = p2 =(struct member *) malloc(LEN);
    printf("请输入ID号码\n");
    scanf("%d",&p1->num);
    while(p1->num != 0)
    {
        printf("请输入姓名\n");
        scanf("%s",p1->name);
        fflush(stdin);
        printf("请输入性别(m/f)\n");
        scanf("%s",p1->sex);
        fflush(stdin);
        printf("请输入基础工资\n");
        scanf("%d",&p1->basePay);
        printf("请输入职务工资\n");
        scanf("%d",&p1->postPay);
        printf("请输入住房公积金\n");
        scanf("%d",&p1->housePay);
        printf("请输入个人所得税\n");
        scanf("%d",&p1->incomeTax);
        printf("请输入水电费\n");
        scanf("%d",&p1->waterCost);
        head = NULL;
        temp++;
        p2 = p1;
        p1 =(struct member *) malloc(LEN);
        printf("请输入ID号码\n");
        scanf("%d",&p1->num);
    }
    p2->next = NULL;
    return (head);
}
int main()
{   
    int choice;
    struct member *head;

    printf("\t\t\t   欢迎登陆职工工资管理系统 \n");
    printf("\n");
    choice = menu();
    switch(choice)
        {

        case 1: printf("您已进入职工信息录入系统\n");
            head = creat();
            LookThrough(head);
            break;
        case 2: printf("职工信息显示\n");
            LookThrough(head);
            break;
        case 3: printf("您已进入职工信息查找系统\n");
            break;
        case 4: printf("您已进入职工信息删除系统\n");
            break;
        case 5: printf("您已进入新职工信息添加系统\n");
            break;
        case 6: printf("您已进入职工信息修改系统\n");
            break;
        case 7: printf("您已进入职工工资计算系统\n");
            break;
        case 8: printf("您已进入职工工资统计系统\n");
            break;
        case 9: printf("保存职工信息\n");
        case 10:
            break;
        default: printf("输入有误, 请按照提示输入!\n");
        }


    return 0;
}


int menu()
{
    int choice;
    printf("\t\t*********************************************\n");
    printf("\t\t---------------------------------------------\n");
    printf("\t\t***       1.职工信息录入                  ***\n");
    printf("\t\t***       2.职工信息显示                  ***\n");
    printf("\t\t***       3.职工信息查找                  ***\n");
    printf("\t\t***       4.职工信息删除                  ***\n");
    printf("\t\t***       5.新职工信息添加                ***\n");
    printf("\t\t***       6.职工信息修改                  ***\n");
    printf("\t\t***       7.计算职工各项工资              ***\n");
    printf("\t\t***       8.统计职工工资信息              ***\n");
    printf("\t\t***       9.保存职工信息                  ***\n");
    printf("\t\t***       10.退出                         ***\n");
    printf("\t\t---------------------------------------------\n");
    printf("\t\t*********************************************\n");
    printf("请输入您的选择:\n");
    scanf("%d",&choice);
    return choice;

}

void LookThrough(struct member *head)
{
    struct member *p;
    p = head;
    if( head != NULL)
    {
        do
        {
            printf("%d%s%lf%lf%lf%lf%lf%lf",p->num, p->name, p->basePay, p->postPay, p->housePay, p->incomeTax, p-
>waterCost, p->reayPay);
            p = p->next;
        }while(p != NULL);
   
    }

}
   这个函数不好使 为什么啊   LookThrough(head)
搜索更多相关主题的帖子: include double member 信息 
2013-07-02 09:42
liu122430950
Rank: 4
等 级:业余侠客
威 望:1
帖 子:45
专家分:211
注 册:2010-5-30
收藏
得分:0 
头指针未初始化
int main()
{   
    int choice;
    struct member *head;
head=NULL;
.......
}

[ 本帖最后由 liu122430950 于 2013-7-6 16:10 编辑 ]
2013-07-02 11:33
liu122430950
Rank: 4
等 级:业余侠客
威 望:1
帖 子:45
专家分:211
注 册:2010-5-30
收藏
得分:20 
说错了是头指针
2013-07-02 11:34
liu122430950
Rank: 4
等 级:业余侠客
威 望:1
帖 子:45
专家分:211
注 册:2010-5-30
收藏
得分:0 
其他部分还有的比较大的问题是链表没链起来。
#include<stdio.h>
#include<stdlib.h>

#define LEN sizeof(struct member)

struct member
{
    int num;
    char name[20];
    char sex[1];
    double basePay;
    double postPay;
    double housePay;
    double incomeTax;
    double waterCost;
    double reayPay;
    struct member *next;
   
};



int menu();
void LookThrough(struct member *head);     //浏览信息
void FindInform();                        //查找指定员工
void Delete();                            //删除员工信息
void AddInform();                         //添加新员工
void AmendInform();                       //修改员工信息
void Calaulate();                         //计算工资
void Statistic();                         //统计
void SaveInform();                        //保存信息

struct member *creat()                    // ID号、姓名、基础工资、职务工资、住房公积金、个人收入所得税,水电费、实发工资。
{

    int temp = 0;
    struct member *head=NULL;//初始化
    struct member *p1, *p2;
    p1 = p2 =(struct member *) malloc(LEN);
    printf("请输入ID号码\n");
    scanf("%d",&p1->num);
    while(p1->num != 0)
    {
        printf("请输入姓名\n");
        scanf("%s",p1->name);
        fflush(stdin);
        printf("请输入性别(m/f)\n");
        scanf("%s",p1->sex);
        fflush(stdin);
        printf("请输入基础工资\n");
        scanf("%d",&p1->basePay);
        printf("请输入职务工资\n");
        scanf("%d",&p1->postPay);
        printf("请输入住房公积金\n");
        scanf("%d",&p1->housePay);
        printf("请输入个人所得税\n");
        scanf("%d",&p1->incomeTax);
        printf("请输入水电费\n");
        scanf("%d",&p1->waterCost);
//        head = NULL;//!!!!删除
        //!!!!!链表没有链起来。
        temp++;
        p2 = p1;
        p1 =(struct member *) malloc(LEN);
        printf("请输入ID号码\n");
        scanf("%d",&p1->num);
    }
    p2->next = NULL;
    return head;
}
int main()
{   
    int choice;
    struct member *head;
    head=NULL;//初始化头结点

    printf("\t\t\t   欢迎登陆职工工资管理系统 \n");
    printf("\n");
    choice = menu();
    switch(choice)
        {

        case 1: printf("您已进入职工信息录入系统\n");
            head = creat();
            LookThrough(head);
            break;
        case 2: printf("职工信息显示\n");
            LookThrough(head);
            break;
        case 3: printf("您已进入职工信息查找系统\n");
            break;
        case 4: printf("您已进入职工信息删除系统\n");
           break;
       case 5: printf("您已进入新职工信息添加系统\n");
           break;
        case 6: printf("您已进入职工信息修改系统\n");
            break;
        case 7: printf("您已进入职工工资计算系统\n");
            break;
        case 8: printf("您已进入职工工资统计系统\n");
           break;
        case 9: printf("保存职工信息\n");
        case 10:
            break;
        default: printf("输入有误, 请按照提示输入!\n");
        }


    return 0;
}


int menu()
{
    int choice;
    printf("\t\t*********************************************\n");
    printf("\t\t---------------------------------------------\n");
    printf("\t\t***       1.职工信息录入                  ***\n");
    printf("\t\t***       2.职工信息显示                  ***\n");
    printf("\t\t***       3.职工信息查找                  ***\n");
    printf("\t\t***       4.职工信息删除                  ***\n");
    printf("\t\t***       5.新职工信息添加                ***\n");
    printf("\t\t***       6.职工信息修改                  ***\n");
    printf("\t\t***       7.计算职工各项工资              ***\n");
    printf("\t\t***       8.统计职工工资信息              ***\n");
    printf("\t\t***       9.保存职工信息                  ***\n");
    printf("\t\t***       10.退出                         ***\n");
    printf("\t\t---------------------------------------------\n");
    printf("\t\t*********************************************\n");
    printf("请输入您的选择:\n");
    scanf("%d",&choice);
    return choice;

}

void LookThrough(struct member *head)
{
    struct member *p;
    p = head;
    if( head!=NULL)
    {
        do
        {
            printf("%d%s%lf%lf%lf%lf%lf%lf",p->num, p->name, p->basePay, p->postPay, p->housePay, p->incomeTax, p->waterCost, p->reayPay);
            p = p->next;
        }while(p != NULL);
    }
}

[ 本帖最后由 liu122430950 于 2013-7-6 16:07 编辑 ]
2013-07-02 12:06
快速回复:求大神知道 关于链表问题
数据加载中...
 
   



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

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