Question
Directions Complete the following homework assignment using the description given in each section. Purpose Use a structure to build linked list. Perform search
Directions
Complete the following homework assignment using the description given in each section.
Purpose
• Use a structure to build linked list.
• Perform search and delete operations on the built linked list
• Read input from a text file and write the final output to a text file.
Submission information
Submit this assignment using the tc.rnet submission system by the deadline. Not doing so will result in a zero, no exceptions. DO NOT WAIT TILL THE LAST DAY TO EMAIL. DO NOT submit on canvas or by email!
Log onto tc.rnet.missouri.edu and submit homework 2 assignment by following command (assuming your filename is homework2.c):
submit CS2050 2050HW2 homework2.c
Description
For the homework assignment build a linked list of the bank account information stored in the account.txt file (available on canvas).Each account has an account number, name of the person and the current amount in the account. Use following structure prototype for creating “bank” node.
typedef struct struct_bank
{
int accn_num;
char *name;
float amount;
struct struct_bank *next;
}bank;
Read the account information from the account.txt file, create a node using the input from the file and build a linked list. Your implementation should correctly handle this logic as the new node will go at the end of the linked list. The created linked list can be accessed by the pointer “head” that points to the beginning of the linked list. After creating the linked list open the second text file “update.txt”. This text file has account information that needs to be updated. For example update.txt has account for the user “Jessica” with amount -715.00 so take this amount for the user Jessica and update her amount information (in the linked list) by adding the two amounts (400-715=-315). If there is new account in the update.txt file (like John) add those new accounts at the end. After updating the accounts by information stored in update.txt file some of the accounts will have negative amounts in their accounts, now perform a delete operation where you delete all the nodes in the linked list with negative amount. Finally after performing the delete operation write the account information from the linked list into a text file (output file will contain all the accounts with positive amounts in them).
Use the following functions to implement the above problem.
bank * create_node(char *n, int accn, float amt): This function takes a string , integer and float variable (which is the account information of a user) creates a node and returns the address of the created node.
bank * insert_node(bank* head, bank* node): This function takes pointer head that points to the beginning of the linked list and inserts the node at the end of the list.
bank * build_list(char*): This function takes the input file name (accounts.txt), opens the input file, reads the user information from the file pass it to create_node function. After that it call insert_node function with the created node (by the create_node) function and the pointer “head” pointing at the beginning of the linked list.At the end function returns the “head” pointer.
int check_list(bank* head, char *n, int accn, float amt): This function uses the information from the update.txt file and checks if the account information (s, accn and amt) is already present in the linked list or not. If the account is already present then it update the total amount for that account (as explained above) and returns 1 otherwise 0 and an error message is printed out indicating that the account is not in the linked list. Pointer “head” is used to traverse the linked list.
bank* update_list(char *str, bank* head): This function tales a file name str and the pointer “head”. It updates the account information by first opening the update.txt file, reading the account information and checking if account is already there or not (using check_list function, if account is already there then check_list will update the total amount for that account).If account is not their it calls the insert_node function to insert the new account in the created linked list.
bank* delete_node( bank* head): This function takes head pointer and delete all the node with negative amount and return the pointer “head” that points at the beginning of the linked list.
int write_output(char * str, bank*head):This function write the content of linked list after the delete operation to the output file. It takes output file name and the “head” pointer.
void print_list(bank *head ): It takes pointer “head” and prints the account information as shown in the sample output below.
main(): It calls build_list, update_list and delete_node functions and after each function calls print_list to print the linked list content. At the end it calls the write_output function.
Note
Read the complete document carefully before starting the homework assignment.
While adding a node or deleting a node, a node can be the first node or the last node or some node from the middle of the linked list so implementation should correctly implement this logic.
Structure bank has a field name which has a type character pointer so you might need to malloc this separately. Also in the create_node function if assignment of variable “n” to the node->name (node->name =n) does not work then use strcpy function from the string.h library and copy “n” into node->name.
Error check for the all the input file names.
Print the output after each operation on the screen (as shown in the sample output below) also at the end write the final account information to a text file. Output on the screen should be correctly formatted (word document has removed some of the formatting in the sample output below).
Sample Output
./a.out master.txt update.txt out.txt
Created linked list
54981 Adam 57.75
91023 Alice 1206.50
65347 Beth 15000.00
87201 Chris 475.00
47012 Daniel 342.90
98432 Jerry 765.00
32456 Jessica 400.00
73121 Jonathan 5750.00
76290 Morgan 1000.00
31498 Nicole 125.50
Linked list after update operation
54981 Adam -92.25
91023 Alice 1206.50
41923 Anderson 1534.75
65347 Beth 15375.50
87201 Chris 475.00
47012 Daniel -200.00
98432 Jerry 930.30
40023 Jesse 134.75
32456 Jessica -315.00
73651 John 5750.00
73121 Jonathan 5750.00
76290 Morgan 1000.00
31498 Nicole -74.50
Linked list after delete operation
91023 Alice 1206.50
41923 Anderson 1534.75
65347 Beth 15375.50
87201 Chris 475.00
98432 Jerry 930.30
40023 Jesse 134.75
73651 John 5750.00
73121 Jonathan 5750.00
76290 Morgan 1000.00
Guidelines for Grading Homework-2
40 Points Possible
General
Assignment will not be given any credit (0/40) if your program does not compile or fail to produce any valid output.
-5 points – Not displaying the outputs with correct formatting.
5 points – create_node function.
5 points – insert_node function.
5 points – build_list function.
5 points – check_node function.
5 points – update_list function
5 points – delete_node function.
5 points – print_list function.
5 points – write_output function.
Step by Step Solution
3.57 Rating (168 Votes )
There are 3 Steps involved in it
Step: 1
homework2cpp include include Used for strcpy include Used for malloc structbank structure typedef struct structbank int accnnum char name20 float amount struct structbank next bank initialising such t...Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Document Format ( 2 attachments)
635dbf2f56beb_178523.pdf
180 KBs PDF File
635dbf2f56beb_178523.docx
120 KBs Word File
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started