Done By: Prof.Dhumane A.V. VIIT, Pune
*/
#include
#include
struct student
{
int roll;
char name[30];
char clas[20];
};
int insert_record(struct student *stud,int records_count)
{
records_count++;
printf("\nEnter the roll number of the student ");
scanf("%d",&stud[records_count].roll);
printf("\n Enter the name of the student");
scanf("%s",stud[records_count].name);
printf("\n Enter the class of the student");
scanf("%s",stud[records_count].clas);
return records_count;
}
void display_records(struct student *stud,int records_count)
{
int i;
clrscr();
printf("\n----------------------------------------------------------");
printf("\nROLL\t\tNAME \t\tCLASS");
printf("\n----------------------------------------------------------");
for(i=0;i<=records_count;i++)
{
printf("\n%d\t\t%s\t\t%s",stud[i].roll,stud[i].name,stud[i].clas);
}
getch();
}
int delete_record(struct student*stud,int records_count)
{
int roll,i=0,found=0;
printf("\nEnter the roll number of the student to be deleted ..");
scanf("%d",&roll);
while(i<=records_count)
{
if(stud[i].roll==roll)
{
found=1;
while(i
stud[i]=stud[i+1];
i++;
}
records_count--;
break;
}
i++;
}
if(found==0)
{
printf("\nRecord not found");
}
else
{
printf("\nRecord deleted successfully");
}
return records_count;
}
void modify_record(struct student*stud,int records_count,int roll)
{
int i=0;
char ans;
while(i<=records_count)
{
if(stud[i].roll==roll)
{
printf("\n Want to change roll number? [y/n]");
ans=getche();
if(ans!='n')
{
printf("\n Enter new roll number ");
scanf("%d",&stud[i].roll);
}
printf("\n Want to change Name? [y/n]");
ans=getche();
if(ans!='n')
{
printf("\n Enter new Name ");
scanf("%s",&stud[i].name);
}
printf("\n Want to change Class? [y/n]");
ans=getche();
if(ans!='n')
{
printf("\n Enter new Class ");
scanf("%s",&stud[i].clas);
}
}
i++;
}
}
void main()
{
struct student stud[50];
int records_count=-1,choice,roll;
clrscr();
while(1)
{
printf("\n1. Insert Record");
printf("\n2. Display records");
printf("\n3. Delete record");
printf("\n4. Modify record");
printf("\n5. Exit");
printf("\n Enter your choice ");
scanf("%d",&choice);
switch(choice)
{
case 1: records_count=insert_record(stud,records_count);
break;
case 2: display_records(stud,records_count);
break;
case 3: records_count=delete_record(stud,records_count);
break;
case 4:
printf("\nEnter the roll number of the record to be modified ");
scanf("%d",&roll);
modify_record(stud,records_count,roll);
break;
case 5: exit(0);
}
}
}
No comments:
Post a Comment