Submission: Electronic Submission On Brightspace • Write a readme file. Write a single PDF file with your answers to Part 1, where you type the answers and short explanations. Submit
a single tar file with all the files you created for this assignment (including all the c files, h files, and your pdf). The file name is a3.tar. Note: ○ ○ ○ TAs will generate the executable files. So, write detailed instructions in the ReadMe file to ensure they know how to compile your files. It is up to the TAs to deduct points for improper submission. The grades include commenting, no usage of global variables, clear and simple code, and no code repetitions (if needed, add functions to avoid repeating code sections) In this assignment, you are asked to write short programs to meet the function descriptions. Coding instructions: Add functions as needed. Code must compile and execute on the course VM Write the design of the code within the function body and then comment on it. This way, you will catch two birds in one step: the function will already include comments, and you will only need to complete a few lines of code under each comment. Do not post the assignment or the assignment and/or solutions on any website. Objectives: 1. Demonstrate the ability to code a program in C and create a corresponding file management system. 2. Emphasize using function pointers and doubly linked lists. 3. Apply the acquired knowledge of recursion and usage of the make utility. 4. Master the translation of question requirements into actual functions within a C program. Grading (The assignment is graded out of 100) Part I - 20 points (10 points for each question) • Generate a single PDF file that includes all answers for this section. For each question: О Develop a short program to validate the answer. ○ Briefly explain how the system would generate the answers. ○ Submit a combination of the detailed text explanations and screenshots without submitting the code files. Grading Details: О Allocate 8 points for well-written text explanations demonstrating a clear understanding of corresponding course materials relevant to the question. О Allocate 2 points for correct output. ○ Deduct 1 point for NOT attaching the screenshots with the timestamp and name of the files. Part II - 80 points (Points distribution is given to each question) Adhere to reasonable C code formatting standards. (e.g., naming, spacing, etc.) ● For this section, write a program for each given question. • • • Submit both the .c files and, if applicable, the .h files. No need to provide answers or explanations in this section; focus solely on functional C programs. • Grading Details ○ Award FULL marks for each sub-questions ○ Clarity and completeness of functions within the file. This evaluation should consider factors such as meaningful function names, appropriate parameter usage, and the overall structure of the code. ■ Successfully achieving the correct program output according to the specified requirements. Deduct 5 points for the ABSENCE of proper adherence to commenting standards throughout the code. Part I (Write short answers) 1. (10 points) Analyze the given C code for fork(). Given the code below, predict the output upon its execution. Provide a thorough analysis outlining the total count of generated processes, a step-by-step breakdown of the printed numbers, and explain why. #include #include int main() { if (fork()) { } if (!fork()) { fork(); printf("1"); } else { printf("2"); } } else { printf("3"); } printf("4"); return 0; 2. (10 points) Analyze the given C code for the doubly linked list. Given the sortList function and the input list {1, 2, -3, -4, 9, -1}, predict the output resulting from the application of the sorting function. Provide a step-by-step breakdown of what happens in each iteration, confirming your predictions and specifying the updated output of the sorted list. void sortList(Node** head) { // Initialize the previous and the current nodes Node* previous = (*head); Node* current; // list traversal for(current (*head)->next; current != NULL; current = current->next) { // continue if the current element // is at its right place if (current->value >= previous->value) { } previous = current; } } // If the current is smaller than previous, then // it must be moved to head else { } // Detach current from the linked list previous->next = current->next; // Move the current node to the beginning current->next = (*head); (*head) = current; // Update current current = previous; Part II: Write a code based on the description 1. (15 points) Find Triplets Summing to Zero Using the Doubly linked List. You are tasked with creating a C program determining whether three elements (a, b, and c) exist in an array nums such that a + b + c = 0. If such triplets exist, your program should find and display all unique combinations of these triplets. Your program should adhere to the following specifications: 1) (5 points) Command Line Input Handling: • Develop a function that verifies if an array of values is provided as command-line parameters. Assume the user will input the values in ascending order. • If the values are provided properly, implement the function to store the arguments in an array. If values are not provided or if the number of values is less than 3, the program should display usage information: Usage: ./programName ... Please provide at least 3 values for the program to execute. 2) (5 points) Doubly Linked List Implementation: Implement a doubly linked list to store the sorted array values. Insert the values into the linked list in the same sequence as they appear in the sorted list. 3) (5 points) Finding Triplets and Output: . Develop a function that receives a doubly linked list as input. This function should identify and print all the combinations of triplets whose sum is zero. If the first item in the list is greater than 0, it indicates there is no possibility of finding triplets that meet the specified condition. To find triplets, consider three pointers: a, b, and c. • Start with a pointing to the head, b to the next node, and c to the tail. When the sum of elements in a triplet is larger than 0, think about which pointers should move in which direction to explore potential triplets efficiently. Example: Given the values: {-1,-1,0,1}, the expected output is [-1,0,1], and [-1,0,1]. Given the values: {-3,-1,0,1,2}, the expected output is [-3,1,2], and [-1,0,1].