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

Write down a Linked list based C program for generating and manipulating student

ID: 3801570 • Letter: W

Question

Write down a Linked list based C program for generating and manipulating students’ record. The program should do the following:

a) Create initial linked list

i) Ask the user for the number of desired records as an input, e.g., n = 10.

ii) Create a Linked list with ‘n’ nodes to representation of the students’ record.

iii) Each node of the linked list should be a structure with three members. The information part of the node should consist of the student_id which should be an integer value and student’s grade point average (GPA) which should be double or float variable. The maximum GPA should be 4.00. You will need another member in the linked list node which will be link part (pointer to student structure). The link part will help in linking the individual student nodes together in forming the linked list.

b) Traverse the linked list representing students’ record to print the student’s id and grade (GPA).

c) Do following insertions in the created linked list 1. Insert at the beginning of the linked list a student with student_id as 1001, and GPA as 3.5

2. Insert at the end of the linked list a student with student_id as 1020 and GPA as 3.75

d) Print the updated linked list representing students’ record.

e) Delete the second record in your updated linked list. Please print the updated linked list representing the students’ record.

Explanation / Answer

#include<stdio.h>
#include<conio.h>
struct Node
{
       int student_id;
       float gpa;
       Node *next;
      
       Node(int id,float g)
       {
           student_id=id;
           gpa=g;
           next=NULL;
       }
  
};
struct List
{
   Node *head;
   List()
   {
       head=NULL;
   }
       void insert()
       {
           int n,idno;
           float grade;
           printf(" enter the number of Nodes in the list :");
           scanf("%d",&n);
           for(int i=0;i<n ;i++)
           {
           printf("enter the details of student %d ",i+1);
           printf("ID_Number :");
           scanf("%d",&idno);
           printf("grade point :");
           scanf("%f",grade);
           if(grade > 4)
           {
               printf("please enter a grade point less than 4");
               i--;
           }
           else
           {
           Node *temp=new Node(idno,grade);
           Node *trav;
           if(head==NULL)
           head=temp;
           else
           {
               for(trav=head; trav->next; trav=trav->next);              
               trav->next=temp;
           }
           }
       }
       }
       void display()
       {
           printf(" ");
           if(head==NULL)
           printf("NO elements to display");
           for(Node *temp=head;temp;temp=temp->next)       //traversal through the list
               printf("%d,%f",temp->student_id,temp->gpa);
       }
       void insertBegin(int idno,float grade)
       {
           Node *temp=new Node(idno,grade);
           temp->next=head;
           head=temp;
       }
       void insertEnd(int idno,float grade)
       {
           Node *temp=new Node(idno,grade);
           Node *trav;
           if(head==NULL)
           head=temp;
           else
           {
               for(trav=head; trav->next; trav=trav->next);              
               trav->next=temp;
           }
       }
       void removeposition(int position)
       {
           if (head == NULL)
           {
           printf("no elements to remove");  
           }
           else
           {
           Node *trav,*follower;
          
           int i;
           for( i=1,follower=NULL,trav = head; i<position; follower=trav,trav=trav->next,i++);
           delete trav;
           if(follower==NULL)   // if only one node exists
           head=NULL;
           else
           follower->next=NULL;
          
               }  
       }  
   };
   int main()
   {
       List student;
       printf(" creating a linked list :");
       student.insert();
       printf(" travesing across the list by printing the data in each node");
       student.display();
       printf(" insertion at the beginning");
       student.insertBegin(1001,3.5);
       printf(" insertion at the end");
       student.insertEnd(1020,3.75);
       printf(" printing the list :");
       student.display();
       printf(" removal at second position :");
       student.removeposition(2);
   }

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote