Sheridan College Page 1 of 3 PROG20799: Assignments N3 Winter 2020 typedef struct node { size_t id; char* name; float gpa; struct node *next; } student_t; PROG20799: Data Structures and Algorithms in...

1 answer below »
I need to create a project on Netbeans using C/C++ application and write a code in C to fulfill all requirements given in pdf file. main.c should be used as template, and code should be written only inside functions. exercise8_2 is a simpler version of what needs to be done. Please use the code when possible to make the assignment look similar.


Sheridan College Page 1 of 3 PROG20799: Assignments N3 Winter 2020 typedef struct node { size_t id; char* name; float gpa; struct node *next; } student_t; PROG20799: Data Structures and Algorithms in C Evaluation: 10 points, 5% of your final grade. Due date: See SLATE. Late submission: 10% per day penalty, up to 3 days. In this assignment you need to create a linked list of structures to store student’s info. Your goal is to collect and sort students' records by GPA, and print them in a table-like output. Please check the Demo version: https://youtu.be/i-DKOCZVX7s You must use a linked list and the following structure: Requirements: • Please download and use main.c.txt template file. You must only use this template file with function prototypes or you’ll get a zero grade. • You absolutely must use the structure mentioned above. You’ll get a zero grade if you use anything else to store student’s info. • Structures must be allocated on the HEAP. You’ll get a zero grade otherwise. • You must set initial student id to 1000 and auto-increment it when a new student is added. • You must use fgets() to get both the name and gpa of the student (check MAX_LEN macros). • You must allocate student's name on the HEAP and use appropriate strto…() function to convert input to floating-point value. Do NOT use scanf(), sscanf() or atof() anywhere! • You must use Insertion into Sorted Linked List algorithm when you insert a new node (with student’s info) into the Linked List: http://babanski.com/files/prog20799/assignment3/ • You cannot modify the main() function given to you in the template file. • You must use and implement the following functions (see template file): student_t* createNode(); // function to create the node student_t* createList(); // function to create the list void displayList(…………..); // function to display the list void insertNode(................); // function to insert node into the sorted list. void removeList(................); // function to delete the linked list • You must destroy the linked list and deallocate memory at the end of the program. Please use function removeList(..) accordingly. • Your program must work similarly to the Demo version posted on Youtube, ignore the incorrect input, have same error notifications, sort the records, etc. • Your solution should have optimal time and space complexity. https://youtu.be/i-DKOCZVX7s http://babanski.com/files/prog20799/assignment3/ Sheridan College Page 2 of 3 PROG20799: Assignments N3 Winter 2020 Hints: 1. The reason we want to use a linked list instead of an array is because you can “sort” the linked list during console input. I.e. you create a new node, get student’s GPA and insert the node into the linked list in such a way that it is always sorted by students’ GPA. Array of structures can't be used because you don't know how many students you have and then you can't sort it on-the-fly as easy. 2. When you enter empty name then it is assumed there are no more nodes to add to the list. 3. Function createNode() must collect student’s info from the console, allocate memory on the HEAP for the node and for the name, and return memory address of the node. 4. In the removeList() function you need to de-allocate memory for the name first and then for the node itself. 5. You should allocate memory for student’s name on the HEAP using calloc() function. Don’t forget to use strlen(name)+1 as size. 6. Do not forget about special cases in Step 5: http://babanski.com/files/prog20799/assignment3/ 7. Check the demo posted on YouTube. Demo input and output: http://babanski.com/files/prog20799/assignment3/ Sheridan College Page 3 of 3 PROG20799: Assignments N3 Winter 2020 Submission: This is an individual assignment. Even partially copied code will be subject to regulations against academic integrity. Do NOT discuss your solution with anybody else. Posting this assignment and/or solution on the Internet is a violation of the academic integrity policy. • Please make sure your code is POSIX-compliant (works in NetBeans/Cygwin)! • Please save main.c as a text with extension .txt • You must upload main.txt file to the Assignment Dropbox by the due date. • Your submission must be unique or have references. • Please self-evaluate and self-grade your code in the comments section of the Dropbox. • Late submissions are penalized 10% / day (1 point / day), up to -3 points. Only submissions that are up to 3 days late will be accepted. Grading Scheme: • See Main requirements and also Course_Introduction.pdf. Deductions will be applied if partial functionality is provided. • You’ll get zero grade if your code doesn’t compile. • Any compilation warning is a major mistake. • "Debugging code" or commented out "old code" is a minor mistake. • Please check assignment and submissions requirements for any additional deductions. PROG20799: Data Structures and Algorithms in C // Assignment N3 Template #include #include #include #define FLUSH stdin=freopen(NULL,"r",stdin) #define MAX_LEN 50 typedef struct node { char *name; float gpa; size_t id; struct node *next; } student_t; // You must use the prototypes below. Do NOT declare any other functions! // You must fix the prototypes below: Make sure you use the correct parameter(s) student_t* createNode(); // function to create the node student_t* createList(); // function to create the list void displayList(..........); // function to display the list void insertNode(................); // function to insert node into the sorted list. void removeList(................); // function to delete the linked list int main() { printf("\nCreating List of students:\n\n"); student_t *head = createList(); displayList(head); removeList(&head); return 0; } // Your code goes below!! // Declare the functions according to prototypes. // Exercise 8.2: Template #include #include #include #define FLUSH stdin=freopen(NULL,"r",stdin) #define MAX_LEN 50 typedef struct node { char name[MAX_LEN]; struct node *next; } student_t; //return HEAD of the linked list student_t* createList(); //create node of the linked list student_t* createNode(); //prints the linked list void displayList(student_t*); //enters another value at the end of the linked list void pushBack(student_t**); //enters another value at the beginning of the linked list void pushFront(student_t**); //remove the first element of the linked list void removeFirst(student_t**); //remove the last element of the linked list void removeLast(student_t**); //remove any item in the linked list by its index void removeByIndex(student_t**, int); // -------------------------------------- int main() { printf("== Creating List:\n"); student_t* head = createList(); printf("== PushBack:\n"); pushBack(&head); printf("== PushFront:\n"); pushFront(&head); printf("== Printing Linked List:\n"); displayList(head); printf("== Remove first:\n"); removeFirst(&head); displayList(head); printf("== Remove last:\n"); removeLast(&head); displayList(head); printf("== Remove by index:\n"); removeByIndex(&head, 1); displayList(head); return 0; } student_t* createList() { student_t* head = NULL, *new_node, *current = NULL; while ((new_node = createNode()) != NULL) { if (current == NULL) { head = new_node; } else { current->next = new_node; } current = new_node; } return head; } student_t* createNode() { student_t* record = NULL; char tmp[MAX_LEN] = {0}; printf("Please enter name: "); fgets(tmp, sizeof (tmp), stdin); FLUSH; // We get rid of '\n' character at the end : tmp[strcspn(tmp, "\n")] = 0; if (strlen(tmp) > 1) { record = (student_t*) malloc(sizeof (student_t)); if (record == NULL) { printf("Cannot allocate memory for person!"); exit(1); } strncpy(record->name, tmp, sizeof (record->name)); record->next = NULL; // this MUST be done! } // Returns NULL if no record! return record; } void displayList(student_t* head) { if (head == NULL) { printf("Linked list is empty\n"); } else { student_t* current = head; int i = 1; while (current != NULL) { printf("%d. %s\n", i, current->name); current = current->next; i++; } } } void pushBack(student_t** head) { if (*head == NULL) {
Answered Same DayMar 09, 2021

Answer To: Sheridan College Page 1 of 3 PROG20799: Assignments N3 Winter 2020 typedef struct node { size_t id;...

Arun Shankar answered on Mar 11 2021
152 Votes
// Assignment N3 Template
#include
#include
#include
#define FLU
SH stdin=freopen(NULL,"r",stdin)
#define MAX_LEN 50
typedef struct node {
char *name;
float gpa;
size_t id;
struct node *next;
} student_t;
// You must use the prototypes below. Do NOT declare any other functions!
// You must fix the prototypes below: Make sure you use the correct parameter(s)
student_t* createNode(); // function to create the node
student_t* createList(); // function to create the list
void displayList(student_t*); // function to display the list
void insertNode(student_t**,student_t*); // function to insert node into the sorted list.
void removeList(student_t**); // function to delete the linked list
int main()
{
printf("\nCreating List of students:\n\n");
student_t *head = createList();
displayList(head);
...
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here