Ask Question

Name:
Title:
Your Question:

Answer Question

Name:
Your Answer:
User Submitted Source Code!


Description:
  kjhgkj
Language: C/C++
Code:
#include<stdio.h>
#include<stdlib.h>
#include<conio.h>
#include<string.h>

struct student
{
int Tmarks;
int fine;
char name[100];
char roll[10];
struct student *next;
};
struct student *first=NULL,*last=NULL,*k;
void create()
{
if(first==NULL)
{
first=(struct student*)malloc(sizeof(struct student));
printf("nEnter the first name of the student:");
scanf("%s",first->name);
printf("nEnter the roll number of the student:");
scanf("%s",first->roll);
printf("nEnter the total marks of the student;");
scanf("%d",first->Tmarks);
printf("nenter the fines to be settled by the student:");
scanf("%d",first->fine);
first->next=NULL;
last=first;
}
else
{
k=(struct student*)malloc(sizeof(struct student));
printf("nEnter the name of the student:");
scanf("%s",k->name);
printf("nEnter the roll number of the student:");
scanf("%s",k->roll);
printf("nEnter the total marks of the student;");
scanf("%d",k->Tmarks);
printf("nenter the fines to be settled by the student:");
scanf("%d",k->fine);
k->next=NULL;
last->next=k;
last=k;
}
}


void display()
{
struct student *t=first;
while(t!=NULL)
{
printf("nThe roll number of the student:%s",t->roll);
printf("nName of the student:%s",t->name);
printf("nTotal Marks of the student:%d",t->Tmarks);
printf("nFine to be settled by the student:%d",t->fine);

t=t->next;
}
}


void insertafter()
{
char r[10];
struct student *t;
int flag=0;
printf("nEnter the roll number u wanna insert after that:");
scanf("%s",&r);

t=first;
while(t!=NULL)
{
if(strcmp(r,t->roll)==0)
{
k=(struct student*)malloc(sizeof(struct student));
printf("nEnter the first name of the student:");
scanf("%s",k->name);
printf("nEnter the roll number of the student:");
scanf("%s",k->roll);
printf("nEnter the total marks of the student;");
scanf("%d",k->Tmarks);
printf("nenter the fines to be settled by the student:");
scanf("%d",k->fine);
k->next=t->next;
t->next=k;
flag=1;
break;
}
t=t->next;
}
if(flag==0)
printf("nThe element not found!!!");
}


void del()
{
struct student *back,*t,*k;
char r[10];
int flag=0;
printf("nEnter the roll number u wanna delete:");
scanf("%s",r);
if(strcmpi(r,first->roll)==0)
{
first=first->next;
flag=1;
}
else
{
back=first;
k=first->next;
while(k!=NULL)
{
if(strcmpi(r,k->roll)==0)
{
back->next=k->next;
flag=1;
break;
}
}
}
if(flag==0)
printf("nThe element not found!!!");
}


void search()
{
char r[10];
struct student *t;
int flag=0;
printf("nEnter the roll number u wanna search:");
scanf("%s",r);

t=first;
while(t!=NULL)
{
if(strcmpi(r,t->roll)==0)
{
printf("nThe roll number found in the list!!!nHis name is %s",t->name);
flag=1;
break;
}t=t->next;
}
if(flag==0)
printf("nThe roll number not in database!!");
}

void main()
{
int o;
clrscr();
while(o!=0)
{
printf("nMENUn");
printf("nEnter 1 for inserting a record");
printf("nEnter 2 for displaying database");
printf("nEnter 3 for inserting in Between");
printf("nEnter 4 for deleting a record");
printf("nEnter 5 for searching a record");
printf("nEnter 0 for exit!");
printf("nEnter the choice:");
scanf("%d",&o);
switch(o)
{
case 1:create();break;
case 2:display();break;
case 3:insertafter();break;
case 4:del();break;
case 5:search();break;
case 0:exit(0);break;
default:printf("nYou have entered a wrong choice!!!");
}
}
getch();
}

          
Comments: