Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Reconsider the implementation of your first programming assignment IN C++ by usi

ID: 639919 • Letter: R

Question

Reconsider the implementation of your first programming assignment IN C++ by using the linked list. First, you need to build a linked list for holding these records. Then, sort them in ascending order using Student ID as a key. Display the sorted output. You are limited to use ONLY the concepts of Linked list.

Data set is provided below:

            Name             ID                    GPA

Alice              8234               2.7

            Mark               2672               3.0

            Joanne        1234               3.7

            John               3291               2.0

Tim                 3212               3.8

            Alford             1034               2.7

            Benson        6290               2.5

            Nancy            4234               3.7

            Oscar              1672               1.0

            Larry               1004               2.7

Explanation / Answer

#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <string>

using namespace std;

struct Student {
   string name;
   double gpa;
   int id;
   Student *next;
}

/*void Student addStudent(Student *root_node) {
   string new_name = "Benny";
   float new_gpa = 3.13;
   int new_id = 0001;

   new_node = root_node;
   if (new_node != null) {
       while (new_node->next != null) {
           new_node = new_code->next;
       }
   }
   cout << "Enter the student's name: ";
   cin >> new_name;

   cout << "Enter the student's GPA: ";
   cin >> new_gpa;

   cout << "Enter the student's ID: ";
   cin >> new_id;
   new_node->next = new Student;
   new_node->name = new_name;
   new_node->gpa = new_gpa;
   new_node->id = new_id;
   new_node->next = 0;

}*/

int main()
{
   string new_name = "Jasmine";
   double new_gpa = 3.35;
   int new_id = 1;

   Student *root;
   Student *new_node;
   root = new Student;
   root->next = 0;
   //addStudent(*root);
   new_node = root;
   while (true) {
      
      
       if (new_node != 0) {
           while (new_node->next != 0) {
               new_node = new_node->next;
           }
           new_node->next = new Student;
           new_node = new_node->next;
           new_node->next = 0;
           new_node->gpa = new_gpa;
           new_node->id = new_id;
          
       }
       break;
   }
   cout << new_node->name << endl;
   return 0;
}