Alx09

Untitled

Mar 22nd, 2021
789
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.27 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. typedef struct list {
  4.     char cod[20];
  5.     float pret;
  6.     enum{telefon, unitate, tableta}tip;
  7.     struct list *urm;
  8. }depozit;
  9.  
  10.  
  11. int main()
  12. {
  13.     depozit *head = NULL, *p = NULL;
  14.    
  15.     int opt, ok, i;
  16.    
  17.     do {
  18.         printf("1. Introducere echipament nou\n");
  19.         printf("2. Afisare lista\n");
  20.         printf("3. Schimbare paritate bit\n");
  21.         printf("4. Iesire\n");
  22.         printf("4. Optiunea aleasa: ");
  23.         scanf("%d", &opt);
  24.         switch (opt) {
  25.         case 1:
  26.             p = head;
  27.             head = (depozit *)malloc(sizeof(depozit));
  28.             head->urm = NULL;
  29.             do{
  30.                 ok = 0;
  31.                 printf("Cod: "); scanf("%s", head-> cod);
  32.                 if (head->cod[0] >= '0' && head->cod[0] <= '9' && head->cod[1] >= 'a' && head->cod[1] <= 'z' && head->cod[2] == '-') {
  33.                     for (i = 3; head->cod[i]; i++)
  34.                     if (head->cod[i] < '0' || head->cod[i] > '9') break;
  35.                     if (head->cod[i] == 0)
  36.                         ok = 1;
  37.                 }
  38.             } while (ok == 0);
  39.             printf("Pret: "); scanf("%f", &head->pret);
  40.             printf("Tip: "); scanf("%d", &head->tip);
  41.             head->urm = p;
  42.             break;
  43.         case 2:
  44.             p = head;
  45.             while (p) {
  46.                 printf("Cod produs %s \n", p->cod);
  47.                 printf("Pret de vanzare %f \n", p->pret * 1.15);
  48.                 printf("Tip %d \n", p->tip);
  49.                 p = p->urm;
  50.             }
  51.             break;
  52.         case 4: return 0;
  53.         }
  54.     } while (1);
  55. }
  56.  
Advertisement
Add Comment
Please, Sign In to add comment