Program functions
The program has its operation revolving around logging in and establishing whether as a teacher or a student. If as a teacher, one can choose among the actions within the privileges of a teacher such as listing, inserting, modifying or deleting a course, inserting or modifying scores, and finally exiting the program when done. If one is a student the possible actions in the program are selecting a course, viewing the selected course, viewing one’s GPA, and finally exiting the program. All these actions are made easier in the program by writing functions for basic operations such as insertion, deletion, modification, and all the other necessary operations.
The data entry function serves the purpose of entering various data into text files that serve as storage for the program. The text files will hold data such as students’ GPA scores and a list of all courses.
For example, the above diagram shows a code snippet for the data entry on the text files. The FILE *fp; statement finds files and opens them and the program proceeds by checking for the necessary file to insert data. After the data entry, the file is closed as shown by the code snippet below.
The insert and delete functions serve the purposes of adding items and removing items respectively from the stored data. The modify function, on the other hand, serves the purpose of updating the values for various data. The insert function can insert at the beginning, the end, or an arbitrary position in the data sets. The modified function first proceeds by searching for an element and if it is found it replaces it with the new value. The delete function proceeds by finding the element and then removing it. As shown in the code snippet below, the function first finds the file, opens it, and then finds the course as selected by details and then deleting it.
The select operation is used along with another subsequent operation such as delete or update. The select function serves the purpose of pinpointing the element being searched for before subsequent operations can be applied to it. The exit system function provides closure to the program by terminating the program after the user is accomplished a task.
Program time complexity analysis
This section aims at trying to calculate or determine the time it would take to run the student score program to achieve any task. This form of establishing time complexity, however, does not represent the actual time the program takes. This process proceeds by counting the elementary operation performed when executing the program. The elementary operations in the program include logging in, presenting both student and teacher menus, checking GPA, selecting various values, entry of data, inserting values, deleting values, searching and listing values.
Some operations search as checking GPA and modifying variable values will have to be broken down to basic operations such as searching, selecting, updating, and displaying for easy calculation of time complexity. The time complexity is dependent on the input and hence may be measured by the cumulative time statements take to execute. The operations requiring arithmetic calculations will have a time complexity of O(1) hence a task with several calculations will have an overall complexity of O(n). this includes tasks such as calculating the GPA for each student.
Other tasks that do not require recursive procedures or executing loops, for example, logging in will have a complexity of O(1). When inserting a value in a list the complexity is usually O(n). This program employs a linked list to store values to leverage the advantage of easier operations such as insertion. When inserting in a linked list, the time complexity is usually constant time unlike in an array that would involve several operations. Inserting at the beginning of the end of the linked list will have a complexity of O(1). Inserting at an arbitrary position on the linked list, on the other hand, would be best done linearly which would consequently mean the complexity of O(n).
When deleting from a linked list, the element will have to be searched first hence progressing with time complexity of O(n) until finding the element and constant time in deleting it. A deletion operation will hence have a complexity of O(n). An update process will have the same complexity as deleting since it too involves searching the element first before replacing it. Entering of data will for the first time will have a constant time complexity. Searching, just like deleting, will have a complexity of O(n). Summarily, the overall complexity of the program when accomplishing a task can be measured by summing the complexities of the involved operations.
Program relation to data structures
This program uses the linked list data structure to store data. This is an obvious choice since linked lists are very useful and offer many advantages. Linked lists allow very quick insertion of elements as an insertion at the end of the beginning is usually inserted in constant time O(1). Also, linked lists have effective memory utilization since memory is only allocated if there is a newly added element.
Linked lists usually employ a node to store and a pointer to point to the next node. This allows the advantage of being well suited when the size of data is unknown as otherwise, the arrays would be better suited. The code snippets below show the creation of linked list student node and inserting value to the data structure respectively. The (*headofList) keyword specifies that the insertion will be done at the beginning of the linked list.