Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define _CRT_SECURE_NO_WARNINGS
- #include <stdio.h>
- #include <stdlib.h>
- #include <math.h>
- #include <locale.h>
- #include <string.h>
- #include <time.h>
- struct produkt
- {
- char nazwa[100];
- char cena[100];
- char numer[100];
- };
- struct paragon
- {
- struct produkt zakupiony;
- struct paragon* poprzedni;
- };
- struct magazyn
- {
- struct magazyn* poprzedni;
- struct produkt artykul;
- struct magazyn* nastepny;
- };
- void dodawanieDoListy(struct magazyn** gora, struct produkt dane)
- {
- struct magazyn* nowy = (struct magazyn*)malloc(sizeof(struct magazyn));
- strcpy(nowy->artykul.nazwa, dane.nazwa);
- strcpy(nowy->artykul.cena, dane.cena);
- strcpy(nowy->artykul.numer, dane.numer);
- nowy->poprzedni = 0;
- nowy->nastepny = *gora;
- if (*gora != NULL)
- (*gora)->poprzedni = nowy;
- (*gora) = nowy;
- }
- void odczytywamieZpliku(struct magazyn **gora, int *ile)
- {
- char znak[200];
- char nazwa[300] = "Magazyn.csv";
- FILE* plik;
- plik = fopen(nazwa, "r");
- if (plik == NULL)
- {
- perror("Nie udalo sie otworzyc magazynu");
- return 1;
- }
- else {
- puts("Sukces! Poprawnie wczytano produkty z magazynu");
- }
- struct produkt artykul;
- while (fscanf(plik, "%s", znak) != EOF) {
- sscanf(znak, "%[^;] ;%[^;] ;%[^;] ;%s ", artykul.nazwa, artykul.numer, artykul.cena);
- dodawanieDoListy(gora, artykul);
- (*ile)++;
- }
- }
- void wyswietlaniemagazynu(struct magazyn *gora)
- {
- if (gora == NULL) {
- puts("Magazyn jest pusty");
- }
- while (gora != NULL) {
- printf("%s %s %s\n", (gora)->artykul.nazwa, (gora)->artykul.cena, (gora)->artykul.numer);
- (gora) = (gora)->nastepny;
- }
- }
- void push(struct paragon** gora1, struct magazyn* produkt)
- {
- struct paragon* nowy = (struct paragon*)malloc(sizeof(struct paragon));
- strcpy(nowy->zakupiony.nazwa, produkt->artykul.nazwa);
- strcpy(nowy->zakupiony.cena, produkt->artykul.cena);
- nowy->poprzedni = NULL;
- if (*gora1 == NULL)
- *gora1 = nowy;
- else {
- nowy->poprzedni = *gora1;
- *gora1 = nowy;
- }
- }
- void wyswietlparagon(struct paragon* gora, int *suma, int *reszta)
- {
- time_t current_time;
- char* c_time_string;
- current_time = time(NULL);
- c_time_string = ctime(¤t_time);
- puts("---------------------------------");
- puts("SKLEP JASZEXPOL");
- puts("Paragon:");
- while (gora != NULL) {
- printf("%s, %s\n", gora->zakupiony.nazwa, gora->zakupiony.cena);
- gora = gora->poprzedni;
- }
- printf("Suma: %d\n", *suma);
- printf("Reszta: %d\n", *reszta);
- printf("Paragon wydany %s", c_time_string);
- puts("---------------------------------");
- }
- void dodawaniedoparagaonu(struct magazyn** gora, struct paragon** gora1, int liczikzakup, int *suma)
- {
- if (*gora == NULL || liczikzakup <= 0)
- return;
- struct magazyn* aktywny = *gora;
- int i;
- for (int i = 1; aktywny != NULL && i < liczikzakup; i++)
- aktywny = aktywny->nastepny;
- if (aktywny == NULL)
- return;
- *suma += atoi(aktywny->artykul.cena);
- push(gora1, aktywny);
- }
- void wyszuakniezakupu(struct magazyn* gora)
- {
- while ((gora) != NULL)
- {
- (gora) = (gora)->nastepny;
- }
- printf("%s %s %s\n", (gora)->artykul.nazwa, (gora)->artykul.cena, (gora)->artykul.numer);
- }
- void freszta(int *suma, int *reszta, int *gotowka)
- {
- puts("Wprowdz kwote jaka zaplacil klient:");
- while (scanf("%d", gotowka) != 1 || *gotowka<*suma)
- {
- puts("Kwota jest za niska lub ma bledny format!");
- int c;
- while ((c = getchar()) != '\n' && c != EOF );
- }
- *reszta = *gotowka - *suma;
- printf("Reszta: %d\n", *reszta);
- }
- void drukujParagon(struct paragon* gora, int *suma, int *reszta, int *zaplacono)
- {
- time_t current_time;
- char* c_time_string;
- current_time = time(NULL);
- c_time_string = ctime(¤t_time);
- FILE *plik;
- plik = fopen("G:\\paragon.txt", "w");
- fputs("-----------------------------------\n", plik);
- fputs("Paragon FISKALNY\n", plik);
- fputs("SKLEP JANUSZOP\n", plik);
- fputs("-----------------------------------\n", plik);
- while (gora != NULL) {
- fprintf(plik, "%s, %szl\n", gora->zakupiony.nazwa, gora->zakupiony.cena);
- gora = gora->poprzedni;
- }
- fprintf(plik,"Suma: %dzl\n", *suma);
- fprintf(plik, "Zaplacono: %dzl\n", *zaplacono);
- fprintf(plik,"Reszta: %dzl\n", *reszta);
- fprintf(plik, "Paragon wydany %s", c_time_string);
- fclose(plik);
- }
- int main()
- {
- int gotowka = 0;
- int reszta = 0;
- int licznikdel = 0;
- int licznikdod = 0;
- int suma = 0;
- setlocale(LC_ALL, "");
- struct paragon* dol = NULL;
- struct magazyn* gora = NULL;
- struct listakontatkow* nowy = NULL;
- struct listakontaktow* usun = NULL;
- char wybor[30];
- int a = 1;
- int licznik = 0;
- int ilosczakupow;
- int zakup;
- int czyZakup = 0;
- int czyWczytana = 0;
- int czyZaplacone = 0;
- int wybsort = 0;
- puts("----------------------------");
- puts("KASA FISKALNA");
- puts("----------------------------");
- puts("Wpisz:\nq - Wczytaj magazyn\nw - Wyswietl zawartosc magazynu\nz - Zakupy\ny - Wyswietl paragon\nr - Wydaj reszta\nc - Czyszczenie ekranu\nk - Zamknij");
- while (a == 1) {
- do {
- scanf("%s", &wybor);
- } while (wybor[0] != 'q' && wybor[0] != 'c' && wybor[0] != 'z' && wybor[0] != 'y' && wybor[0] != 'k' && wybor[0] != 'w' && wybor[0] != 't' && wybor[0] != 'f' && wybor[0] != 's' && wybor[0] != 'd' && wybor[0] != 'f' && wybor[0] != 'r');
- switch (wybor[0]) {
- case 'q':
- odczytywamieZpliku(&gora, &licznik);
- czyWczytana = 1;
- break;
- case 'w':
- if (czyWczytana == 1) {
- wyswietlaniemagazynu(gora);
- }
- else {
- puts("Najpierw wczytaj asortyment");
- }
- break;
- case 'z':
- if (czyWczytana == 1) {
- srand(time(NULL));
- ilosczakupow = 1 + rand() % 10;
- //printf("ilosc zakupow:%d\n", ilosczakupow);
- for (int i = 1; i <= ilosczakupow; i++) {
- zakup = 1 + rand() % licznik;
- //printf("zakup: %d\n", zakup);
- dodawaniedoparagaonu(&gora, &dol, zakup, &suma);
- }
- printf("Do zaplaty: %d\n", suma);
- czyZakup = 1;
- }
- else {
- puts("Najpierw wczytaj asorytyment");
- }
- break;
- case 'y':
- if (czyZaplacone == 1) {
- wyswietlparagon(dol, &suma, &reszta);
- }
- else {
- puts("Klient musi najpierw zapalcic!");
- }
- break;
- case 'r':
- if(czyZakup==1)
- freszta(&suma, &reszta, &gotowka);
- else {
- puts("Najpierw skasuj zakupy");
- }
- czyZaplacone = 1;
- break;
- case 'd':
- if (czyZaplacone == 1) {
- drukujParagon(dol, &suma, &reszta, &gotowka);
- }
- else {
- puts("Klient musi najpier zaplacic!");
- }
- break;
- case 'k':
- a = 0;
- break;
- case 'c':
- system("cls");
- break;
- }
- if (a == 1)
- puts("Wpisz:\nq - Wczytaj magazyn\nw - Wyswietl zawartosc magazynu\nz - Zakupy\ny - Wyswietl paragon\nr - Wydaj reszta\nc - Czyszczenie ekranu\nk - Zamknij");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement