Store Details of a Student in Linked list
Hello in this program you will learn how to Store Details of a Student in Linked list, also we learn to process them with an Action Button.
Before understanding this Program, you should have knowledge about the following topics.
C++ Program to Store Details
#include <iostream> using namespace std; class sNode{ public: string Name; string rollNo; sNode *next; sNode(){ next=nullptr; } }; class LinkedList{ sNode *head; public: LinkedList(){ head = nullptr; } void insert_at_beginning(string name, string rNo ){ sNode *temp = new sNode(); temp->Name = name; temp->rollNo = rNo; temp->next = head; head = temp; } void print(){ if (head == NULL){ cout<<"List is empty"<<endl; } else{ sNode *temp = head; cout<<"Linked List: "<<endl; cout<<"Name\t\tRollNo"<<endl; while (temp != NULL){ cout<<temp->Name<<"\t\t"<<temp->rollNo<<endl; temp = temp->next; } } } }; int main() { cout<<"1 to Insert at the beginning"<<endl; cout<<"2 to Display"<<endl; cout<<"3 to Exit"<<endl; int choice,v,p; string n,r; LinkedList ll; do { cout<<"\nEnter Your Choice: "; cin>>choice; switch (choice) { case 1: cout<<"Enter Name: "; cin>>n; cout<<"Enter RollNO: "; cin>>r; ll.insert_at_beginning(n,r); break; case 2: ll.print(); break; } } while (choice != 3); cout<<"program Ends"; return 0; }
Student DataBase system in Cpp
Output
Here the program will provide you 3 Options.
Now we’re giving commands to the executive programs.
After submitting it will represent choice, now we’ll enter our choice again for Displaying.
After Displaying the data, again it will provide an Option for next. But we saw there is a 3 option for Exit, so we choose 3.
♥ Red represents User Inputted Value.
♥Blue Represent compiler Output.
When you enter option 2, then it will displayed you a msg like “List is Empty“