netx_iit

Struct Program 3

May 19th, 2021
230
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.09 KB | None | 0 0
  1. #include<stdio.h>
  2. #include<conio.h>
  3. #include<stdlib.h>
  4. int count=0;
  5. void insert_data();
  6. void view_data();
  7. void search_data();
  8. void search_data1();
  9.  
  10. struct train
  11. {
  12.     int tno;
  13.     char tname[20];
  14.     char ttype[20];
  15.     int price;
  16. }t[4];
  17.  
  18. void main()
  19. {
  20.     int ch;
  21.     clrscr();
  22.     do
  23.     {
  24.         printf("\n 1. Insert data");
  25.         printf("\n 2. View data");
  26.         printf("\n 3. Search data price wise");
  27.         printf("\n 4. Search data train type");
  28.         printf("\n 5. Exit");
  29.         printf("\n Enter your choice----");
  30.         scanf("%d",&ch);
  31.  
  32.         switch(ch)
  33.         {
  34.             case 1:
  35.             insert_data();
  36.             break;
  37.  
  38.             case 2:
  39.             view_data();
  40.             break;
  41.  
  42.             case 3:
  43.             search_data(); //price wise
  44.             break;
  45.  
  46.             case 4:
  47.             search_data1(); //trian type
  48.  
  49.         }
  50.     }while(ch>=1 && ch<=4);
  51.     getch();
  52. }
  53. void insert_data()
  54. {
  55.     if(count==5)
  56.     {
  57.         printf("\n sorry no more record");
  58.     }
  59.     else
  60.     {
  61.         printf("\n Enter train no");
  62.         scanf("%d",&t[count].tno);
  63.         printf("\n Enter train name");
  64.         flushall();
  65.         gets(t[count].tname);
  66.         printf("\n Enter train type");
  67.         flushall();
  68.         gets(t[count].ttype);
  69.         printf("\n Enter the price");
  70.         scanf("%d",&t[count].price);
  71.         count++;
  72.     }
  73. }
  74. void view_data()
  75. {
  76.     int i=0;
  77.     if(count==0)
  78.     {
  79.         printf("\n No more record");
  80.     }
  81.     else
  82.     {
  83.         printf("\n====train info====");
  84.         for(i=0;i<count;i++)
  85.         {
  86.             printf("\n %d \t %s \t %s \t %d",t[i].tno, t[i].tname, t[i].ttype, t[i].price);
  87.         }
  88.     }
  89. }
  90. void search_data()
  91. {
  92.     int temp,i;
  93.     if(count==0)
  94.     {
  95.         printf("\n no more record");
  96.     }
  97.     else
  98.     {
  99.         printf("\n Enter price you want to search");
  100.         scanf("%d", &temp);
  101.         for(i=0;i<count;i++)
  102.         {
  103.             if(t[i].price>=temp)
  104.             {
  105.                 printf("\n %d \t %s \t %s \t %d",t[i].tno, t[i].tname,t[i].ttype, t[i].price);
  106.             }
  107.         }
  108.  
  109.     }
  110.  
  111. }
  112. void search_data1()
  113. {
  114.     int temp,i;
  115.     char type[20];
  116.     if(count==0)
  117.     {
  118.         printf("\n no more record");
  119.     }
  120.     else
  121.     {
  122.         printf("\n Enter type you want to search");
  123.         flushall();
  124.         gets(type);
  125.         for(i=0;i<count;i++)
  126.         {
  127.             if(strcmp(t[i].ttype,type)==0)
  128.             {
  129.                 printf("\n %d \t %s \t %s \t %d",t[i].tno, t[i].tname,t[i].ttype, t[i].price);
  130.             }
  131.         }
  132.     }
  133.  
  134. }
Advertisement
Add Comment
Please, Sign In to add comment