From dc66a90d9b60644b7e63c8485bdcd65efd965d21 Mon Sep 17 00:00:00 2001 From: Kshitij Date: Tue, 17 Oct 2023 18:21:09 +0530 Subject: [PATCH] Added assignment-19 (singly linked list for PRN and name) which takes PRN and names for n students and displays it --- assignment-19.cpp | 60 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 assignment-19.cpp diff --git a/assignment-19.cpp b/assignment-19.cpp new file mode 100644 index 0000000..323c6f6 --- /dev/null +++ b/assignment-19.cpp @@ -0,0 +1,60 @@ +// This code creates a linked list to store PRN and names of n number of students. +// We're not sure if there's anything more to it. For now, it only stores and displays. + +#include +using namespace std; + +class node { + int roll; + string name; + node *next; + + public: + static node* create(); + void display(node* head); +}; + +node* node::create() { + int total; + node *head=NULL; + node* point=NULL; + cout<<"Total number of students are:\t"; + cin>>total; + + for (int i=0; i>head->roll; + cout<<"Enter name for student "<>head->name; + head->next=NULL; + point=head; + } + else { + point->next=new node; + point=point->next; + cout << "Enter PRN number for student "<>point->roll; + cout << "Enter name for student "<>point->name; + point->next=NULL; + } + } + return head; +} + +void node::display(node* head) { + node* point=this; + cout<next) { + cout<roll<<" -> "<name<display(head); + return 0; +}