Advertisement
Guest User

Untitled

a guest
Jan 23rd, 2020
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.15 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. typedef struct Przestepca{
  4.  
  5. char* name;
  6. char* lastname;
  7. int pesel;
  8. int age;
  9. int height;
  10. char* cecha1;
  11. char* cecha2;
  12. char* cecha3;
  13. char* cecha4;
  14. char* cecha5;
  15. int status;
  16. struct Przestepca *next;
  17. }Przestepca;
  18.  
  19. typedef struct Przestepstwa{
  20. int numer;
  21. char* miasto;
  22. char *data;
  23. int pesel;
  24. struct Przestepstwa *next;
  25. } Przestepstwa;
  26.  
  27. void push_backPrzestepca(Przestepca** head, char* new_name, char* new_lastname, int new_pesel, int new_age, int new_height ,char* cecha11,
  28. char* cecha22,char* cecha33, char* cecha44, char* cecha55 , int status1)
  29. {
  30. struct Przestepca* new_Przestepca = (struct Przestepca*) malloc(sizeof(struct Przestepca));
  31. struct Przestepca *last = *head;
  32.  
  33. new_Przestepca->name = new_name;
  34. new_Przestepca->lastname = new_lastname;
  35. new_Przestepca->pesel = new_pesel;
  36. new_Przestepca->age = new_age;
  37. new_Przestepca->height = new_height;
  38. new_Przestepca->cecha1 = cecha11;
  39. new_Przestepca->cecha2 = cecha22;
  40. new_Przestepca->cecha3 = cecha33;
  41. new_Przestepca->cecha4 = cecha44;
  42. new_Przestepca->cecha5 = cecha55;
  43. new_Przestepca->status = status1;
  44.  
  45.  
  46. new_Przestepca->next = NULL;
  47.  
  48. if (*head == NULL)
  49. {
  50. *head = new_Przestepca;
  51. return;
  52. }
  53.  
  54. while (last->next != NULL) //dopoki nie mamy konca
  55. last = last->next;
  56.  
  57. last->next = new_Przestepca;
  58. return;
  59. }
  60. void push_backPrzestepstwa( Przestepstwa **head , int new_numer , char *new_miasto , char *new_data , int new_pesel)
  61. {
  62. struct Przestepstwa *new_przestepstwo = (struct Przestepstwa*)malloc(sizeof(struct Przestepstwa));
  63. struct Przestepstwa *last = *head;
  64.  
  65. new_przestepstwo->numer= new_numer;
  66. new_przestepstwo->miasto= new_miasto;
  67. new_przestepstwo->data= new_data;
  68. new_przestepstwo->pesel = new_pesel;
  69.  
  70. new_przestepstwo->next = NULL;
  71. if(*head == NULL)
  72. {
  73. *head=new_przestepstwo;
  74. }
  75. while (last->next!=NULL)
  76. {
  77. last = last->next;
  78. }
  79. last->next = new_przestepstwo;
  80. last->next->next = NULL;
  81.  
  82. }
  83. void printPrzestepca(Przestepca* node)
  84. {
  85.  
  86. while (node != NULL)
  87. {
  88. printf("%s %s %d %d %d\n", node->name, node->lastname, node->pesel, node->age, node->height);
  89. node = node->next;
  90. }
  91. }
  92.  
  93. int wyszukaj( Przestepca **head , int pesell) // funckja wyszukuje przestepce po peselu
  94. {
  95. struct Przestepca *current = *head;
  96. int i=0;
  97. while( current->pesel != pesell && current->next!=NULL)
  98. {
  99. current= current->next;
  100. i++;
  101. }
  102.  
  103. if(current->next==NULL && current->pesel!=pesell)
  104. {return -1;}
  105.  
  106. return i;
  107. }
  108.  
  109. void usunPrzestepca(Przestepca **head , int pesell)
  110. {
  111. struct Przestepca *current=*head;
  112. struct Przestepca *tmp = NULL;
  113. int n = wyszukaj( head , pesell);
  114.  
  115. for (int i = 0; i < n-1; i++) {
  116. if (current->next == NULL) {
  117. return ;
  118. }
  119. current = current->next;
  120. }
  121.  
  122. tmp = current->next;
  123. current->next = tmp->next;
  124. free(tmp);
  125. }
  126.  
  127. int wyszukaj2( Przestepstwa **head , int number) // funckja wyszukuje przestepce po peselu
  128. {
  129.  
  130.  
  131. struct Przestepstwa *current = *head;
  132. int i=0;
  133. while( current->numer != number && current->next!=NULL)
  134. {
  135. current=current->next;
  136. i++;
  137. printf("hej");
  138. }
  139. if(current->next==NULL && current->numer!=number)
  140. {return -1;}
  141. printf("halo");
  142. return i;
  143.  
  144. }
  145. /*void printPrzestepstwo(Przestepstwa **head , int new_number)
  146. {
  147. Przestepstwa *current=*head;
  148.  
  149. int n = wyszukajnumer( head , new_number);
  150.  
  151. for (int i = 0; i < n-1; i++)
  152. {
  153. current = current->next;
  154. }
  155. printf(" %d %s" , current->numer , current->miasto);
  156.  
  157. }*/
  158. int main()
  159. {
  160. Przestepca* criminal = NULL;
  161. Przestepstwa* criminal2 = NULL;
  162.  
  163. printf("Witamy w criminals!\n\n");
  164. while(1)
  165. {
  166. printf("Kliknij 1, aby dodac przestepce\n");
  167. printf("Kliknij 2, aby dodac przestepstwo\n");
  168. printf("Kliknij 3, aby wyswietlic liste przestepcow\n");
  169. printf("Kliknij 4, aby usunac przestepce\n");
  170. printf("Kliknij 5, aby wyswietlic informacje o przestepcy bioracym udzial w przestepstwie numer : \n");
  171. printf("Kliknij 0, aby zamknac program\n");
  172.  
  173. int choice;
  174. scanf("%d", &choice);
  175.  
  176. switch(choice)
  177. {
  178. case 1:
  179. {
  180. system("cls");
  181. char* name = (char*)malloc(sizeof(char)*20);
  182. char* lastname= (char*)malloc(sizeof(char)*20);
  183. int pesel;
  184. int age;
  185. int height;
  186. char* cecha1 = (char*)malloc(sizeof(char)*20);
  187. char* cecha2 = (char*)malloc(sizeof(char)*20);
  188. char* cecha3 = (char*)malloc(sizeof(char)*20);
  189. char* cecha4 = (char*)malloc(sizeof(char)*20);
  190. char* cecha5 = (char*)malloc(sizeof(char)*20);
  191. int status;
  192.  
  193. printf("Podaj IMIE, NAZWISKO, PESEL, WIEK, WZROST, 5 CECH SZCZEGÓLNYCH (BRAK CECHY OZN. - , STATUS SPRAWY (O - ZLAPANY, 1 NIE) : \n");
  194.  
  195. scanf("%s %s %d %d %d %s %s %s %s %s %d",name, lastname, &pesel, &age, &height, cecha1 ,cecha2 , cecha3, cecha4, cecha5, &status);
  196.  
  197. push_backPrzestepca(&criminal, name, lastname, pesel, age, height, cecha1, cecha2, cecha3, cecha4, cecha5, status);
  198. printf("\n");
  199. break;
  200. }
  201. case 2:
  202. {
  203. system("cls");
  204. int numer;
  205. char *miasto = (char*)malloc(sizeof(char)*20);
  206. char *data = (char*)malloc(sizeof(char)*9);
  207. int pesel;
  208. printf("PODAJ NUMER PRZESTEPSTWA, MIASTO, DATE ORAZ PESEL PRZESTEPCY,KTORYM BRAL W TYM UDZIAL\n");
  209. scanf ( "%d %s %s %d" , &numer , miasto , data , &pesel);
  210. printf("\n");
  211. break;
  212.  
  213. }
  214. case 3:
  215. {
  216. system("cls");
  217. printPrzestepca(criminal);
  218. printf("\n\n");
  219.  
  220. break;
  221. }
  222. case 4:
  223. {
  224. printf("Podaj ID/PESEL przestepcy ktorego chcesz usunac:\n");
  225. int pesel2;
  226. scanf("%d" , &pesel2);
  227. usunPrzestepca(&criminal , pesel2);
  228. break;
  229. }
  230. case 5:
  231. { system("cls");
  232. printf("Podaj numer przestepstwa, aby uzyskac informacje o przestepcy bioracym w nim udzial\n");
  233. int numer;
  234. scanf("%d" , &numer);
  235. wyszukaj2( &criminal2 , numer);
  236. break;
  237.  
  238. }
  239.  
  240. }
  241. if(choice == 0)
  242. break;
  243. }
  244. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement