Sei sulla pagina 1di 11

#define MAX 25

struct add
{

char addr[50];
char city[25];
char state[25];
};

struct stud
{
int roll;
char name[50];
struct add add1;
};
int sdb(struct stud [],int);
struct stud insert();
int create (struct stud [],int);
int search(struct stud [],int);
void edit(struct stud s1[],int n);
void delet(struct stud s1[],int n);
void display(struct stud s1);

main()
{
int n=0;

struct stud st[25];


n=sdb(st,n);
}

/*********************************************************************
SDB FUNCTION
**********************************************************************/
int sdb(struct stud s1[],int n)
{
int ch,i;
do
{

printf("\n\t1\tCREATE A NEW DATABASE");


printf("\n\t2\tINSERT");
printf("\n\t3\tDISPLAY");
printf("\n\t4\tEDIT");
printf("\n\t5\tSEARCH");
printf("\n\t6\tDELETE");
printf("\n\t7\tEXIT");
printf("\n\t\tENTER UR CHOICE\t");
scanf("%d",&ch);
switch(ch)
{
case 1:
n=create(s1,MAX);

break;
case 2:
s1[n]=insert();
n++;
break;
case 3:
if(n==0)
{
printf("\n\tFIRST CREATE DATABAsE!!!");
getch();
break;
}
for(i=0;i<n;i++)
display(s1[i]);
break;
case 4:
if(n==0)
{
printf("\n\tFIRST CREATE DATABASE!!!");
getch();
break;
}
edit(s1,n);
break;
case 5:
if(n==0)

{
printf("\n\tFIRST CREATE DATABASE!!!");
getch();
break;
}
i=search(s1,n);
if(i>=0)
{ printf("\n\tTHE RECORD IS PRESENT");
getch();
display(s1[i]);
}
else
{ printf("\n\t!! NOT FOUND !!");
getch();
}
break;
case 6: if(n==0)
{
printf("\n\tFIRST CREATE DATABADE!!!");
getch();
break;
}
delet(s1,n);
n--;
break;
case 7: exit(0);

default:
printf("\n\n\t\t!!!! INVALID CHOICE !!!!");
getch();
}//end of switch
}while(1);
return n;
}
/**********************************************************
DISPLAY FUNCTION
***********************************************************/
void display(struct stud s1)
{

printf("\n\n\tROLL NO : %d",s1.roll);
printf("\n\tNAME : %s",s1.name);
printf("\n\tADDRESS:\n\t\t%s \n\t\t%s \n\t\t
%s",s1.add1.addr,s1.add1.city,s1.add1.state);
printf("\n\n\t!!! PRESS ANY KEY TO CONTINUE !!!!");
getch();
}
/*************************************************************
INSERT FUNCTION
**************************************************************/
struct stud insert(struct stud s[25],int n)
{
struct stud s1;
int m;

printf("\n\t!!! --- !!!! \n\t ENTER DETAILS\n");


do
{
printf("\n>>> ENTER VALID ROLL NO.\t");
scanf("%d",&s1.roll);
m=v(s1.roll,s,n);
}while(m==1);
printf("\n>>> NAME\t");
scanf("%s",s1.name);
printf("\n>>> ADDRESS \n");
gets(s1.add1.addr);
printf("\n\tCITY\t");
gets(s1.add1.city);
printf("\n\tSTATE\t");
gets(s1.add1.state);
return s1;
}
/*****************************************************
CREATE FUNCTION
*******************************************************/
int create(struct stud s1[25],int n)
{
int i=0;
do
{
s1[i]=insert(s1,n);

i++;
printf("\n\t!!! DO U WANT TO INSERT MORE RECORDS (y/n) !!!");
}while(getchar()=='y');
return i;
}

/**********************************************************
SEARCH FUNCTION
********************************************************/
int search(struct stud s1[],int n)
{
int i,rno;
printf("\n\tENTER ROLL NUMBER\t");
scanf("%d",&rno);
for(i=0;i<n;i++)
{
if(s1[i].roll==rno)
return i;
}
return -1;
}
/*******************************************************
EDIT FUNCTION
********************************************************/
void edit(struct stud s1[],int n)

{
int i;
i=search(s1,n);
if(i>=0)
{
int ch;
do
{
printf("\n\t\t\t\tMODIFY\n");
printf("\n\t\t\t1.ROLL\n\t\t\t2.NAME\n\t\t\t3.ADDRESS\n\t\t\t4.RETURN");
printf("\nEnter your choice: ");
scanf("%d",&ch);
switch(ch)
{
case 1:
printf("\nEnter new roll no: ");
scanf("%d",&s1[i].roll);
break;
case 2:
printf("\nEnter new name: ");
scanf("%s",&s1[i].name);
break;
case 3:
printf("\nEnter new address: ");

printf("\nCity: ");

scanf("%s",&s1[i].add1.city);
printf("\nState: ");
scanf("%s",&s1[i].add1.state);
break;
case 4:
break;
default:printf("\n\nInvalid choice!!\n");
break;
}
}while(ch!=4);
printf("\n\n\tRECORD EDITED");
getch();
}
else
{
printf("\n\t\tRECORD NOT FOUND");
getch();
}
}
/*****************************************************
DELET FUNCTION
*******************************************************/
void delet(struct stud s1[],int n)
{
int i,j;
char ch;

i=search(s1,n);
printf("\n\tdo u wanna delete(y/n)");
if(i>=0&&getch()=='y')
{
for(j=i+1;j<n;j++)
s1[j-1]=s1[j];
printf("\n\n\t!!! DELETED !!!");
getch();
}
else
{
printf("\n\t\tRECORD NOT DELETED");
getch();
}
}
/*****************************************************************
VALIDITY FUNCTION
*****************************************************************/
int v(int r,struct stud s1[25],int n)
{
int i;
for(i=0;i<n;i++)
{
if(s1[i].roll==r)
return 1;
}

return 0;
}