Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Consider the following two nested structure types: struct Node {struct Employee

ID: 3832988 • Letter: C

Question

Consider the following two nested structure types: struct Node {struct Employee data; struct Node "next;}; struct Employee {char name[35]; char 55N[10]; unsigned long salary; unsigned short vacation_days;}; Suppose we have already written a program containing a linked list whose nodes are of type struct Node, and that a pointer variable head currently points to the first element of this list. In the questions below, you need to give the series of statements that we can add to the program to perform the task described in the question. Be sure to declare any additional variables you may need, a) Calculate the sum of the vacation_days field of all nodes in the list, and then display it on the screen. b) Find the node containing the employee with the highest salary In the list, and then display his/her name and salary on the screen. c) Create a dynamic variable of type strict Node; read from the user two strings, a double and a positive integer from the user; store those values in the dynamic variable, and then insert it as the last node of the linked list. d) Remove the third node In the linked list, and delete the corresponding dynamic variable. You assume the list contains at least three nodes.

Explanation / Answer

#include <stdio.h>

struct Employee
{
    char name[35];
    char SSN[10];
    unsigned long salary;
    unsigned short vacation_days;
};

struct Node
{
    struct Employee data;
    struct Node* next;
};

//Calculate the sum of the vacation_days field of all nodes in the list,
//and then display it on the screen.
void countVacationDays(struct Node *head)
{
    unsigned int totalVacationDays = 0;
    while(head != NULL)
    {
       totalVacationDays += head->data.vacation_days;
       head = head->next;
    }
    printf("The number of vacation days is: %d ", totalVacationDays);
}
//Find the node containing the employee with highest salary in the list.
//Display his name and salary.
void highestSalariedEmployee(struct Node *head)
{
    struct Node *highSalariedNode = head;
    while(head != NULL)
    {
       if(head->data.salary > highSalariedNode->data.salary)
           highSalariedNode = head;
       head = head->next;  
    }
    printf("Highest salary is: %ld, and is being earned by %s ", highSalariedNode->data.salary, highSalariedNode->data.name);
}