#include <stdio.h>
#include <stdlib.h>
#include <string.h>
typedef struct _Teacher
{
char id[10];
char name[20];
char gender[10];
char unit[50];
char address[50];
char phone[20];
double salary;
double allowance;
double subsidy;
double pay;
double phone_bill;
double utility_bill;
double rent;
double tax;
double health_insurance;
double fund;
double deduction;
double net_pay;
} Teacher;
typedef struct _ListNode
{
Teacher data;
struct _ListNode *next;
} ListNode;
ListNode *create_list_node(Teacher *data) {
ListNode *new_node = (Teacher*) malloc(sizeof(Teacher));
new_node->data = data->data;
new_node->next = NULL;
return new_node;
}
void print_list(ListNode * head)
{
ListNode *current = head;
while (current != NULL)
{
printf("%s -> ", current->data.id);
printf("%s -> ", current->data.name);
printf("%s -> ", current->data.gender);
printf("%s -> ", current->data.unit);
printf("%s -> ", current->data.address);
printf("%s -> ", current->data.phone);
printf("%.2lf -> ", current->data.salary);
printf("%.2lf -> ", current->data.allowance);
printf("%.2lf -> ", current->data.subsidy);
printf("%.2lf -> ", current->data.pay);
printf("%.2lf -> ", current->data.phone_bill);
printf("%.2lf -> ", current->data.utility_bill);
printf("%.2lf -> ", current->data.rent);
printf("%.2lf -> ", current->data.tax);
printf("%.2lf -> ", current->data.health_insurance);
printf("%.2lf -> ", current->data.fund);
printf("%.2lf -> ", current->data.deduction);
printf("%.2lf -> ", current->***_pay);
current = current->next;
}
printf("\n");
}
void delete_list_node(ListNode ** head)
{
ListNode *current = *head;
ListNode *previous = NULL;
if (current == NULL)
{
return;
}
while (current != NULL)
{
previous = current;
current = current->next;
if (current == NULL)
{
break;
}
if (current->data.next == NULL)
{
previous->next = NULL;
break;
}
previous->next = current->next;
}
}
void find_list_node(ListNode ** head, char *id)
{
ListNode *current = *head;
while (current != NULL)
{
if (strcmp(current->data.id, id) == 0)
{
printf("Found %s in the list:\n", id);
print_list(current);
return;
}
current = current->next;
}
printf("No %s found in the list\n", id);
}int main()
{
ListNode *head =
create_list_node(&Teacher
("John Doe", "Male", "Room 123", "123-456-7890", 8000, 1500, 1000, 9000,
1000, 6000, 2800, 4000));
print_list(head);
int choice;
while (1)
{
printf("\n");
printf("Teacher Management System\n");
printf("1. Input Teacher Data\n");
printf("2. Delete Teacher\n");
printf("3. Browse Teacher Data\n");
printf("4. Update Teacher Data\n");
printf("0. Exit\n");
scanf("%d", &choice);
if (choice >= 0 && choice < 4)
{
printf("Enter Teacher ID (e.g. John Doe): ");
char id[10];
scanf("%s", id);
Teacher *teacher = find_list_node(&head, id);
if (teacher != NULL)
{
printf("Teacher found:\n");
print_list(teacher);
printf("Enter Teacher data:\n");
scanf("%s", teacher->id);
scanf("%s", teacher->name);
scanf("%s", teacher->gender);
scanf("%s", teacher->unit);
scanf("%s", teacher->address);
scanf("%s", teacher->phone);
scanf("%lf", &teacher->salary);
scanf("%lf", &teacher->allowance);
scanf("%lf", &teacher->subsidy);
scanf("%lf", &teacher->pay);
scanf("%lf", &teacher->phone_bill);
scanf("%lf", &teacher->utility_bill);
scanf("%lf", &teacher->rent);
scanf("%lf", &teacher->tax);
scanf("%lf", &teacher->health_insurance);
scanf("%lf", &teacher->fund);
scanf("%lf", &teacher->deduction);
scanf("%lf", &teacher->net_pay);
}
}
else if (choice == 0)
{
printf("Exiting the program\n");
return 0;
}
else if (choice == 1)
{
printf("Enter Teacher ID (e.g. John Doe): ");
char id[10];
scanf("%s", id);
Teacher *teacher = find_list_node(&head, id);
if (teacher != NULL)
{
delete_list_node(&head);
break;
}
}
else if (choice == 2)
{
printf("Enter ID of the Teacher to browse: ");
char id[10];
scanf("%s", id);
find_list _node(&head, id);
}
else if (choice == 3)
{
print _list(head);
}
else
{
printf(" Invalid choice \ n ");
}
}
return 0;
}
无法运行,求帮忙修改 QAQ
错误提示消息我的类型赋值不匹配,使用chatgpt修改对应部分仍然无法正确运行。