/*---------------------------------------------------------------------------------------
Program : Write a program to perform following
operations on any
database:Add, Delete,Modify, Display, Search
& Sort etc.
Created
By : JABIR DAUD PATHAN
Branch :
COMPUTER ENGINEERING
-------------------------------------------------------------------------------------------*/
/*--------------------<< Header File
>>----------------------*/
#include<stdio.h>
#include<conio.h>
/*------------<<
Global Declaration of Functions
>>------------*/
void
accept(void);
void
add(void);
void
del(void);
void
modify(void);
void
display(void);
void
search(void);
void
sort(void);
struct
Student
{
int roll_no;
char name[25];
int marks;
}s[10],temp;
int
i=0,j=0,ch,n,pos; //Global Declaration of variables
/*-------<<
function defination for accept student details >>------*/
void
accept()
{
printf("\nEnter the total no. of
student==>");
scanf("%d",&n);
for(i=0;i<n;i++)
{
printf("\n\nEnter the details of
student %d==>\n",i+1);
printf("\n\tEnter the
roll_no==>");
scanf("%d",&s[i].roll_no);
//accept roll no of student
printf("\n\tEnter the name of
student==>");
scanf("%s",&s[i].name); //accept name of student
printf("\n\tEnter the
marks==>");
scanf("%d",&s[i].marks);
//accept marks of student
}
}
/*-----------<<
function defination for add record >>-------------*/
void
add()
{
int k,m;
printf ("\nEnter how many member you
want to add in data==>");
scanf("%d",&m);
for(k=0;k<m;k++)
{
for(i=n;i>=n;i--)
{
s[i+1]=s[i];
printf("\n\tEnter the
roll_no==>");
scanf("%d",&s[i].roll_no);
printf("\n\tEnter the name of
student==>");
scanf("%s",&s[i].name);
printf("\n\tEnter the marks==>");
scanf("%d",&s[i].marks);
}
n++;
}
sort(); //function call
}
/*-----------<<
function defination for delete record >>------------*/
void
del()
{
int m;
printf("\nEnter any roll_no whose
details you want to delete ==>");
scanf("%d",&m);
printf("\n\nStudent details
are==>\n");
printf("\n\t\tRoll_No\tName\tMarks\n");
for(i=0;i<n;i++)
{
if(s[i].roll_no==m)
{
s[i-1]=s[i];
i++;
}
n--;
printf("\n\t\t%d\t%s\t%d\n",s[i].roll_no,s[i].name,s[i].marks);
}
}
/*---------<<
function defination for modify record >>------------*/
void
modify()
{
int m;
printf("\nEnter any roll_no whose
details you want to modify==>");
scanf("%d",&m);
for(i=0;i<n;i++)
{
if(s[i].roll_no==m)
{
printf("\n\tEnter the
roll_no==>");
scanf("%d",&s[i].roll_no);
printf("\n\tEnter the name of
student==>");
scanf("%s",&s[i].name);
printf("\n\tEnter the
marks==>");
scanf("%d",&s[i].marks);
printf("\nAfter modify student
details are==>\n");
}
}
}
/*---------<<
function defination for display record >>-----------*/
void
display()
{
printf("\n\nStudent details
are==>\n");
printf("\n\t\tRoll_No\tName\tMarks\n");
for(i=0;i<n;i++)
{
printf("\n\t\t%d\t%s\t%d\n",s[i].roll_no,s[i].name,s[i].marks);
}
}
/*---------<<
function defination for search record >>-----------*/
void
search()
{
int m;
printf("\nEnter any roll_no to search==>");
scanf("%d",&m);
for(i=0;i<n;i++)
{
if(s[i].roll_no==m)
{
printf("\n\tRoll_no=%d is present at
location=%d",m,i+1);
printf("\n\n\tSearched student
details are==>\n");
printf("\n\t\tRoll_No\tName\tMarks\n");
printf("\n\t\t%d\t%s\t%d\n",s[i].roll_no,s[i].name,s[i].marks);
}
}
}
/*-----------<<
function defination for sort record >>--------------*/
void
sort()
{
/* using bubble sort technique */
for(i=1;i<n;i++)
{
for(j=0;j<n-1;j++)
{
if(s[j].roll_no>s[i].roll_no)
{
temp=s[i];
s[i]=s[j];
s[j]=temp;
}
}
}
}
/*--------------<< Main Function Start >>------------------*/
void
main()
{
char ans;
//Variable declaration
do
{
clrscr();
//Clear the text mode of window
printf("\n\t\t\t----<< MENU
>>----");
printf("\n\n\t\t\t1.Add");
printf("\n\t\t\t2.Delete");
printf("\n\t\t\t3.Modify");
printf("\n\t\t\t4.Display");
printf("\n\t\t\t5.Search");
printf("\n\t\t\t6.Sort");
printf("\n\t\t\t7.Exit");
printf("\n\n\t\t\t------------------");
printf("\n\n\t\t\tEnter your
choice==>");
scanf("%d",&ch); //accept
choice from user
switch(ch)
{
case 1:
accept(); //function call
add();
display();
break;
case 2:
accept();
del();
break;
case 3:
accept();
modify();
display();
break;
case 4:
accept();
display();
break;
case 5:
accept();
search();
break;
case 6:
accept();
sort();
display();
break;
case 7:
exit(0);
break;
default:
printf("\n\tinvalid choice");
break;
}
printf("\n\n\t\tDo you want to
continue(Y/N)?==>");
ans=getch();
}while(ans=='Y'||ans=='y');
getch();
}
/*-----------<< End Of Main Function >>---------------*/
/*-----------------<< OUTPUT
SCREEN >>-------------------*/
----<< MENU
>>----
1.Add
2.Delete
3.Modify
4.Display
5.Search
6.Sort
7.Exit
------------------
Enter your
choice==>1
Enter
the total no. of student==>2
Enter
the details of student 1==>
Enter the roll_no==>14
Enter the name of student==>jabir
Enter the marks==>78
Enter
the details of student 2==>
Enter the roll_no==>13
Enter the name of student==>ritesh
Enter the marks==>72
Enter
how many member you want to add in data==>1
Enter the roll_no==>11
Enter the name of student==>amir
Enter the marks==>75
Student
details are==>
Roll_No Name Marks
11 amir 75
13 ritesh
72
14 jabir
78
Do you want to
continue(Y/N)?==>Y
----<< MENU
>>----
1.Add
2.Delete
3.Modify
4.Display
5.Search
6.Sort
7.Exit
------------------
Enter your
choice==>2
Enter
the total no. of student==>3
Enter
the details of student 1==>
Enter the roll_no==>14
Enter the name of student==>jabir
Enter the marks==>78
Enter
the details of student 2==>
Enter the roll_no==>11
Enter the name of student==>amir
Enter the marks==>75
Enter
the details of student 3==>
Enter the roll_no==>13
Enter the name of student==>ritesh
Enter the marks==>72
Enter
any roll_no whose details you want to delete ==>13
Student
details are==>
Roll_No Name Marks
14 jabir
78
11 amir
75
Do you want to
continue(Y/N)?==>Y
----<< MENU
>>----
1.Add
2.Delete
3.Modify
4.Display
5.Search
6.Sort
7.Exit
------------------
Enter your
choice==>3
Enter
the total no. of student==>2
Enter
the details of student 1==>
Enter the roll_no==>11
Enter the name of student==>amir
Enter the marks==>75
Enter
the details of student 2==>
Enter the roll_no==>16
Enter the name of student==>ritesh
Enter the marks==>70
Enter
any roll_no whose details you want to modify==>16
Enter the roll_no==>14
Enter the name of student==>jabir
Enter the marks==>78
After
modify student details are==>
Student
details are==>
Roll_No Name Marks
11 amir 75
14 jabir
78
Do you want to
continue(Y/N)?==>Y
----<< MENU
>>----
1.Add
2.Delete
3.Modify
4.Display
5.Search
6.Sort
7.Exit
------------------
Enter your
choice==>4
Enter
the total no. of student==>2
Enter
the details of student 1==>
Enter the roll_no==>13
Enter the name of student==>ritesh
Enter the marks==>72
Enter
the details of student 2==>
Enter the roll_no==>14
Enter the name of student==>jabir
Enter the marks==>78
Student
details are==>
Roll_No Name Marks
13 ritesh
72
14 jabir
78
Do you want to
continue(Y/N)?==>Y
----<< MENU
>>----
1.Add
2.Delete
3.Modify
4.Display
5.Search
6.Sort
7.Exit
------------------
Enter your
choice==>5
Enter
the total no. of student==>2
Enter
the details of student 1==>
Enter the roll_no==>11
Enter the name of student==> amir
Enter the marks==>75
Enter
the details of student 2==>
Enter the roll_no==>14
Enter the name of student==>jabir
Enter the marks==>78
Enter
any roll_no to search==>14
Roll_no=14 is present at location=2
Searched student details are==>
Roll_No Name Marks
14 jabir
78
Do you want to
continue(Y/N)?==>Y
----<< MENU
>>----
1.Add
2.Delete
3.Modify
4.Display
5.Search
6.Sort
7.Exit
------------------
Enter your
choice==>6
Enter
the total no. of student==>3
Enter
the details of student 1==>
Enter the roll_no==>14
Enter the name of student==>jabir
Enter the marks==>78
Enter
the details of student 2==>
Enter the roll_no==>11
Enter the name of student==> amir
Enter the marks==>75
Enter
the details of student 3==>
Enter the roll_no==>13
Enter the name of student==>ritesh
Enter the marks==>72
Student
details are==>
Roll_No Name Marks
11 amir 75
13 ritesh
72
14 jabir
78
Do you want to
continue(Y/N)?==>Y
----<< MENU
>>----
1.Add
2.Delete
3.Modify
4.Display
5.Search
6.Sort
7.Exit
------------------
Enter your
choice==>7
No comments:
Post a Comment