Case study Structure:
Create a structure ‘library’ with different members as given below.
Member_id, Member_name, Member_type (type can be a teacher or student) and Member_joining_date. Write a small program using following interface.
1. Input member records
2. View the member records
3. Search a member using joining date.
4. Exit
Use switch… case structure. You may use function.
//case study of structure//
#include<stdio.h>
int total,choice;
struct student
{
char name[100];
int id;
int date;
}s[100];
void input(struct student s[100]);
void records(struct student s[100]);
void search(struct student s[100]);
void menu(struct student s[100]);
int main()
{
menu(s);
return 0;
}
void input(struct student s[100])
{
printf("Enter total numbers of students\n");
scanf("%d",&total);
for(int i=0; i<total; i++){
printf("Enter your ID\n");
scanf("%d",&s[i].id);
printf("Enter your name\n");
scanf("%s",s[i].name);
printf("Enter your joining date\n");
scanf("%d",&s[i].date);
}
}
void menu(struct student s[100])
{
printf("We have following menu\n");
printf("1.To view your record\n");
printf("2.To search your record\n");
printf("3.Exit\n");
printf("Enter your choice\n");
scanf("%d",&choice);
switch(choice)
{
case 1:
records(s);
break;
case 2:
search(s);
break;
case 3:
printf("........Exit.......\n");
break;
default:
printf("Please enter from 1 to 3\n");
break;
}
}
void records(struct student s[100])
{
for(int i=0; i<total; i++)
{
printf("Your name is %s\n",s[i].name);
printf("Your ID is %d\n",s[i].id);
printf("Your joining date is %d\n",s[i].date);
}
menu(s);
}
void search(struct student s[100])
{
int search,found=0,i;
printf("enter your joining date to search your data\n");
scanf("%d",&search);
for(i=0; i<total; i++)
{
if(s[i].date==search)
{
found=1;
break;
}
}
if(found==1)
{
printf("Member data found in %d\n",i);
printf("Your name is %s\n",s[i].name);
printf("Your ID is %d\n",s[i].id);
printf("Your joining date is %d\n",s[i].date);
}
else
{
printf("%d id is not in the list.....\n");
}
menu(s);
}
No comments:
Post a Comment