Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- typedef struct Przestepca{
- char* name;
- char* lastname;
- int pesel;
- int age;
- int height;
- char* cecha1;
- char* cecha2;
- char* cecha3;
- char* cecha4;
- char* cecha5;
- int status;
- struct Przestepca *next;
- }Przestepca;
- typedef struct Przestepstwa{
- int numer;
- char* miasto;
- char *data;
- int pesel;
- struct Przestepstwa *next;
- } Przestepstwa;
- void push_backPrzestepca(Przestepca** head, char* new_name, char* new_lastname, int new_pesel, int new_age, int new_height ,char* cecha11,
- char* cecha22,char* cecha33, char* cecha44, char* cecha55 , int status1)
- {
- struct Przestepca* new_Przestepca = (struct Przestepca*) malloc(sizeof(struct Przestepca));
- struct Przestepca *last = *head;
- new_Przestepca->name = new_name;
- new_Przestepca->lastname = new_lastname;
- new_Przestepca->pesel = new_pesel;
- new_Przestepca->age = new_age;
- new_Przestepca->height = new_height;
- new_Przestepca->cecha1 = cecha11;
- new_Przestepca->cecha2 = cecha22;
- new_Przestepca->cecha3 = cecha33;
- new_Przestepca->cecha4 = cecha44;
- new_Przestepca->cecha5 = cecha55;
- new_Przestepca->status = status1;
- new_Przestepca->next = NULL;
- if (*head == NULL)
- {
- *head = new_Przestepca;
- return;
- }
- while (last->next != NULL) //dopoki nie mamy konca
- last = last->next;
- last->next = new_Przestepca;
- return;
- }
- void push_backPrzestepstwa( Przestepstwa **head , int new_numer , char *new_miasto , char *new_data , int new_pesel)
- {
- struct Przestepstwa *new_przestepstwo = (struct Przestepstwa*)malloc(sizeof(struct Przestepstwa));
- struct Przestepstwa *last = *head;
- new_przestepstwo->numer= new_numer;
- new_przestepstwo->miasto= new_miasto;
- new_przestepstwo->data= new_data;
- new_przestepstwo->pesel = new_pesel;
- new_przestepstwo->next = NULL;
- if(*head == NULL)
- {
- *head=new_przestepstwo;
- }
- while (last->next!=NULL)
- {
- last = last->next;
- }
- last->next = new_przestepstwo;
- last->next->next = NULL;
- }
- void printPrzestepca(Przestepca* node)
- {
- while (node != NULL)
- {
- printf("%s %s %d %d %d\n", node->name, node->lastname, node->pesel, node->age, node->height);
- node = node->next;
- }
- }
- int wyszukaj( Przestepca **head , int pesell) // funckja wyszukuje przestepce po peselu
- {
- struct Przestepca *current = *head;
- int i=0;
- while( current->pesel != pesell && current->next!=NULL)
- {
- current= current->next;
- i++;
- }
- if(current->next==NULL && current->pesel!=pesell)
- {return -1;}
- return i;
- }
- void usunPrzestepca(Przestepca **head , int pesell)
- {
- struct Przestepca *current=*head;
- struct Przestepca *tmp = NULL;
- int n = wyszukaj( head , pesell);
- for (int i = 0; i < n-1; i++) {
- if (current->next == NULL) {
- return ;
- }
- current = current->next;
- }
- tmp = current->next;
- current->next = tmp->next;
- free(tmp);
- }
- int wyszukaj2( Przestepstwa **head , int number) // funckja wyszukuje przestepce po peselu
- {
- struct Przestepstwa *current = *head;
- int i=0;
- while( current->numer != number && current->next!=NULL)
- {
- current=current->next;
- i++;
- printf("hej");
- }
- if(current->next==NULL && current->numer!=number)
- {return -1;}
- printf("halo");
- return i;
- }
- /*void printPrzestepstwo(Przestepstwa **head , int new_number)
- {
- Przestepstwa *current=*head;
- int n = wyszukajnumer( head , new_number);
- for (int i = 0; i < n-1; i++)
- {
- current = current->next;
- }
- printf(" %d %s" , current->numer , current->miasto);
- }*/
- int main()
- {
- Przestepca* criminal = NULL;
- Przestepstwa* criminal2 = NULL;
- printf("Witamy w criminals!\n\n");
- while(1)
- {
- printf("Kliknij 1, aby dodac przestepce\n");
- printf("Kliknij 2, aby dodac przestepstwo\n");
- printf("Kliknij 3, aby wyswietlic liste przestepcow\n");
- printf("Kliknij 4, aby usunac przestepce\n");
- printf("Kliknij 5, aby wyswietlic informacje o przestepcy bioracym udzial w przestepstwie numer : \n");
- printf("Kliknij 0, aby zamknac program\n");
- int choice;
- scanf("%d", &choice);
- switch(choice)
- {
- case 1:
- {
- system("cls");
- char* name = (char*)malloc(sizeof(char)*20);
- char* lastname= (char*)malloc(sizeof(char)*20);
- int pesel;
- int age;
- int height;
- char* cecha1 = (char*)malloc(sizeof(char)*20);
- char* cecha2 = (char*)malloc(sizeof(char)*20);
- char* cecha3 = (char*)malloc(sizeof(char)*20);
- char* cecha4 = (char*)malloc(sizeof(char)*20);
- char* cecha5 = (char*)malloc(sizeof(char)*20);
- int status;
- printf("Podaj IMIE, NAZWISKO, PESEL, WIEK, WZROST, 5 CECH SZCZEGÓLNYCH (BRAK CECHY OZN. - , STATUS SPRAWY (O - ZLAPANY, 1 NIE) : \n");
- scanf("%s %s %d %d %d %s %s %s %s %s %d",name, lastname, &pesel, &age, &height, cecha1 ,cecha2 , cecha3, cecha4, cecha5, &status);
- push_backPrzestepca(&criminal, name, lastname, pesel, age, height, cecha1, cecha2, cecha3, cecha4, cecha5, status);
- printf("\n");
- break;
- }
- case 2:
- {
- system("cls");
- int numer;
- char *miasto = (char*)malloc(sizeof(char)*20);
- char *data = (char*)malloc(sizeof(char)*9);
- int pesel;
- printf("PODAJ NUMER PRZESTEPSTWA, MIASTO, DATE ORAZ PESEL PRZESTEPCY,KTORYM BRAL W TYM UDZIAL\n");
- scanf ( "%d %s %s %d" , &numer , miasto , data , &pesel);
- printf("\n");
- break;
- }
- case 3:
- {
- system("cls");
- printPrzestepca(criminal);
- printf("\n\n");
- break;
- }
- case 4:
- {
- printf("Podaj ID/PESEL przestepcy ktorego chcesz usunac:\n");
- int pesel2;
- scanf("%d" , &pesel2);
- usunPrzestepca(&criminal , pesel2);
- break;
- }
- case 5:
- { system("cls");
- printf("Podaj numer przestepstwa, aby uzyskac informacje o przestepcy bioracym w nim udzial\n");
- int numer;
- scanf("%d" , &numer);
- wyszukaj2( &criminal2 , numer);
- break;
- }
- }
- if(choice == 0)
- break;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement