struct
struct
Program:
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
struct student{
printf("DATABASE OF STUDENT\n");
printf("Roll no\t Name\t\t\t\tDE\tSS\tDSA\tECA\tAvg\n");
}
void struct_input(struct student s[], int intial ,int final){
printf("Marks:\n");
printf("DE , SS , DSA , ECA: ");
scanf("%d%d%d%d",&s[i].DE,&s[i].SS,&s[i].DSA,&s[i].ECA);
s[i].avg=avg(s, i);
printf("\n");
}
void sort(struct student s[],int n){
for(int i=0;i<n-1;i++){
short int didSwap= 0;
for(int j=0;j<n-i-1;j++){
if(s[j].roll_no>s[j+1].roll_no){
int temp;
temp=s[j+1].roll_no;
s[j+1].roll_no=s[j].roll_no;
s[j].roll_no=temp;
didSwap=1;
}
if(didSwap== 0) break;
}
}
int searching(struct student s[],int n ,char search[]){
int a ;
for(int i=0;i<n;i++){
a=strcmp(search , s[i].name);
if(a==0) {
return i; //store index of the element
}
}
return -1;
}
int search_rno(struct student s[],int n,int rno){
}
void modify(struct student s[] ,int mod ,int n){
int rno ,updated_no ,index ,sub ,mks;
switch(mod){
case 1://roll no
printf("Enter the roll no to be modified: " );
scanf("%d",&rno);
index=search_rno(s , n ,rno);
if(index==-1) printf("Data not found\n");
else s[index].roll_no=updated_no;
break;
case 2://name
printf("Enter the roll no : ");
scanf("%d",&rno);
index=search_rno(s,n ,rno);
if(index==-1) printf("Data not present\n");
else{
case 4://ECA
printf("Enter the updated DE marks: ");
scanf("%d",&mks);
s[index].ECA=mks;
printf("Marks updated\n");
break;
}
}
}
int main(){
int n , mod;
int ch;
do{
printf("\n***************MENU******************\n");
printf("1 Search\n2 Append\n3 Modify\n4 Sort\n5 Display\n6 exit\n");
switch (ch){
case 1:// Search
printf("Enter the name to search: ");
char search[20];
scanf("%s", search);
int index= searching( s, n , search);
case 2://Append
printf("Number of entries to add: ");
scanf("%d",&m);
struct_input(s, n ,n+m);
n+=m;
break;
if(mod==4) break;
modify(s ,mod , n);
return 0;
Output:
PS D:\Anushka\college> cd "d:\Anushka\college\DSA\" ; if ($?) { gcc structure.c -o structure } ; if ($?) { .\structure }
Enter the no of students: 3
Student 1
roll number: 1
name of student: anu
Marks:
DE , SS , DSA , ECA: 54 77 68 33
Student 2
roll number: 2
name of student: sara
Marks:
DE , SS , DSA , ECA: 77 64 58 33
Student 3
roll number: 8
name of student: apurv
Marks:
DE , SS , DSA , ECA: 87 14 96 33
***************MENU******************
1 Search
2 Append
3 Modify
4 Sort
5 Display
6 exit
Enter the choice: 1
Enter the name to search: apurv
Found at index 2
***************MENU******************
1 Search
2 Append
3 Modify
4 Sort
5 Display
6 exit
Enter the choice: 1
Enter the name to search: kaka
Not found
***************MENU******************
1 Search
2 Append
3 Modify
4 Sort
5 Display
6 exit
Enter the choice: 2
Number of entries to add: 1
Student 4
roll number: 4
name of student: akash
Marks:
DE , SS , DSA , ECA: 78 99 44 99
***************MENU******************
1 Search
2 Append
3 Modify
4 Sort
5 Display
6 exit
Enter the choice: 3
Enter the fields to change:
1.Roll no
2.Name
3.Marks
4.Dont modify
Enter the choice: 1
***************MENU******************
1 Search
2 Append
3 Modify
4 Sort
5 Display
6 exit
Enter the choice: 4
***************MENU******************
1 Search
2 Append
3 Modify
4 Sort
5 Display
6 exit
Enter the choice: 5
DATABASE OF STUDENT
Roll no Name DE SS DSA ECA Avg
1 arav 98 77 68 33 85.00
5 sara 77 64 58 33 79.00
8 apurv 87 14 96 33 98.00
***************MENU******************
1 Search
1 Search
2 Append
3 Modify
4 Sort
5 Display
6 exit
Enter the choice: 6
PS D:\Anushka\college\DSA>