Student record management system using linked list

01 Dec, 2021
Prerequisites: Linked list
Problem: Create a student Record Management system that can perform the following operations:
Insert Student record
Delete student record
Show student record
Search student record
The student record should contain the following items
Name of Student
Roll Number of Student
Course in which Student is Enrolled
Total Marks of Student
Approach: With the basic knowledge of operations on Linked Lists like insertion, deletion of elements in the Linked list, the student record management system can be created. Below are the functionalities explained that are to be implemented:
Check Record: It is a utility function of creating a record it checks before insertion that the Record Already Exist or not. It uses the concept of checking for a Node with given Data in a linked list.
Create Record: It is as simple as creating a new node in the Empty Linked list or inserting a new node in a non-Empty linked list.
Search Record: Search a Record is similar to searching for a key in the linked list. Here in the student record key is the roll number as roll number is unique for every student.
Delete Record: Delete Record is similar to deleting a key from a linked list. Here the key is the roll number. Delete record is an integer returning function it returns -1 if no such record with a given roll number is found otherwise it deletes the node with the given key and returns 0.
Show Record: It shows the record is similar to printing all the elements of the Linked list.
Exception Handling
Although the implementation of exception handling is quite simple few things must be taken into consideration before designing such a system:
Roll Number must be used as a key to distinguish between two different records so while inserting record check whether this record already exists in our database or not if it already exists then immediately report to the user that record already exists and insert that record in the database.
The record should be inserted in sorted order for this to make the roll number a key and use the inserting node in the sorted linked list.
Below is the implementation of the above approach:
C++
// C++ program for the above approach#include <bits/stdc++.h>using namespace std; // Node Classclass Node {public:    int roll;    string Name;    string Dept;    int Marks;    Node* next;}; // Stores the head of the Linked ListNode* head = new Node(); // Check Function to check that if// Record Already Exist or Notbool check(int x){    // Base Case    if (head == NULL)        return false;     Node* t = new Node;    t = head;     // Traverse the Linked List    while (t != NULL) {        if (t->roll == x)            return true;        t = t->next;    }     return false;} // Function to insert the recordvoid Insert_Record(int roll, string Name,                   string Dept, int Marks){    // if Record Already Exist    if (check(roll)) {        cout << "Student with this "             << "record Already Exists\n";        return;    }     // Create new Node to Insert Record    Node* t = new Node();    t->roll = roll;    t->Name = Name;    t->Dept = Dept;    t->Marks = Marks;    t->next = NULL;     // Insert at Begin    if (head == NULL        || (head->roll >= t->roll)) {        t->next = head;        head = t;    }     // Insert at middle or End    else {        Node* c = head;        while (c->next != NULL               && c->next->roll < t->roll) {            c = c->next;        }        t->next = c->next;        c->next = t;    }     cout << "Record Inserted "         << "Successfully\n";} // Function to search record for any// students Record with roll numbervoid Search_Record(int roll){    // if head is NULL    if (!head) {        cout << "No such Record "             << "Available\n";        return;    }     // Otherwise    else {        Node* p = head;        while (p) {            if (p->roll == roll) {                cout << "Roll Number\t"                     << p->roll << endl;                cout << "Name\t\t"                     << p->Name << endl;                cout << "Department\t"                     << p->Dept << endl;                cout << "Marks\t\t"                     << p->Marks << endl;                return;            }            p = p->next;        }         if (p == NULL)            cout << "No such Record "                 << "Available\n";    }} // Function to delete record students// record with given roll number// if it existint Delete_Record(int roll){    Node* t = head;    Node* p = NULL;     // Deletion at Begin    if (t != NULL        && t->roll == roll) {        head = t->next;        delete t;         cout << "Record Deleted "             << "Successfully\n";        return 0;    }     // Deletion Other than Begin    while (t != NULL && t->roll != roll) {        p = t;        t = t->next;    }    if (t == NULL) {        cout << "Record does not Exist\n";        return -1;        p->next = t->next;         delete t;        cout << "Record Deleted "             << "Successfully\n";         return 0;    }} // Function to display the Student's// Recordvoid Show_Record(){    Node* p = head;    if (p == NULL) {        cout << "No Record "             << "Available\n";    }    else {        cout << "Index\tName\tCourse"             << "\tMarks\n";         // Until p is not NULL        while (p != NULL) {            cout << p->roll << "    \t"                 << p->Name << "\t"                 << p->Dept << "\t"                 << p->Marks << endl;            p = p->next;        }    }} // Driver codeint main(){    head = NULL;    string Name, Course;    int Roll, Marks;     // Menu-driven program    while (true) {        cout << "\n\t\tWelcome to Student Record "                "Management System\n\n\tPress\n\t1 to "                "create a new Record\n\t2 to delete a "                "student record\n\t3 to Search a Student "                "Record\n\t4 to view all students "                "record\n\t5 to Exit\n";        cout << "\nEnter your Choice\n";        int Choice;         // Enter Choice        cin >> Choice;        if (Choice == 1) {            cout << "Enter Name of Student\n";            cin >> Name;            cout << "Enter Roll Number of Student\n";            cin >> Roll;            cout << "Enter Course of Student \n";            cin >> Course;            cout << "Enter Total Marks of Student\n";            cin >> Marks;            Insert_Record(Roll, Name, Course, Marks);        }        else if (Choice == 2) {            cout << "Enter Roll Number of Student whose "                    "record is to be deleted\n";            cin >> Roll;            Delete_Record(Roll);        }        else if (Choice == 3) {            cout << "Enter Roll Number of Student whose "                    "record you want to Search\n";            cin >> Roll;            Search_Record(Roll);        }        else if (Choice == 4) {            Show_Record();        }        else if (Choice == 5) {            exit(0);        }        else {            cout << "Invalid Choice "                 << "Try Again\n";        }    }    return 0;}
Output: Below are the screenshots of the output of the various functions provided by the student record management system:
Create Record:  
Show Record:  
Delete Record:  
Search Record:  
Student Record:  
sagar0719kumar
simmytarika5
Linked Lists
Technical Scripter 2020
C++
C++ Programs
Project
Technical Scripter
CPP
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Sorting a vector in C++
Polymorphism in C++
std::string class in C++
Friend class and function in C++
Pair in C++ Standard Template Library (STL)
Header files in C/C++ and its uses
Sorting a Map by value in C++ STL
Program to print ASCII Value of a character
How to return multiple values from a function in C or C++?
C++ program for hashing with chaining