Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include <errno.h>
- #define lenght_of_personal_data 15
- struct klient
- {
- unsigned int numer_karty;
- char nazwisko[lenght_of_personal_data];
- char imie[lenght_of_personal_data];
- char telefon[10];
- struct klient *nastepny;
- };
- struct ksiazka
- {
- unsigned int ID;
- char tytul[50];
- unsigned int rok;
- char autor[2*lenght_of_personal_data+1];
- char gatunek[15];
- unsigned char liczba_egzemplarzy;
- unsigned char liczba_wypozyczonych;
- struct ksiazka *nastepny;
- };
- struct wypozyczenie
- {
- unsigned int numer_karty;
- unsigned int ID_ksiazki;
- unsigned char rok_od;
- unsigned char miesiac_od;
- unsigned char dzien_od;
- unsigned char rok_do;
- unsigned char miesiac_do;
- unsigned char dzien_do;
- struct wypozyczenie *nastepny;
- };
- struct klient wczytaj_nowego_klienta()
- {
- struct klient nowy;
- puts("Wypełnij dane klienta: ");
- printf("Numer: \t");
- scanf("%u", &nowy.numer_karty);
- printf("Imie:\t ");
- scanf("%s", &nowy.imie);
- printf("Nazwisko: \t");
- scanf("%s", &nowy.nazwisko);
- do{
- printf("Telefon: ");
- scanf("%s", &nowy.telefon);
- }while(sprawdz_telefon(nowy.telefon)!=0);
- return nowy;
- };
- int sprawdz_telefon(char telefon[])
- {
- int i = 0;
- for(i; i <9; i++)
- {
- if(telefon[i]>='0'&&telefon[i]<='9'){}
- else return -1;
- }
- if(strlen(telefon)!=9) return -2;
- else return 0;
- }
- struct ksiazka wczytaj_nowa_ksiazke()
- {
- struct ksiazka nowy;
- puts("Wypełnij dane ksiazki: ");
- printf("Identyfikator: \t");
- scanf("%u", &nowy.ID);
- while(getchar()!='\n');
- printf("Tytul:\t ");
- scanf("%[^\n]s", &nowy.tytul);
- while(getchar()!='\n');
- printf("Rok wydania: \t");
- scanf("%u", &nowy.rok);
- while(getchar()!='\n');
- printf("Autor: ");
- scanf("%[^\n]s", &nowy.autor);
- while(getchar()!='\n');
- printf("Gatunek: ");
- scanf("%[^\n]s", &nowy.gatunek);
- while(getchar()!='\n');
- printf("Liczba egzemplarzy: ");
- scanf("%u", &nowy.liczba_egzemplarzy);
- while(getchar()!='\n');
- printf("Liczba wypozyczonych: ");
- scanf("%u", &nowy.liczba_wypozyczonych);
- while(getchar()!='\n');
- return nowy;
- };
- struct klient *create_list_client()
- {
- struct klient *first =(struct klient *)malloc(sizeof(struct klient));
- if(first)
- {
- struct klient nowy;
- nowy = wczytaj_nowego_klienta();
- first->numer_karty = nowy.numer_karty;
- strcpy(first->imie, nowy.imie);
- strcpy(first->nazwisko, nowy.nazwisko);
- strcpy(first->telefon, nowy.telefon);
- first->nastepny = NULL;
- }
- return first;
- }
- struct ksiazka *create_list_book()
- {
- struct ksiazka *first =(struct ksiazka *)malloc(sizeof(struct ksiazka));
- if(first)
- {
- struct ksiazka nowy;
- nowy = wczytaj_nowa_ksiazke();
- first->ID = nowy.ID;
- strcpy(first->tytul, nowy.tytul);
- first->rok = nowy.rok;
- strcpy(first->autor, nowy.autor);
- strcpy(first->gatunek, nowy.gatunek);
- first->liczba_egzemplarzy = nowy.liczba_egzemplarzy;
- first->liczba_wypozyczonych = nowy.liczba_wypozyczonych;
- first->nastepny = NULL;
- }
- return first;
- }
- struct klient *add_node_client(struct klient *list_pointer)
- {
- struct klient *nowy_klient = (struct klient *)malloc(sizeof(struct klient));
- if(list_pointer && nowy_klient) {
- struct klient nowy;
- nowy = wczytaj_nowego_klienta();
- nowy_klient->numer_karty = nowy.numer_karty;
- strcpy(nowy_klient->imie, nowy.imie);
- strcpy(nowy_klient->nazwisko, nowy.nazwisko);
- strcpy(nowy_klient->telefon, nowy.telefon);
- nowy_klient->nastepny = list_pointer->nastepny;
- list_pointer->nastepny = nowy_klient;
- }
- return list_pointer;
- }
- struct ksiazka *add_node_book(struct ksiazka *list_pointer)
- {
- struct ksiazka *nowa_ksiazka = (struct ksiazka *)malloc(sizeof(struct ksiazka));
- if(list_pointer && nowa_ksiazka) {
- struct ksiazka nowy;
- nowy = wczytaj_nowa_ksiazke();
- nowa_ksiazka->ID = nowy.ID;
- nowa_ksiazka->ID = nowy.ID;
- strcpy(nowa_ksiazka->tytul, nowy.tytul);
- nowa_ksiazka->rok = nowy.rok;
- strcpy(nowa_ksiazka->autor, nowy.autor);
- strcpy(nowa_ksiazka->gatunek, nowy.gatunek);
- nowa_ksiazka->liczba_egzemplarzy = nowy.liczba_egzemplarzy;
- nowa_ksiazka->liczba_wypozyczonych = nowy.liczba_wypozyczonych;
- nowa_ksiazka->nastepny = list_pointer->nastepny;
- list_pointer->nastepny = nowa_ksiazka;
- }
- return list_pointer;
- }
- void wyswietlanie_klient(struct klient *a){
- struct klient *tmp;
- tmp = a;
- if (tmp == NULL)
- printf("Brak elementow, wybierz z listy:\n");
- else
- {
- while (tmp != NULL)
- {
- printf("ID: %u\nImie: %s\nNazwisko: %s \nTelefon: %s\n", tmp->numer_karty, tmp->imie, tmp->nazwisko, tmp->telefon);
- printf("\n");
- tmp = tmp->nastepny;
- }
- }
- }
- struct klient *find_previous_node(struct klient *list_pointer, int id)
- {
- struct klient *previous = NULL;
- while(list_pointer && list_pointer->numer_karty!=id) {
- previous=list_pointer;
- list_pointer=list_pointer->nastepny;
- }
- return previous;
- };
- struct klient *delete_at_front(struct klient *list_pointer)
- {
- struct klient *next = list_pointer->nastepny;
- free(list_pointer);
- return next;
- };
- struct klient *delete_node(struct klient *list_pointer, int id)
- {
- if(list_pointer) {
- if(list_pointer->numer_karty==id)
- return delete_at_front(list_pointer);
- else {
- struct list_node *previous =
- find_previous_node(list_pointer,id);
- delete_middle_or_last_node(previous);
- }
- }
- return list_pointer;
- };
- void delete_middle_or_last_node(struct klient *previous)
- {
- struct klient *node = previous->nastepny;
- if(node) {
- previous->nastepny = node->nastepny;
- free(node);
- }
- }
- //asdasdasd
- struct ksiazka *find_previous_node_ksiazka(struct ksiazka *list_pointer, int id)
- {
- struct ksiazka *previous = NULL;
- while(list_pointer && list_pointer->ID!=id) {
- previous=list_pointer;
- list_pointer=list_pointer->nastepny;
- }
- return previous;
- };
- struct ksiazka *delete_at_front_ksiazka(struct ksiazka *list_pointer)
- {
- struct ksiazka *next = list_pointer->nastepny;
- free(list_pointer);
- return next;
- };
- struct ksiazka *delete_node_ksiazka(struct ksiazka *list_pointer, int id)
- {
- if(list_pointer) {
- if(list_pointer->ID==id)
- return delete_at_front_ksiazka(list_pointer);
- else {
- struct list_node *previous =
- find_previous_node_ksiazka(list_pointer,id);
- delete_middle_or_last_node_ksiazka(previous);
- }
- }
- return list_pointer;
- };
- void delete_middle_or_last_node_ksiazka(struct ksiazka *previous)
- {
- struct ksiazka *node = previous->nastepny;
- if(node) {
- previous->nastepny = node->nastepny;
- free(node);
- }
- }
- void wyswietlanie_ksiazek(struct ksiazka *a){
- struct ksiazka *tmp;
- tmp = a;
- if (tmp == NULL)
- printf("Brak elementow, wybierz z listy:\n");
- else
- {
- while (tmp != NULL)
- {
- printf("ID: %u\nTytul: %s\nRok: %u\nAutor: %s\nGatunek: %s\nLiczba egzemplarzy: %u\nLiczba wypozyczonych: %u\n", tmp->ID, tmp->tytul, tmp->rok, tmp->autor, tmp->gatunek, tmp->liczba_egzemplarzy, tmp->liczba_wypozyczonych);
- printf("\n");
- tmp = tmp->nastepny;
- }
- }
- }
- void modyfikuj_klienta(struct klient *a)
- {
- }
- int main()
- {
- system("chcp 1250>null");
- struct klient *a = NULL;
- struct ksiazka *ksiazka = NULL;
- unsigned int opcja = 0;
- unsigned char ile = 0;
- printf("Witamy w projekcie Wypożyczalnia książek");
- printf("Wybierz co chesz zrobić:\n");
- puts("1. Dodawanie/usuwanie/edycja/wyswietlanie klientów");
- puts("2. Dodawanie/usuwanie/edycja/wyswietlanie książek");
- puts("3. Wypożyczenie/oddanie książki");
- puts("4. Wyœwietlenie książek");
- puts("5. Wyszukanie książek");
- puts("6. Zapisanie/wczytanie danych o klientach, książkach i wypożyczeniach");
- puts("0. Wyjście");
- printf("Wybieram opcje nr. ");
- while(scanf("%u", &opcja))
- {
- int id;
- switch(opcja)
- {
- case 1: //klienci
- printf("Co teraz chcesz zrobić: \n");
- system("cls");
- printf("1. Dodawanie\n2. Usuwanie\n3. Edytowanie\n4. Wyswietlanie\n0. Powrót\n");
- while(scanf("%u", &opcja)!=5){
- switch(opcja)
- {
- case 1:
- if(a==NULL)
- {
- a= create_list_client();
- }
- else
- {
- a = add_node_client(a);
- }
- printf("Co teraz chcesz zrobić: \n");
- system("cls");
- break;
- case 2:
- wyswietlanie_klient(a);
- if(a==NULL){}
- else{
- puts("Podaj ID klienta którego chcesz usunąć: ");
- scanf("%d", &id);
- a = delete_node(a, id);
- }
- break;
- case 3:
- wyswietlanie_klient(a);
- if(a==NULL){}else{
- puts("Podaj ID klienta którego chcesz modyfikować: ");
- scanf("%u", &id);}
- break;
- case 4:
- wyswietlanie_klient(a);
- break;
- case 0:
- break;
- default:
- printf("Niepoprawna komenda");
- break;
- }
- printf("1. Dodawanie\n2. Usuwanie\n3. Edytowanie\n4. Wyswietlanie\n0. Powrót\n");
- if(opcja==0)
- break;
- }
- break;
- case 2: //ksiazki
- printf("Co teraz chcesz zrobić: \n");
- system("cls");
- printf("1. Dodawanie\n2. Usuwanie\n3. Edytowanie\n4. Wyswietlanie\n0. Powrót\n");
- while(scanf("%u", &opcja)!=5){
- switch(opcja)
- {
- case 1:
- if(ksiazka==NULL)
- {
- ksiazka= create_list_book();
- }
- else
- {
- ksiazka = add_node_book(ksiazka);
- }
- printf("Co teraz chcesz zrobić: \n");
- system("cls");
- break;
- case 2:
- wyswietlanie_ksiazek(ksiazka);
- puts("Podaj ID klienta którego chcesz usunąć: ");
- scanf("%d", &id);
- ksiazka = delete_node_ksiazka(ksiazka, id);
- break;
- case 3:
- break;
- case 4:
- wyswietlanie_ksiazek(ksiazka);
- break;
- case 0:
- break;
- default:
- printf("Niepoprawna komenda");
- break;
- }
- printf("1. Dodawanie\n2. Usuwanie\n3. Edytowanie\n4. Wyswietlanie\n0. Powrót\n");
- if(opcja==0)
- break;
- }
- break;
- case 3:
- break;
- case 4:
- break;
- case 5:
- break;
- case 6:
- break;
- case 0:
- return 0;
- break;
- default:
- printf("Opcja o numerze %u nie istnieje!", opcja);
- break;
- }
- system("cls");
- printf("Witamy w projekcie Wypożyczalnia książek");
- printf("Wybierz co chesz zrobić:\n");
- puts("1. Dodawanie/usuwanie/edycja/wyswietlanie klientów");
- puts("2. Dodawanie/usuwanie/edycja/wyswietlanie książek");
- puts("3. Wypo¿yczenie/oddanie książki");
- puts("4. Wyœwietlenie książek");
- puts("5. Wyszukanie książek");
- puts("6. Zapisanie/wczytanie danych o klientach, książkach i wypożyczeniach");
- puts("0. Wyjście");
- printf("Wybieram opcje nr. ");
- }
- return 0;
- }
- /*
- Wypo¿yczalnia ksi¹¿ek.
- Dodawanie/usuwanie/edycja klientów (numer karty, nazwisko, imiê, telefon).
- Dodawanie/usuwanie/edycja ksi¹¿ek (ID, tytu³, rok, autor, gatunek, liczba egzemplarzy, liczba wypo¿yczonych).
- Wypo¿yczanie/oddawanie ksi¹¿ek (kto wypo¿yczy³ (numer karty), któr¹ ksi¹¿kê (ID), kiedy, do kiedy).
- Wyœwietlanie ksi¹¿ek z mo¿liwoœci¹ sortowania rosn¹cego/malej¹cego po dowolnym polu.
- Wyszukiwanie ksi¹¿ek.
- Zapisywanie/wczytywanie danych o klientach, ksi¹¿kach i wypo¿yczeniach do/z plików.
- Wykorzystanie list.
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement