Created
May 9, 2016 00:10
-
-
Save agaikwad123/b2ff99e80fa40a6c9193e8dda32d6c15 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Program details: | |
Various operations like read,insert,delete,print,sort,modify for student database | |
*/ | |
#include <stdio.h> | |
#include <conio.h> | |
#include <string.h> | |
typedef struct student | |
{ int rollno; | |
char name[20]; | |
int marks; | |
}student; | |
void insert( student st[],int position,int n); | |
void Delete(student st[],int position,int n); | |
int search(student st[],int rollno,int n); | |
void print(student st[],int n); | |
void read(student st[],int n); | |
void sort(student st[],int n); | |
void modify(student st[],int n); | |
main() | |
{ student st[30]; | |
int n,i,op,position,rollno; | |
do{ | |
printf("\n1)create\n2)insert\n3)delete\n4)search\n5)print\n6)Sort\n7)Modify"); | |
printf("\n8)Quit"); | |
printf("\nEnter Your Choice:"); | |
scanf("%d",&op); | |
switch(op) | |
{ case 1: printf("\nEnter No. of student:"); | |
scanf("%d",&n); | |
read(st,n); | |
break; | |
case 2: printf("\n enter the position(no of records=%d):",n); | |
scanf("%d",&position); | |
if(position<=n+1) | |
{ | |
insert(st,position,n); | |
n++; | |
print(st,n); | |
} | |
else | |
printf("\n can not insert"); | |
break; | |
case 3:printf("\n enter the rollno : "); | |
scanf("%d",&rollno); | |
position=search(st,rollno,n); | |
if(position != -1 ) | |
{ | |
Delete(st,position,n); | |
n--; | |
print(st,n); | |
} | |
else | |
printf("\n can not delete "); | |
break; | |
case 4: printf("\nenter rollno:"); | |
scanf("%d",&rollno); | |
position=search(st,rollno,n); | |
if(position==-1) | |
printf("\nnot found"); | |
else | |
{ printf("\n found at location=%d",position+1); | |
printf("\n %s\t%d\t%d",st[position].name,st[position].rollno,st[position].marks); | |
} | |
break; | |
case 5: print(st,n); | |
break; | |
case 6: sort(st,n);print(st,n);break; | |
case 7: modify(st,n);break; | |
} | |
}while(op!=8); | |
} | |
void insert( student st[],int position,int n) | |
{ int i; | |
printf("\n enter data(name rollno marks): "); | |
for(i=n-1;i>=position-1;i--) /*index is 1 less than position*/ | |
st[i+1]=st[i]; | |
scanf("%s%d%d",st[position-1].name,&st[position-1].rollno,&st[position-1].marks); | |
} | |
void Delete(student st[],int position,int n) | |
{ int i; | |
for(i=position+1;i<n;i++) | |
st[i-1]=st[i]; | |
} | |
int search(student st[],int rollno,int n) | |
{ int i; | |
for(i=0;i<n;i++) | |
if(rollno==st[i].rollno) | |
return(i); | |
return(-1); | |
} | |
void print(student st[],int n) | |
{ int i; | |
for(i=0;i<n;i++) | |
printf("\n%20s%5d%5d",st[i].name,st[i].rollno,st[i].marks); | |
} | |
void read(student st[],int n) | |
{ int i; | |
printf("\n enter data(name rollno marks): "); | |
for(i=0;i<n;i++) | |
scanf("%s%d%d",st[i].name,&st[i].rollno,&st[i].marks); | |
} | |
void modify(student st[], int n) | |
{ | |
int rollno,i; | |
printf("\nEnter the Rollno : "); | |
scanf("%d",&rollno); | |
i=search(st,rollno,n); | |
if(i==-1) | |
printf("\nNo such rollno "); | |
else | |
{ | |
printf("\n enter data(name rollno marks): "); | |
scanf("%s%d%d",st[i].name,&st[i].rollno,&st[i].marks); | |
} | |
} | |
void sort(student st[],int n) | |
{ int i,j; | |
student temp; | |
for(i=1;i<n;i++) | |
for(j=0;j<n-i;j++) | |
if(st[j].rollno > st[j+1].rollno) | |
{ | |
temp=st[j]; | |
st[j]=st[j+1]; | |
st[j+1]=temp; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment