Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
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;
/*********************************************************************
SDB FUNCTION
**********************************************************************/
int sdb(struct stud s1[],int n)
{
int ch,i;
do
{
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;
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;
}