#include<
#include<
#include<
#include<
#include<
using namespace std;
char reg[10];
struct student{
char regno[10];
char name[20];
char class1[10];
int marks[3];
student *link;
}*temp,*head,*t,*x;
int find()
{ int str=0;
t=head;
x=head;
cout<<"\n\nPlease enter the Regno to find : "; cin>>reg;
if(head!=NULL)
{
do
{
str=strcmpi(t->regno,reg) ;
if (str==0) //||t->regno==reg)
{
return 1;
}
x=t;
t=t->link;
}while(t->link!=NULL);
str=strcmpi(t->regno,reg) ;
if (str==0) // ||t->regno==reg)
{
return 1;
}
}
else
return 0;
}
void add()
{
int choice;
clrscr();
cout<<"\n-= Add Student =-"; cout<<"\n1. Add In Beginning"; cout<<"\n2. Add In Between"; cout<<"\n3. Add At End"; cout<<"\nSelection : "; cin>>choice;
temp=new student;
switch(choice)
{
case 1:
if(head==NULL)
{
head=temp;
temp->link=NULL;
}
else
{
temp->link=head;
head=temp;
}
break;
case 2:
if(find())
{
temp->link=t->link;
t->link=temp;
}
else
{cout<<"\nInvalid Regno!!"; free (temp); goto lab; } break; case 3: temp->link=NULL;
t=head;
while(t->link!=NULL)
t=t->link;
t->link=temp;
break;
default:
{cout<<"\nInvalid Selection"; free (temp); goto lab; } } cout<<"\nPlease enter the student Regno : "; gets(temp->regno);
cout<<"\nPlease enter the student Name : "; gets(temp->name);
cout<<"\nPlease enter the student Class : "; gets(temp->class1);
cout<<"\nPlease enter the Marks Of The Subject 1: "; cin>>temp->marks[0];
cout<<"\nPlease enter the Marks Of The Subject 2: "; cin>>temp->marks[1];
cout<<"\nPlease enter the Marks Of The Subject 3: "; cin>>temp->marks[2];
lab:
}
void display()
{
system("cls");
cout<<"\nProgress Report"; if(find()) { cout<<"\nRegno :"<
cout<<"\nName :"<
cout<<"\nClass :"<
cout<<"\n--------------------------"; cout<<"\n\nMarks"; cout<<"\nSubject 1 : "<
cout<<"\nSubject 2 : "<
cout<<"\nSubject 3 : "<
}
else
cout<<"\n Invalid Reg No"; } void del() { if(find()) { if(head==t) { head=t->link;
free(t);
}
else if(t->link==NULL)
{
x->link=NULL;
free(t);
}
else
{
x->link=t->link;
free(t);
}
}
else
cout<<"\nInvalid Reg No"; } void main() { system("cls"); int choice; head=NULL; while(1) { system("cls"); cout<<"\n-={Student Details Using Singly Linked List}=-"; cout<<"\nPlease Select an Operation To Perform"; cout<<"\n1. Add a Student"; cout<<"\n2. Display Student Details"; cout<<"\n3. Delete a Student"; cout<<"\n4. Exit"; cout<<"\nSelection : "; cin>>choice;
switch(choice)
{
case 1:
add();
break;
case 2:
display();
break;
case 3:
del();
break;
case 4:
exit(0);
break;
default:
cout<<"\nInvalid Selection"; } getch(); } }
No comments:
Post a Comment