Advertisement
Immons

FoCP lab 23.11

Nov 28th, 2012
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 3.99 KB | None | 0 0
  1. #include <stdlib.h>
  2. #include <io.h>
  3. #include <iostream>
  4. #include <time.h>
  5. #include <string.h>
  6.  
  7. struct student
  8. {
  9.     char name[40];
  10.     unsigned int age;
  11.     char id[11];
  12.     unsigned int group;
  13. };
  14.  
  15. struct student* arr [10] = { 0 };
  16.  
  17. void Print(int i)
  18. {
  19.     printf("Imie studenta: %s\n", arr[i]->name);
  20.     printf("Wiek studenta: %d\n", arr[i]->age);
  21.     printf("Pesel studenta: %s\n", arr[i]->id);
  22.     printf("Grupa studenta: %d\n", arr[i]->group);
  23. }
  24.  
  25. void Save()
  26. {
  27.     int i = 0;
  28.  
  29.     for (i; i < 10; i++)
  30.     {
  31.         if (arr[i] == NULL)
  32.         {
  33.             arr[i] = (struct student*)malloc(sizeof(struct student));
  34.             printf("Podaj imie studenta:\n");
  35.             scanf("%s", arr[i]->name);
  36.             printf("Podaj wiek studenta:\n");
  37.             scanf("%d", &arr[i]->age);
  38.             printf("Podaj pesel studenta:\n");
  39.             scanf("%s", arr[i]->id);
  40.             printf("Podaj grupe studenta:\n");
  41.             scanf("%d", &arr[i]->group);
  42.             break;
  43.         }
  44.     }
  45. }
  46.  
  47. void Edit(int n)
  48. {
  49.  
  50.     arr[n] = (struct student*)malloc(sizeof(struct student));
  51.     printf("Podaj imie studenta:\n");
  52.     scanf("%s", arr[n]->name);
  53.     printf("Podaj wiek studenta:\n");
  54.     scanf("%d", &arr[n]->age);
  55.     printf("Podaj pesel studenta:\n");
  56.     scanf("%s", arr[n]->id);
  57.     printf("Podaj grupe studenta:\n");
  58.     scanf("%d", &arr[n]->group);
  59. }
  60.  
  61. int main()
  62. {
  63.     int studentsNumber = 0;
  64.  
  65. Entrance:
  66.     system("cls");
  67.     printf("======Program tworzacy profil studenta=======\n");
  68.     printf("======Wcisnij:===============================\n");
  69.     printf("======1. By dodac studenta===================\n");
  70.     printf("======2. By zmienic studenta dane============\n");
  71.     printf("======3. By wyswietlic dane studenta=========\n");
  72.     printf("======0. By wyjsc============================\n");
  73.  
  74.     int choice = 0;
  75.  
  76.     scanf("%d", &choice);
  77.  
  78.     switch (choice)
  79.     {
  80.     case 1:
  81.         {
  82.             system("cls");
  83.             Save();
  84.             studentsNumber++;
  85.             goto Entrance;
  86.         }
  87.     case 2:
  88.         {
  89.             Edit:
  90.             system("cls");
  91.             printf("Podaj pesel studenta do edycji:\n");
  92.             char studentsID[11];
  93.             scanf("%s", &studentsID);
  94.  
  95.             int chosenStudent = 100;
  96.            
  97.             for (int i = 0; i < 10; i++)
  98.             {
  99.                 for (int j = 0; j < 11; j++)
  100.                 {
  101.                     if (arr[i] != NULL)
  102.                     {
  103.                         if (arr[i]->id[j] != studentsID[j])
  104.                         {
  105.                             break;
  106.                         }
  107.  
  108.                         if (j == 10)
  109.                         {
  110.                             chosenStudent = i;
  111.                         }
  112.                     }
  113.                 }
  114.             }
  115.  
  116.             if (chosenStudent == 100)
  117.             {
  118.                 printf("Nieprawdilowy pesel!\n");
  119.                 goto Entrance;
  120.             }
  121.  
  122.             system("cls");
  123.             Edit(chosenStudent);
  124.  
  125.             goto Entrance;
  126.         }
  127.     case 3:
  128.         {
  129.             Start:
  130.             system("cls");
  131.             printf("Wyswietlic wszystkie dane czy jednego studenta(wszystkie - 1, jednego - 2)?\n");
  132.             int locChoice = 0;
  133.             scanf("%d", &locChoice);
  134.  
  135.             system("cls");
  136.  
  137.             switch(locChoice)
  138.             {
  139.                 case 1:
  140.                     {
  141.                         for (int i = 0; i < studentsNumber; i++)
  142.                         {
  143.                             if (arr[i]->name != "")
  144.                             {
  145.                                 printf("Numer studenta: %d\n", i);
  146.                                 Print(i);
  147.                                 printf("\n");
  148.                             }
  149.                         }
  150.                         break;
  151.                     }
  152.                 case 2:
  153.                     {
  154.                         printf("Podaj pesel studenta:\n");
  155.                         char ID[11];
  156.                         scanf("%s", &ID);
  157.  
  158.                         int printedNumber = 0;
  159.  
  160.                         system("cls");
  161.  
  162.                         for (int i = 0; i < studentsNumber; i++)
  163.                         {
  164.                             if (arr[i]->name != "")
  165.                             {
  166.                                 bool print = true;
  167.  
  168.                                 for (int j = 0; j < 11; j++)
  169.                                 {
  170.                                     int temp = 1;
  171.                                     if (arr[i]->id[j] != ID[j])
  172.                                     {
  173.                                         print = false;
  174.                                         break;
  175.                                     }
  176.                                 }
  177.  
  178.                                 if (print == true)
  179.                                 {
  180.                                     PrintDetails:
  181.                                     printedNumber++;
  182.                                     Print(i);
  183.                                     break;
  184.                                 }
  185.                             }
  186.                         }
  187.  
  188.                         if (printedNumber == 0)
  189.                         {
  190.                             printf("Nie znaleziono szukanego studenta\n");
  191.                         }
  192.                         break;
  193.                     }
  194.                 default:
  195.                     {
  196.                         printf("Bledny wybor, ponow komende");
  197.                         goto Start;
  198.                     }
  199.             }
  200.  
  201.  
  202.             system("PAUSE");
  203.             goto Entrance;
  204.         }
  205.     case 0:
  206.         {
  207.             goto Close;
  208.         }
  209.     }
  210.  
  211.  
  212.     goto Entrance;
  213. Close: {
  214.             for (int i = 0; i < 10; i++)
  215.             {
  216.                 if(arr[i] != NULL)
  217.                 {
  218.                     free(arr[i]);
  219.                 }
  220.             }
  221.        }
  222. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement