Answered step by step
Verified Expert Solution
Question
1 Approved Answer
(Make own text files to draw from) Objectives: Warm up with C programming. . Practice with data structures. . Practice with dynamic memory allocation and
(Make own text files to draw from)
Objectives: Warm up with C programming. . Practice with data structures. . Practice with dynamic memory allocation and pointers. Learn some system calls and practice using them. Exercise reading man pages in Unix. ectangular Snip Trace systems calls that a program executes. Discipline your programs for black-box testing where the expected output will have a rigid format. 1 Project Description In this project, you will write a C program in Linux that will read a sequence of student records from two different input files, will sort these records individually using linked lists and the insertion sort algorithm, will merge these two sorted linked lists in a third sorted linked list holding all student records from both files, and will finally print the sorted records into an output file. Both input files will be text files containing information about one student per line. Each line will include the following information in the following format: StudentID Firstname Lastname Department GPA You can assume Firstname, Lastname, and Department are single words each composed of ascii letters (lower + upper case). Assume StudentID is a 7 digit number between (and including) 1000000 and 9999999. Assume GPA is a floating point number between (and including) 0 and 4. There can be one or more space or TAB characters between the fields. You can use the fscanf() function to read the fields of a line into your variables. Note that Firstname, Lastname, and Department can be any length, therefore make sure that you do not assume anything about their lengths, create the memory required to hold them dynamically (Tip: the m modifier of fscanf() might be handy here). Also, do not forget to deallocate (free()) any dynamically allocated memory later (including the ones implicitly allocated by the m modifier of fscanf() or any other function like strdup (), etc.) not to cause memory leaks. Your program will read the information from the input files and will build a separate linked list for each input file where each node (item) of a list will contain information about one student. Hence, each node of a list will be a structure having the fields necessary to store the information of a student (in C, we do not have classes, we have structs). You will build the lists as a doubly linked list, where each node in a list will have a separate pointer to the next node and the previous node. After building the lists, your program will sort the lists individually using the insertion sort algorithm. Sorting will be done in increasing order based on the StudentID field, which will be guaranteed to be unique. Then, your program will merge the lists in a third linked list in a sorted order, and will finally write this third linked list into an output text file. Each line of the output file will contain information about one student in the following format: StudentID; Firstname; Lastname; Department;GPA Note the semicolon (instead of space, comma, or TAB characters) between the fields. The output should contain no spaces or TABs, and no empty lines. It is very important that you produce the output in this format since we will use this format in our automated blackbox testings. 2 Development It is the requirement of this assignment that you have to use three linked list data structures, dynamic memory allocation, the insertion sort algorithm for the first two linked lists, and a sorted merge technique for the third linked list. You cannot build the first two linked lists in sorted order while inserting the elements. You should build the first two lists by simply inserting the nodes to the end (tail) of the lists. Then, you should implement a separate insertion sort function and sort these two linked lists using this insertion sort function. You are not allowed to use the insertion sort function for the third linked list; the third list should be constructed by simply merging the first two sorted linked lists in a sorted order. Also, you cannot assume maximum number of characters for the strings (firstname, lastname, department); they can be any size and the memory for them should be allocated dynamically. In this way, you will be able to practice with malloc, pointers, and structs. The name of your executable file has to be student records. A sample invocation of your program can be like the following: ./studentrecords inl.txt in2.txt out.txt Here, inl.txt is the first input text file, in2.txt is the second input text file, and out.txt is the output text file to be created by your program. It is very important that you follow these specifications to receive full points. Example 1 A sample first input file (for example, inl.txt) can be like the following: 2040003 AAAA BBBBBBBBB Computer Science 3.45 2040002 ElectricalEngineering AAAAAAAAAAAAAAAAA BBB ComputerScience 3.60 A sample second input file (for example, in2.txt) can be like the following: 2040004 XX WWWW Math 2.17 2040001 eee kkkk Civil Engineering 3.33 2040006 9999 FFFFFF ComputerScience 3.10 Then the output file (for example, out.txt) should be the following: 2040001; eee; kkkk;CivilEngineering;3.33 2040002; AAA; CCC;ElectricalEngineering;3.01 2040003; AAAA; BBBBBBBBB; ComputerScience;3.45 2040004;XX; WWWW;Math;2.17 2040005; AAAAAAAAAAAAAAAAA; BBB; Computer Science;3.60 2040006;qqqq;FFFFFF; ComputerScience;3.10 AAA 3.01 2040005 3 Development You will develop your program in a Unix environment using the programming language. You can develop your program using a text editor (emacs, vi, gedit etc.) or an Integrated Development Environment available in Linux. gee must be used as the compiler. You will be provided a Makefile and your program should compile without any errors/warnings using this Makefile. Black-box testing will be applied and your program's output will be compared to the correct output. A simple black-box testing script will be provided to you for your own test; make sure that your program produces the success message in the provided test. A more complicated test (possibly more then one test) might be applied to grade your program. Submissions not following the specified rules here will be penalized. 4 Tracing System Calls After finishing your program, you will trace the execution of your code to find out all the system calls that your program makes. To do this, you will use the strace command available in Linux. See man strace for more details on strace. In a separate README file, you will write only the names of the system calls that your program made in ascending sorted order by eliminating duplicate names, if any. 5 Checking Memory Leaks You will need to make dynamic memory allocation. If you do not deallocate the memory that you allocated previously using free (), it means that your program has memory leaks. To receive full credit, your program should be memory-leak free. You can use valgrind to check the memory-leaks in your program. valgrind will output: "All heap blocks were freed - no leaks are possible" if your program is memory-leak free. 6 Submission Submission will be done through Blackboard strictly following the instructions below. Your work will be penalized 5 points out of 100 if the submission instructions are not followed. In addition, memory leaks will be penalized with a total of 5 points without depending on the amount of the leak. Similarly, compilation warnings will also be penalized with a total of 5 points without depending on the type or the number of warnings. You can check the compilation warnings using the-Wall flag of gcc. 6.1 What to Submit 1. README.txt: It should include your name, ID, and the list of system calls that your program made. Only the unique system call names should be written in ascending order, where each line has a single system call name. No other details about the system calls should be reported. 2. studentrecords.c: Source code of your program. 3. Makefile: Makefile used to compile your program. If different than the provided one, then you should inform the TA about your changes. 6.2 How to Submit 1. Create a directory and name it as your UofL ID number. For example, if a student's ID is 1234567, then the name of the directory will be 1234567. 2. Put all the files to be submitted (only the ones asked in the What to Submit section above) into this directory. 3. Zip the directory. As a result, you will have the file 1234567.zip. 4. Upload the file 1234567.zip to Blackboard using the "Attach File" option. You do not need to write anything to the "Submission" and "Comments" sections. NO LATE SUBMISSIONS AFTER THE PENALTY DEADLINE WILL BE GRADED! 5. You are allowed to make multiple attempts of submission but only the latest attempt submitted before the deadline will be graded. Objectives: Warm up with C programming. . Practice with data structures. . Practice with dynamic memory allocation and pointers. Learn some system calls and practice using them. Exercise reading man pages in Unix. ectangular Snip Trace systems calls that a program executes. Discipline your programs for black-box testing where the expected output will have a rigid format. 1 Project Description In this project, you will write a C program in Linux that will read a sequence of student records from two different input files, will sort these records individually using linked lists and the insertion sort algorithm, will merge these two sorted linked lists in a third sorted linked list holding all student records from both files, and will finally print the sorted records into an output file. Both input files will be text files containing information about one student per line. Each line will include the following information in the following format: StudentID Firstname Lastname Department GPA You can assume Firstname, Lastname, and Department are single words each composed of ascii letters (lower + upper case). Assume StudentID is a 7 digit number between (and including) 1000000 and 9999999. Assume GPA is a floating point number between (and including) 0 and 4. There can be one or more space or TAB characters between the fields. You can use the fscanf() function to read the fields of a line into your variables. Note that Firstname, Lastname, and Department can be any length, therefore make sure that you do not assume anything about their lengths, create the memory required to hold them dynamically (Tip: the m modifier of fscanf() might be handy here). Also, do not forget to deallocate (free()) any dynamically allocated memory later (including the ones implicitly allocated by the m modifier of fscanf() or any other function like strdup (), etc.) not to cause memory leaks. Your program will read the information from the input files and will build a separate linked list for each input file where each node (item) of a list will contain information about one student. Hence, each node of a list will be a structure having the fields necessary to store the information of a student (in C, we do not have classes, we have structs). You will build the lists as a doubly linked list, where each node in a list will have a separate pointer to the next node and the previous node. After building the lists, your program will sort the lists individually using the insertion sort algorithm. Sorting will be done in increasing order based on the StudentID field, which will be guaranteed to be unique. Then, your program will merge the lists in a third linked list in a sorted order, and will finally write this third linked list into an output text file. Each line of the output file will contain information about one student in the following format: StudentID; Firstname; Lastname; Department;GPA Note the semicolon (instead of space, comma, or TAB characters) between the fields. The output should contain no spaces or TABs, and no empty lines. It is very important that you produce the output in this format since we will use this format in our automated blackbox testings. 2 Development It is the requirement of this assignment that you have to use three linked list data structures, dynamic memory allocation, the insertion sort algorithm for the first two linked lists, and a sorted merge technique for the third linked list. You cannot build the first two linked lists in sorted order while inserting the elements. You should build the first two lists by simply inserting the nodes to the end (tail) of the lists. Then, you should implement a separate insertion sort function and sort these two linked lists using this insertion sort function. You are not allowed to use the insertion sort function for the third linked list; the third list should be constructed by simply merging the first two sorted linked lists in a sorted order. Also, you cannot assume maximum number of characters for the strings (firstname, lastname, department); they can be any size and the memory for them should be allocated dynamically. In this way, you will be able to practice with malloc, pointers, and structs. The name of your executable file has to be student records. A sample invocation of your program can be like the following: ./studentrecords inl.txt in2.txt out.txt Here, inl.txt is the first input text file, in2.txt is the second input text file, and out.txt is the output text file to be created by your program. It is very important that you follow these specifications to receive full points. Example 1 A sample first input file (for example, inl.txt) can be like the following: 2040003 AAAA BBBBBBBBB Computer Science 3.45 2040002 ElectricalEngineering AAAAAAAAAAAAAAAAA BBB ComputerScience 3.60 A sample second input file (for example, in2.txt) can be like the following: 2040004 XX WWWW Math 2.17 2040001 eee kkkk Civil Engineering 3.33 2040006 9999 FFFFFF ComputerScience 3.10 Then the output file (for example, out.txt) should be the following: 2040001; eee; kkkk;CivilEngineering;3.33 2040002; AAA; CCC;ElectricalEngineering;3.01 2040003; AAAA; BBBBBBBBB; ComputerScience;3.45 2040004;XX; WWWW;Math;2.17 2040005; AAAAAAAAAAAAAAAAA; BBB; Computer Science;3.60 2040006;qqqq;FFFFFF; ComputerScience;3.10 AAA 3.01 2040005 3 Development You will develop your program in a Unix environment using the programming language. You can develop your program using a text editor (emacs, vi, gedit etc.) or an Integrated Development Environment available in Linux. gee must be used as the compiler. You will be provided a Makefile and your program should compile without any errors/warnings using this Makefile. Black-box testing will be applied and your program's output will be compared to the correct output. A simple black-box testing script will be provided to you for your own test; make sure that your program produces the success message in the provided test. A more complicated test (possibly more then one test) might be applied to grade your program. Submissions not following the specified rules here will be penalized. 4 Tracing System Calls After finishing your program, you will trace the execution of your code to find out all the system calls that your program makes. To do this, you will use the strace command available in Linux. See man strace for more details on strace. In a separate README file, you will write only the names of the system calls that your program made in ascending sorted order by eliminating duplicate names, if any. 5 Checking Memory Leaks You will need to make dynamic memory allocation. If you do not deallocate the memory that you allocated previously using free (), it means that your program has memory leaks. To receive full credit, your program should be memory-leak free. You can use valgrind to check the memory-leaks in your program. valgrind will output: "All heap blocks were freed - no leaks are possible" if your program is memory-leak free. 6 Submission Submission will be done through Blackboard strictly following the instructions below. Your work will be penalized 5 points out of 100 if the submission instructions are not followed. In addition, memory leaks will be penalized with a total of 5 points without depending on the amount of the leak. Similarly, compilation warnings will also be penalized with a total of 5 points without depending on the type or the number of warnings. You can check the compilation warnings using the-Wall flag of gcc. 6.1 What to Submit 1. README.txt: It should include your name, ID, and the list of system calls that your program made. Only the unique system call names should be written in ascending order, where each line has a single system call name. No other details about the system calls should be reported. 2. studentrecords.c: Source code of your program. 3. Makefile: Makefile used to compile your program. If different than the provided one, then you should inform the TA about your changes. 6.2 How to Submit 1. Create a directory and name it as your UofL ID number. For example, if a student's ID is 1234567, then the name of the directory will be 1234567. 2. Put all the files to be submitted (only the ones asked in the What to Submit section above) into this directory. 3. Zip the directory. As a result, you will have the file 1234567.zip. 4. Upload the file 1234567.zip to Blackboard using the "Attach File" option. You do not need to write anything to the "Submission" and "Comments" sections. NO LATE SUBMISSIONS AFTER THE PENALTY DEADLINE WILL BE GRADED! 5. You are allowed to make multiple attempts of submission but only the latest attempt submitted before the deadline will be gradedStep by Step Solution
There are 3 Steps involved in it
Step: 1
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
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started