#include<stdlib.h>
#include<stdio.h>
#include<conio.h>
#include<string.h>
#define N 5
typedef struct monthsalary
{
float JBGZ;
float jiangjin;
float shuijin;
}MSalary;
typedef union salary
{
float yearsalary;
MSalary gongzi;
}Salary;
typedef struct Employee
{ int ID;
char XM[20];
Salary gz;
struct Employee *next;
}Employee;
Employee *create(Employee ee[])
{
Employee *h,*fre,*head;
int i=0;
for(i=0;i<N;i++)
{
h=(Employee*)malloc(sizeof(Employee));
h->ID=ee[i].ID;
strcpy(h->XM,ee[i].XM);
if(h->ID>>12==15)
h->gz.yearsalary=ee[i].gz.yearsalary;
else
{
h->gz.gongzi.JBGZ=ee[i].gz.gongzi.JBGZ;
printf("\n输入%s的奖金:",h->XM);
scanf("%f",&h->gz.gongzi.jiangjin);
printf("\n输入%s的税金:",h->XM);
scanf("%f",&h->gz.gongzi.shuijin);
}
h->next=NULL;
if(i>0)
fre->next=h;
fre=h;
if(i==0)head=h;
}
return head;
}
void display(Employee *p)
{
if(p!=NULL)
if(p->ID>>12==15)
{
printf("工号\t姓名\t年薪\n");
printf("%d\t%s\t%7.2f\t\n",p->ID,p->XM,p->gz.yea
报错上面说,你的find函数没有指定。
你题目的解答代码如下:
#include <stdlib.h>
#include <stdio.h>
#include <conio.h>
#include <string.h>
#define N 5
typedef struct monthsalary
{
float JBGZ;
float jiangjin;
float shuijin;
} MSalary;
typedef union salary
{
float yearsalary;
MSalary gongzi;
} Salary;
typedef struct Employee
{
int ID;
char XM[20];
Salary gz;
struct Employee *next;
} Employee;
Employee *create(Employee ee[])
{
Employee *h, *fre, *head;
int i = 0;
for (i = 0; i < N; i++)
{
h = (Employee *)malloc(sizeof(Employee));
h->ID = ee[i].ID;
strcpy(h->XM, ee[i].XM);
if (h->ID >> 12 == 15)
h->gz.yearsalary = ee[i].gz.yearsalary;
else
{
h->gz.gongzi.JBGZ = ee[i].gz.gongzi.JBGZ;
printf("\n输入%s的奖金:", h->XM);
scanf("%f", &h->gz.gongzi.jiangjin);
printf("\n输入%s的税金:", h->XM);
scanf("%f", &h->gz.gongzi.shuijin);
}
h->next = NULL;
if (i > 0)
fre->next = h;
fre = h;
if (i == 0)
head = h;
}
return head;
}
void display(Employee *p)
{
if (p != NULL)
if (p->ID >> 12 == 15)
{
printf("工号\t姓名\t年薪\n");
printf("%d\t%s\t%7.2f\t\n", p->ID, p->XM, p->gz.yearsalary);
}
else
{
printf("工号\t姓名\t基本工资\t奖金\t税金\n");
printf("%d\t%s\t%7.2f\t\t%7.2f\t%7.2f\t\n", p->ID, p->XM, p->gz.gongzi.JBGZ, p->gz.gongzi.jiangjin, p->gz.gongzi.shuijin);
}
else
printf("查无此人\n");
}
Employee *find(Employee *h, int k) //find写成了fine
{
Employee *t = h;
while (t != NULL)
{
if (t->ID == k)
return t;
else
t = t->next;
}
return NULL;
}
void main()//main 写成了 mian
{
Employee ee[5] = {{0xf001, "张三", 200000, 0}, {0xf002, "李四", 200000, 0}, {0x1003, "王五", 3000, 0}, {0x1004, "赵六", 3000, 0}, {0x1005, "孙七", 2800, 0}};
Employee *head, *p;
int temp = 1;
head = create(ee);
while (temp > 0)
{
printf("\n请输入员工工号(16进制)");
scanf("%x", &temp);
fflush(stdin);
p = find(head, temp);
display(p);
}
}
如有帮助,请点击我的回答下方的【采纳该答案】按钮帮忙采纳下,谢谢!