SHARE
TWEET

Untitled

a guest Apr 22nd, 2019 70 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <ctype.h>
  4. #include <string.h>
  5. typedef struct {
  6.     float firstYear;
  7.     float secondYear;
  8.     float thirdYear;
  9.     float fourthYear;
  10.     float fifthYear;
  11. }income;
  12. typedef struct {
  13.     char taxRegistryNumber[13];
  14.     char name[40];
  15.     income incomePerYear;
  16.     char dateRegistry[50];
  17.  
  18.  
  19. }firm;
  20.  
  21. typedef struct node{
  22.     firm frm;
  23.     struct node *next;
  24. }node;
  25. firm addFirm(void);
  26. node * makeList(node * head, FILE *f);
  27.  
  28. int main()
  29. {
  30.  
  31.  
  32.     int n;
  33.     int keyValidation;
  34.  
  35.  
  36.     menu(keyValidation);
  37.  
  38.  
  39.     return 0;
  40. }
  41. void menu(int keyValidation) {
  42.     FILE *fp;
  43.  
  44.     firm fr;
  45.     node *head = NULL;
  46.     fp = fopen("C:\\Users\\Димитър\\Desktop\\firma.txt","wb");
  47.  
  48.  
  49.     if(fp == NULL) {
  50.         printf("NE moje da bude otvoren faila");
  51.         exit(1);
  52.     }
  53.     do {
  54.         printf("1.Dobavqne na nova firma...\n");
  55.         printf("2.Aktualizirane na informaciq za firmata...\n");
  56.         printf("3.Spravka za vsichki firmi imashti pechalba za poslednite 5 godini v zadaden interval...\n");
  57.         printf("4.Po zadaden danuchen nomer da se razpechatva info za firmata...\n");
  58.         printf("Vavedi key...\n");
  59.         scanf("%d",&keyValidation);
  60.  
  61.      if(keyValidation == 1) {
  62.  
  63.         do{
  64.  
  65.             fr = addFirm();
  66.             fwrite(&fr,sizeof(fr),1,fp);
  67.             printf("Dobavqqne na nova firma? Y/N?\n");
  68.  
  69.         } while(toupper(getch()) == 'Y');
  70.  
  71.         fclose(fp);
  72.         head = makeList(head,fp);
  73.  
  74.     } else if(keyValidation == 2) {
  75.         char name[40];
  76.         printf("Vavedete ime na firma\n");
  77.         fflush(stdin);
  78.         gets(name);
  79.  
  80.         update(name,head);
  81.  
  82.     } else if(keyValidation == 3) {
  83.  
  84.             average(head);
  85.     } else if(keyValidation == 4) {
  86.             info(head);
  87.     }
  88.     printf("Spirane s vurteneto?Y/N\n");
  89.     } while(toupper(getch()) == 'N');
  90.     prt(head);
  91.  
  92. }
  93. void info(node *head) {
  94.     char tax[50];
  95.     printf("Vuvedete danuchen nomer za firmata\n");
  96.     fflush(stdin);
  97.     gets(tax);
  98.  
  99.  
  100.     while(head) {
  101.  
  102.        if(strcmp(head->frm.taxRegistryNumber,tax) == 0) {
  103.             printf("Ime na firmata :%s\n",head->frm.name);
  104.             printf("Dohod za pyrvata godina %.2f\n",head->frm.incomePerYear.firstYear);
  105.             printf("Dohod za vtorata godina %.2f\n",head->frm.incomePerYear.secondYear);
  106.             printf("Dohod za tretata godina %.2f\n",head->frm.incomePerYear.thirdYear);
  107.             printf("Dohod za chetvurtata godina %.2f\n",head->frm.incomePerYear.fourthYear);
  108.             printf("Dohod za petata godina %.2f\n",head->frm.incomePerYear.fifthYear);
  109.             printf("Data na registrirane: %s",head->frm.dateRegistry);
  110.        }
  111.  
  112.  
  113.        head = head->next;
  114.     }
  115. }
  116.  
  117. void average(node *head) {
  118.     int nachalenInterval;
  119.  
  120.         float average = 0.0;
  121.  
  122.  
  123.         while(head) {
  124.             printf("Vavedete interval ot 1-vata do 5-tata godina za tazi firma...\n");
  125.             scanf("%d",&nachalenInterval);
  126.             printf("Firma :%s ima sredna pechalba ",head->frm.name);
  127.  
  128.             if(nachalenInterval == 1) {
  129.             average = (head->frm.incomePerYear.firstYear + head->frm.incomePerYear.secondYear + head->frm.incomePerYear.thirdYear + head->frm.incomePerYear.fourthYear + head->frm.incomePerYear.fifthYear)/5;
  130.         } else if(nachalenInterval == 2) {
  131.             average = (head->frm.incomePerYear.secondYear + head->frm.incomePerYear.thirdYear + head->frm.incomePerYear.fourthYear + head->frm.incomePerYear.fifthYear)/4;
  132.         } else if(nachalenInterval == 3) {
  133.             average = (head->frm.incomePerYear.thirdYear + head->frm.incomePerYear.fourthYear + head->frm.incomePerYear.fifthYear)/3;
  134.         } else if(nachalenInterval == 4) {
  135.             average = (head->frm.incomePerYear.fourthYear + head->frm.incomePerYear.fifthYear)/2;
  136.         } else if(nachalenInterval == 5) {
  137.             average = (head->frm.incomePerYear.fifthYear)/1;
  138.         }
  139.  
  140.  
  141.             printf("%.2f leva\n",average);
  142.  
  143.             head = head->next;
  144.             average = 0.0;
  145.         }
  146. }
  147.  
  148.  
  149. firm addFirm() {
  150.  
  151.     firm f;
  152.     printf("Vavedi Tax registry Number\n");
  153.     fflush(stdin);
  154.     gets(f.taxRegistryNumber);
  155.     printf("Vavedi ime na firmata\n");
  156.     fflush(stdin);
  157.     gets(f.name);
  158.     printf("Dohod za purvata godina\n");
  159.     scanf("%f",&(f.incomePerYear.firstYear));
  160.     printf("Dohod za vtorata godina\n");
  161.     scanf("%f",&(f.incomePerYear.secondYear));
  162.     printf("Dohod za tretata godina\n");
  163.     scanf("%f",&(f.incomePerYear.thirdYear));
  164.     printf("Dohod za chetvurtata godina\n");
  165.     scanf("%f",&(f.incomePerYear.fourthYear));
  166.     printf("Dohod za petata godina\n");
  167.     scanf("%f",&(f.incomePerYear.fifthYear));
  168.  
  169.     printf("Data na registraciq v format GGGG//DD//MM\n");
  170.     fflush(stdin);
  171.     gets(f.dateRegistry);
  172.  
  173.  
  174.     return f;
  175. }
  176. update(char *name,node *current) {
  177.  
  178.  
  179.    while(current) {
  180.  
  181.     if(strcmp(current->frm.name,name)==0) {
  182.         printf("Vavedi novite danni...\n");
  183.         printf("Vavedi tax registry number....\n");
  184.         fflush(stdin);
  185.         gets(current->frm.taxRegistryNumber);
  186.  
  187.         printf("Vavedi novi dohodi za purvata godina...\n");
  188.         scanf("%f",&(current->frm.incomePerYear.firstYear));
  189.  
  190.         printf("Vavedi novi dohodi za vtorata godina...\n");
  191.         scanf("%f",&(current->frm.incomePerYear.secondYear));
  192.  
  193.         printf("Vavedi novi dohodi za tretata godina...\n");
  194.         scanf("%f",&(current->frm.incomePerYear.thirdYear));
  195.  
  196.         printf("Vavedi novi dohodi za chetvurtata godina...\n");
  197.         scanf("%f",&(current->frm.incomePerYear.fourthYear));
  198.  
  199.         printf("Vavedi novi dohodi za petata godina...\n");
  200.         scanf("%f",&(current->frm.incomePerYear.fifthYear));
  201.  
  202.         printf("Vavedi nova data na izdavane format GGGG//DD//MM");
  203.         fflush(stdin);
  204.         gets(current->frm.dateRegistry);
  205.  
  206.     }
  207.  
  208.     current = current->next;
  209.    }
  210.  
  211. }
  212. node *makeList(node * head, FILE *f) {
  213.  
  214.     node *p;
  215.     f = fopen("C:\\Users\\Димитър\\Desktop\\firma.txt","rb");
  216.     if(f == NULL) {
  217.         printf("Error");
  218.         exit(1);
  219.     }
  220.  
  221.     do {
  222.        p = (node*)malloc(sizeof(node));
  223.        if(p==NULL) {
  224.         printf("Memory error!");
  225.         exit(1);
  226.        }
  227.         p->next = NULL;
  228.         if(!fread(&(p->frm),sizeof(firm),1,f)) {
  229.             free(p);
  230.             break;
  231.         }
  232.         p->next = head;
  233.         head = p;
  234.     }while(1);
  235.  
  236.     return head;
  237.  
  238. }
  239. void prt(node *current) {
  240.     printf("The list is: \n");
  241.  
  242.     while(current) {
  243.         printf("Tax registry :%s\n",current->frm.taxRegistryNumber);
  244.         printf("Firm name :%s\n",current->frm.name);
  245.         printf("Dohod za purva godina %.2f \n",current->frm.incomePerYear.firstYear);
  246.         printf("Dohod za vtora godina %.2f \n",current->frm.incomePerYear.secondYear);
  247.         printf("Dohod za treta godina %.2f \n",current->frm.incomePerYear.thirdYear);
  248.         printf("Dohod za chetvurta godina %.2f\n",current->frm.incomePerYear.fourthYear);
  249.         printf("Dohod za peta godina %.2f \n",current->frm.incomePerYear.fifthYear);
  250.         printf("Data na registraciq %s\n",current->frm.dateRegistry);
  251.         current = current->next;
  252.  
  253.     }
  254. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top