Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- #include<conio.h>
- #include<stdlib.h>
- int count=0;
- void insert_data();
- void view_data();
- void search_data();
- void search_data1();
- struct train
- {
- int tno;
- char tname[20];
- char ttype[20];
- int price;
- }t[4];
- void main()
- {
- int ch;
- clrscr();
- do
- {
- printf("\n 1. Insert data");
- printf("\n 2. View data");
- printf("\n 3. Search data price wise");
- printf("\n 4. Search data train type");
- printf("\n 5. Exit");
- printf("\n Enter your choice----");
- scanf("%d",&ch);
- switch(ch)
- {
- case 1:
- insert_data();
- break;
- case 2:
- view_data();
- break;
- case 3:
- search_data(); //price wise
- break;
- case 4:
- search_data1(); //trian type
- }
- }while(ch>=1 && ch<=4);
- getch();
- }
- void insert_data()
- {
- if(count==5)
- {
- printf("\n sorry no more record");
- }
- else
- {
- printf("\n Enter train no");
- scanf("%d",&t[count].tno);
- printf("\n Enter train name");
- flushall();
- gets(t[count].tname);
- printf("\n Enter train type");
- flushall();
- gets(t[count].ttype);
- printf("\n Enter the price");
- scanf("%d",&t[count].price);
- count++;
- }
- }
- void view_data()
- {
- int i=0;
- if(count==0)
- {
- printf("\n No more record");
- }
- else
- {
- printf("\n====train info====");
- for(i=0;i<count;i++)
- {
- printf("\n %d \t %s \t %s \t %d",t[i].tno, t[i].tname, t[i].ttype, t[i].price);
- }
- }
- }
- void search_data()
- {
- int temp,i;
- if(count==0)
- {
- printf("\n no more record");
- }
- else
- {
- printf("\n Enter price you want to search");
- scanf("%d", &temp);
- for(i=0;i<count;i++)
- {
- if(t[i].price>=temp)
- {
- printf("\n %d \t %s \t %s \t %d",t[i].tno, t[i].tname,t[i].ttype, t[i].price);
- }
- }
- }
- }
- void search_data1()
- {
- int temp,i;
- char type[20];
- if(count==0)
- {
- printf("\n no more record");
- }
- else
- {
- printf("\n Enter type you want to search");
- flushall();
- gets(type);
- for(i=0;i<count;i++)
- {
- if(strcmp(t[i].ttype,type)==0)
- {
- printf("\n %d \t %s \t %s \t %d",t[i].tno, t[i].tname,t[i].ttype, t[i].price);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment