



Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Community
Ask the community for help and clear up your study doubts
Discover the best universities in your country according to Docsity users
Free resources
Download our free guides on studying techniques, anxiety management strategies, and thesis advice from Docsity tutors
This task was assigned by Prof. Chandrashekar Baag at Amrita Vishwa Vidyapeetham. This assignment is related to Data Structures and Representation course. It includes: Current, Student, Information, System, Options, Display, Specific, Node, Choice
Typology: Exercises
1 / 5
This page cannot be seen from the preview
Don't miss anything!
#include<stdio.h> #include<conio.h> #include<iostream.h> #include<string.h> struct stu { char reg[30]; char name[30]; float marks; struct stu next; }; void menu (); void main () { int choice,srn; struct stu current,p,first,last;char key[30]; first=NULL; last=NULL; clrscr(); cout<<"\nWelcome to student information system. Enter one of the following options:\n\n\t\t- To enter Data press:\t\t\t1\n\t\t- To Display data press:\t\t\t2\n\t\t- To delete last press:\t\t\t3\n\t\t- To insert at start press:\t\t4\n\t\t- To delete from start press:\t\t5\n\t\t- To insert before specific value press:\t6\n\t\t- To insert after specific value press:\t7\n\t\t- To delete specific node press:\t\t8\n\t\t- To exit press:\t\t\t\t10\n"; cin>>choice; while (choice!=10) { switch(choice) { case 1: /For New Data*/ current=new stu; current->next=NULL; cout<<"\n\n\nEnter Registration # of the student:\t"; cin>>current->reg; cout<<"Enter Name of the student:\t"; cin>>current->name; cout<<"Enter Marks of the student:\t"; cin>>current->marks; if(first==NULL) { first=last=current; } else { last->next=current; last=current; } break;
case 2: /To Display/ p=first;srn=1; clrscr();
if(p==NULL)
cout<<"\nThere is no DATA in the list\n"; } else { while (p!=NULL) { cout<<"\n\n Student #: "<<srn; cout<<"\n\n\tRegistration number:\t"<<p->reg; cout<<"\n\tName:\t"<<p->name; cout<<"\n\tMarks:\t"<<p->marks<<"\n"; p=p->next;srn++; } } break; case 3: /To delete last node/ p=first; if(p==NULL) { cout<<"\nThere is no DATA in the list\n"; } if(first==last) { delete(p); first=last=NULL; } else { while (p->next!=last) { p=p->next; } delete(p->next); p->next=NULL; last=p; } break;
case 4: /To insert at start/ current=new stu; current->next=first; cout<<"\n\n\nEnter Registration # of the student:\t"; cin>>current->reg; cout<<"Enter Name of the student:\t"; cin>>current->name; cout<<"Enter Marks of the student:\t"; cin>>current->marks; first=current; break;
case 5: /To delete from start/ if (first==NULL) { cout<<"\nThere is no data in the list\n";
cin>>key; p=first; if(first==NULL) { cout<<"\t there is no student persent in the list\n"; } else { while (strcmp(p->name,key)!=0 && p!=NULL) { p=p->next; } if(p==NULL) { cout<<"\nThe student is not in the list\n"; } else { current=new stu; cout<<"\n\n\nEnter Registration # of the student:\t"; cin>>current->reg; cout<<"Enter Name of the student:\t"; cin>>current->name; cout<<"Enter Marks of the student:\t"; cin>>current->marks;
if(strcmp(last->name,key)==0) { last->next=current; current->next=NULL; last=current; } else { current->next=p->next; p->next=current; } } } break;
case 8: /To Delete Specific node/ cout<<"\nEnter the name of the student you want to delete:\t"; cin>>key; p=first; if(first==NULL) { cout<<"\n There is no data in the list\n"; } else { if(strcmp(first->name,key)==0) { p=p->next; first->next=NULL;
delete(first); first=p; } else { while (strcmp(p->next->name,key)!=0 && p->next->next!=NULL) { p=p->next; } if(p->next->next==NULL && strcmp(p->next->name,key)!=0) { cout<<"\t The student is not in the list\n\n"; } else { p->next=p->next->next; p->next->next=NULL; delete(p->next); }} } break;
case 9: menu(); break;
default: cout<<"\nYou Entered the Wrong choice, Please enter again\n"; } cout<<"\n\n\tEnter choice:\t"; cin>>choice; } }
void menu () { cout<<"\nWelcome to student information system. Enter one of the following options:\n\n\t\t- To enter Data press:\t\t\t1\n\t\t- To Display data press:\t\t\t2\n\t\t- To delete last press:\t\t\t3\n\t\t- To insert at start press:\t\t4\n\t\t- To delete from start press:\t\t5\n\t\t- To insert before specific value press:\t6\n\t\t- To insert after specific value press:\t7\n\t\t- To delete specific node press:\t\t8\n\t\t- To exit press:\t\t\t\t10\n"; }