61 lines
1.4 KiB
C++
61 lines
1.4 KiB
C++
|
// 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 <iostream>
|
||
|
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<total; i++) {
|
||
|
if (head==NULL) {
|
||
|
head = new node;
|
||
|
cout<<"Enter PRN number for student "<<i+1<<":\t";
|
||
|
cin>>head->roll;
|
||
|
cout<<"Enter name for student "<<i+1<<":\t";
|
||
|
cin>>head->name;
|
||
|
head->next=NULL;
|
||
|
point=head;
|
||
|
}
|
||
|
else {
|
||
|
point->next=new node;
|
||
|
point=point->next;
|
||
|
cout << "Enter PRN number for student "<<i+1<<":\t";
|
||
|
cin>>point->roll;
|
||
|
cout << "Enter name for student "<<i+1<<":\t";
|
||
|
cin>>point->name;
|
||
|
point->next=NULL;
|
||
|
}
|
||
|
}
|
||
|
return head;
|
||
|
}
|
||
|
|
||
|
void node::display(node* head) {
|
||
|
node* point=this;
|
||
|
cout<<endl<<"PRNs and names are:"<<endl;
|
||
|
for (point=head; point!=NULL; point=point->next) {
|
||
|
cout<<point->roll<<" -> "<<point->name<<endl;
|
||
|
}
|
||
|
cout<<endl<<"## DESIGNED AND ENGINEERED BY KSHITIJ\n## END OF CODE"<<endl;
|
||
|
}
|
||
|
|
||
|
int main() {
|
||
|
node* head = node::create();
|
||
|
head->display(head);
|
||
|
return 0;
|
||
|
}
|