netx_iit

Struct Program 2

May 12th, 2021
256
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.90 KB | None | 0 0
  1. #include<stdio.h>
  2. #include<conio.h>
  3. #include<stdlib.h>
  4. int count=0;
  5. void insert_prod();//declaration
  6. void view_prod();
  7. void search_prod1();
  8. struct prod
  9. {
  10.     int pid;
  11.     char pname[20];
  12.     int qty;
  13.     int price;
  14.     int total;
  15. }p[5];
  16. void main()
  17. {
  18.     //struct prod p[5];//array of structure
  19.     int ch;
  20.     clrscr();
  21.     do
  22.     {
  23.         printf("\n 1. Insert product information");
  24.         printf("\n 2. View product information");
  25.         printf("\n 3. Search product price");
  26.         printf("\n 4. Search product name");
  27.         printf("\n 5. Exit");
  28.         printf("\n Enter your choice");
  29.         scanf("%d",&ch);
  30.  
  31.         switch(ch)
  32.         {
  33.             case 1:
  34.                 insert_prod();//user deinfe function calling
  35.                 break;
  36.  
  37.             case 2:
  38.                 view_prod();
  39.                 break;
  40.  
  41.             case 3:
  42.                 search_prod1();
  43.                 break;
  44.  
  45.         }
  46.     }while(ch>=1 && ch<=4);
  47.     getch();
  48. }
  49. void insert_prod()              //definatino
  50. {
  51.     if(count==5)
  52.     {
  53.         printf("\n Sorry no more record is inserted...");
  54.     }
  55.     else
  56.     {
  57.         printf("\n Enter product Id=");
  58.         scanf("%d",&p[count].pid);
  59.         printf("\n Enter proudct Name=");
  60.         flushall();
  61.         gets(p[count].pname);
  62.         printf("\n Enter proudct price=");
  63.         scanf("%d",&p[count].price);
  64.         printf("\n Enter product qty=");
  65.         scanf("%d",&p[count].qty);
  66.         p[count].total=p[count].price*p[count].qty;
  67.         count++;
  68.     }
  69. }
  70.  
  71. void view_prod()
  72. {
  73.     int i=0;
  74.     if(count==0)
  75.     {
  76.         printf("\n No record found...");
  77.     }
  78.     else
  79.     {
  80.         printf("\n ======= Product Information  ====== ");
  81.         for(i=0;i<count;i++)
  82.         {
  83.             printf("\n%d \t %s \t %d \t %d \t %d",p[i].pid,p[i].pname,p[i].price,p[i].qty,p[i].total);
  84.         }
  85.     }
  86. }
  87.  
  88. void search_prod1()
  89. {
  90.     int temp,i;
  91.     if(count==0)
  92.     {
  93.         printf("\n No record found...");
  94.     }
  95.     else
  96.     {
  97.         printf("\n Enter price you want to search");
  98.         scanf("%d",&temp);
  99.         for(i=0;i<count;i++)
  100.         {
  101.             if(p[i].price >= temp)
  102.             {
  103.                 printf("\n%d \t %s \t %d \t %d \t %d",p[i].pid,p[i].pname,p[i].price,p[i].qty,p[i].total);
  104.             }
  105.         }
  106.     }
  107. }
  108.  
  109.  
Advertisement
Add Comment
Please, Sign In to add comment