| | |
| Stránka: 1 z 1
| [ Príspevkov: 5 ] | |
Autor | Správa |
---|
Registrovaný: 09.05.09 Prihlásený: 09.05.09 Príspevky: 5 Témy: 2 |
Kód: #include <stdio.h> #include <conio.h> #include <stdlib.h> #include <string.h>
struct ucet { int cislo; char typ; // b - bezny, t - terminovany, s - sporiaci char meno[20]; char priezvisko[30]; float zostatok; float poplatok; float urok; ucet *dalsi; };
struct banka { ucet *prvy; ucet *posledny; int pocet; int maxcislo; };
int hlavnemenu(void) { system("cls"); printf("====== HLAVNE MENU ======\n"); printf(" 1 - vytvor novy ucet \n"); // OK printf(" 2 - nacitaj zo suboru \n"); // OK printf(" 3 - uloz do suboru \n"); // OK printf(" 4 - vklad na ucet \n"); // OK printf(" 5 - vyber z uctu \n"); // OK printf(" 6 - prevod medzi uctami \n"); // OK printf(" 7 - Vypis uctov \n"); // OK printf(" 8 - Koniec programu \n"); // OK printf(" 9 - Zrusenie uctu \n"); // OK printf("=========================\n"); int znak; do { znak = 0; znak = getch(); } while (!((znak >='1') && (znak <= '9'))); return znak; }
int funkcia4(banka &bb) { int cislouctu; printf("\nZadaj cislo uctu na ktory budu peniaze ulozene : \n"); scanf("%d", &cislouctu); float suma; printf("\nZadaj sumu, ktoru chces vlozit :\n"); scanf("%f", &suma); ucet *pomocny = bb.prvy; printf("\n"); while( pomocny != NULL) { if (pomocny->cislo == cislouctu) { pomocny->zostatok = pomocny->zostatok + suma; printf("\nSuma %f bola uspesne pripisana na ucet\n", suma); getch(); return 0; } pomocny = pomocny->dalsi; } printf("\nZvoleny ucet neexistuje\n"); char pom = getch(); return -1; }
// vyber z uctu int funkcia5(banka &bb) { int cislouctu; printf("\nZadaj cislo uctu z ktoreho budu peniaze vybrate : \n"); scanf("%d", &cislouctu); float suma; printf("\nZadaj sumu, ktoru chces vybrat :\n"); scanf("%f", &suma); ucet *pomocny = bb.prvy; printf("\n"); while( pomocny != NULL) { if (pomocny->cislo == cislouctu) { if (suma > pomocny->zostatok) { printf("\nNa ucte nie je dostatok financii !\n"); getch();
return -1; } pomocny->zostatok = pomocny->zostatok - suma; printf("\nSuma %f bola uspesne vybrata z uctu\n", suma); getch(); return 0; } pomocny = pomocny->dalsi; } printf("\nZvoleny ucet neexistuje\n"); char pom = getch(); return -1; }
// pridanie noveho uctu int funkcia1(banka &bb) { char typuctu = ' '; do { printf("\nVyber typ uctu ('t'=terminovany ; 'b'=bezny ; 's'=sporiaci)\n"); typuctu = getch(); } while (!((typuctu == 't') || (typuctu == 's') || (typuctu == 'b'))); printf("Zadaj urokovu mieru: \n"); float nacitanyurok; scanf("%f", &nacitanyurok); printf("\nZadaj poplatok: \n"); float nacitanypoplatok; scanf("%f", &nacitanypoplatok);
char kmeno[20]; printf("\nZadaj krstne meno majitela uctu : \n"); scanf("%s", kmeno); kmeno[19] = 0; char priezvisko[30]; printf("\nZadaj priezvisko majitela uctu : \n"); scanf("%s", priezvisko); priezvisko[29] = 0; ucet *pomocny = (ucet *) malloc(sizeof(ucet)); if (pomocny == NULL) { printf("\nCHYBA, UCET NEBOL VYTVORENY\n"); char ppp = getch(); return -1; } pomocny->urok = nacitanyurok; pomocny->poplatok = nacitanypoplatok; pomocny->zostatok = 0; strncpy(pomocny->meno, kmeno, 20); strncpy(pomocny->priezvisko, priezvisko, 30); pomocny->typ = typuctu; pomocny->dalsi = NULL; pomocny->cislo = bb.maxcislo+1; bb.maxcislo++; // doteraz nebol v pamati ziadny ucet if (bb.prvy == NULL) { bb.prvy = bb.posledny = pomocny; bb.pocet = 1; } else { bb.posledny->dalsi = pomocny; bb.posledny = bb.posledny->dalsi; bb.pocet++; } return 0; }
// zrusenie uctu int funkcia9 (banka &bb) { printf("\nZadaj cislo uctu, ktory sa ma zrusit\n"); int cislouctu; scanf("%d", &cislouctu); ucet *pomocny = bb.prvy; if (bb.prvy == NULL) { printf("\nZvoleny ucet neexistuje !\n"); getch(); return -1; } if (pomocny->cislo == cislouctu) { if (bb.posledny == bb.prvy) bb.posledny = bb.prvy->dalsi; bb.prvy = bb.prvy->dalsi; free(pomocny); printf("\nUcet bol uspesne zruseny\n"); bb.pocet--; getch(); return 0; } while( pomocny->dalsi != NULL) {
if (pomocny->dalsi->cislo == cislouctu) { ucet *pomocny2 = pomocny->dalsi->dalsi; free(pomocny->dalsi); pomocny->dalsi = pomocny2; bb.pocet--; printf("\nUcet bol uspesne zruseny\n"); getch(); return 0; } pomocny = pomocny->dalsi; } printf("\nZvoleny ucet neexistuje !\n"); getch(); return -1; }
// nacitanie zo suboru int funkcia2(banka &bb) { // dealokovanie if (bb.prvy != NULL) { ucet *pom1, *pom2; pom1 = bb.prvy; do { pom2 = pom1->dalsi; free(pom1); pom1 = pom2; } while (!(pom1 == NULL)); bb.prvy = bb.posledny = NULL; bb.pocet = 0; bb.maxcislo = 11111111; } printf("\nZadaj nazov suboru : \n"); char suborik[60]; scanf("%s", suborik); FILE *fsubor = fopen(suborik, "r+"); if (fsubor == NULL) { printf("\nChyba, subor sa nepodarilo vytvorit !\n"); return -1; }; int pocetuctov = 0; fscanf(fsubor, "%d\n", &pocetuctov); int maxcisielko = 0; ucet hlp; ucet *pomoc; for (int i = 0; i < pocetuctov; i++) { fscanf(fsubor,"%d %s %s %c %f %f %f \n", &(hlp.cislo), hlp.meno, hlp.priezvisko, &(hlp.typ), &(hlp.zostatok), &(hlp.poplatok), &(hlp.urok)); pomoc = (ucet *) malloc(sizeof(ucet)); *pomoc = hlp; pomoc->dalsi = NULL; if (bb.pocet == 0) { bb.prvy = bb.posledny = pomoc; bb.pocet = 1; bb.maxcislo = bb.prvy->cislo; } else { bb.posledny->dalsi = pomoc; bb.posledny = bb.posledny->dalsi; bb.pocet++; } if (bb.posledny->cislo > maxcisielko) { maxcisielko = bb.posledny->cislo; }; } bb.maxcislo = maxcisielko; fclose(fsubor); printf("Nacitanie bolo uspesne !"); char cc = getch(); return 0; }
int funkcia6(banka &bb) { int ucet1, ucet2; float suma = 0; printf("\nZadaj cislo uctu platitela : \n"); scanf("%d", &ucet1);
printf("\nZadaj cislo uctu prijemcu : \n"); scanf("%d", &ucet2);
printf("\nZadaj sumu ktora sa ma previest : \n"); scanf("%f", &suma); if (ucet1 == ucet2) { printf("\nChyba, zdrojovy ucet sa rovna cielovemu !\n"); return -2; } char najdeny1 = 0, najdeny2 = 0; ucet *pomocny = bb.prvy; while(pomocny != NULL) { if (pomocny->cislo == ucet2) najdeny2 = 1; if ((pomocny->cislo == ucet1) && (pomocny->zostatok >= suma)) najdeny1 = 1; pomocny = pomocny->dalsi; }; if ((najdeny1) && (najdeny2)) { ucet *pomocny2 = bb.prvy; while(pomocny2 != NULL) { if (pomocny2->cislo == ucet2) pomocny2->zostatok = pomocny2->zostatok + suma; if (pomocny2->cislo == ucet1) pomocny2->zostatok = pomocny2->zostatok - suma; pomocny2 = pomocny2->dalsi; }; } else { printf("\nChyba, jeden z uctov nebol najdeny, alebo platitel nema dostatocny zostatok na platbu"); getch(); return -1; } printf("\nTransakcia bola uspesne zrealizovana\n"); getch(); return 0; }
// zapis do suboru int funkcia3(banka &bb) { printf("\nZadaj nazov suboru : \n"); char suborik[60]; scanf("%s", suborik); FILE *fsubor = fopen(suborik, "w+"); if (fsubor == NULL) { printf("\nChyba, subor sa nepodarilo vytvorit !\n"); return -1; }; fprintf(fsubor, "%d\n", bb.pocet); ucet *pomocny = bb.prvy; while(pomocny != NULL) { fprintf(fsubor, "%d %s %s %c %f %f %f \n", pomocny->cislo, pomocny->meno, pomocny->priezvisko, pomocny->typ, pomocny->zostatok, pomocny->poplatok, pomocny->urok); pomocny = pomocny->dalsi; }; fclose(fsubor); printf("\nZapis do suboru bol uspesny\n"); char cc = getch(); return 0; }
// vypis uctov int funkcia7(banka &bb) { ucet *pomocny = bb.prvy; printf("\n"); while( pomocny != NULL) { printf("%d %s %s %c %f %f %f \n", pomocny->cislo, pomocny->meno, pomocny->priezvisko, pomocny->typ, pomocny->zostatok, pomocny->poplatok, pomocny->urok); pomocny = pomocny->dalsi; } printf("\nPokracujte stlacenim lubovolneho klavesu \n"); char pom = getch(); }
int main(void) { banka slsp; slsp.prvy = NULL; slsp.posledny = NULL; slsp.pocet = 0; slsp.maxcislo = 11111111; int vstup = 0; do { vstup = hlavnemenu(); // vytvorenie noveho uctu if (vstup == '1') funkcia1(slsp); // zapis do suboru if (vstup == '2') funkcia2(slsp); // zapis do suboru if (vstup == '3') funkcia3(slsp);
if (vstup == '4') funkcia4(slsp);
if (vstup == '5') funkcia5(slsp);
if (vstup == '6') funkcia6(slsp); // vypis if (vstup == '7') funkcia7(slsp); // zrusenie uctu if (vstup == '9') funkcia9(slsp); } while (vstup != '8'); // dealokovanie if (slsp.prvy != NULL) { ucet *pom1, *pom2; pom1 = slsp.prvy; do { pom2 = pom1->dalsi; free(pom1); pom1 = pom2; } while (!(pom1 == NULL)); slsp.prvy = slsp.posledny = NULL; slsp.pocet = 0; } return 0; }
ako upravim to zadanie mi tam vyhodí same warningy
|
|
Registrovaný: 20.10.07 Prihlásený: 27.03.10 Príspevky: 16 Témy: 4 |
urcite tu este vypis tie warningy...a setky tie chyby pri kompilacii
|
|
Registrovaný: 09.05.09 Prihlásený: 09.05.09 Príspevky: 5 Témy: 2 | Napísal autor témy janka1412: 09.05.2009 19:40 | |
|
17 C:\Dev-Cpp\zada.c syntax error before "ucet"
17 C:\Dev-Cpp\zada.c [Warning] no semicolon at end of struct or union
23 C:\Dev-Cpp\zada.c syntax error before "ucet"
23 C:\Dev-Cpp\zada.c [Warning] no semicolon at end of struct or union
24 C:\Dev-Cpp\zada.c [Warning] data definition has no type or storage class
27 C:\Dev-Cpp\zada.c syntax error before '}' token
59 C:\Dev-Cpp\zada.c syntax error before '&' token
C:\Dev-Cpp\zada.c In function `funkcia4':
69 C:\Dev-Cpp\zada.c `ucet' undeclared (first use in this function)
(Each undeclared identifier is reported only once
for each function it appears in.)
69 C:\Dev-Cpp\zada.c `pomocny' undeclared (first use in this function)
69 C:\Dev-Cpp\zada.c `bb' undeclared (first use in this function)
At top level:
91 C:\Dev-Cpp\zada.c syntax error before '&' token
C:\Dev-Cpp\zada.c In function `funkcia5':
101 C:\Dev-Cpp\zada.c `ucet' undeclared (first use in this function)
101 C:\Dev-Cpp\zada.c `pomocny' undeclared (first use in this function)
101 C:\Dev-Cpp\zada.c `bb' undeclared (first use in this function)
At top level:
130 C:\Dev-Cpp\zada.c syntax error before '&' token
C:\Dev-Cpp\zada.c In function `funkcia1':
158 C:\Dev-Cpp\zada.c `ucet' undeclared (first use in this function)
158 C:\Dev-Cpp\zada.c `pomocny' undeclared (first use in this function)
158 C:\Dev-Cpp\zada.c syntax error before ')' token
173 C:\Dev-Cpp\zada.c `bb' undeclared (first use in this function)
At top level:
194 C:\Dev-Cpp\zada.c syntax error before '&' token
C:\Dev-Cpp\zada.c In function `funkcia9':
200 C:\Dev-Cpp\zada.c `ucet' undeclared (first use in this function)
200 C:\Dev-Cpp\zada.c `pomocny' undeclared (first use in this function)
200 C:\Dev-Cpp\zada.c `bb' undeclared (first use in this function)
227 C:\Dev-Cpp\zada.c `pomocny2' undeclared (first use in this function)
At top level:
246 C:\Dev-Cpp\zada.c syntax error before '&' token
C:\Dev-Cpp\zada.c In function `funkcia2':
250 C:\Dev-Cpp\zada.c `bb' undeclared (first use in this function)
252 C:\Dev-Cpp\zada.c `ucet' undeclared (first use in this function)
252 C:\Dev-Cpp\zada.c `pom1' undeclared (first use in this function)
252 C:\Dev-Cpp\zada.c `pom2' undeclared (first use in this function)
283 C:\Dev-Cpp\zada.c syntax error before "hlp"
284 C:\Dev-Cpp\zada.c `pomoc' undeclared (first use in this function)
285 C:\Dev-Cpp\zada.c 'for' loop initial declaration used outside C99 mode
287 C:\Dev-Cpp\zada.c `hlp' undeclared (first use in this function) 290 C:\Dev- Cpp\zada.c syntax error before ')' token
290 C:\Dev-Cpp\zada.c syntax error before ')' token
At top level:
321 C:\Dev-Cpp\zada.c syntax error before '&' token C:\Dev-Cpp\zada.c In function `funkcia6':
342 C:\Dev-Cpp\zada.c `ucet' undeclared (first use in this function)
342 C:\Dev-Cpp\zada.c `pomocny' undeclared (first use in this function)
342 C:\Dev-Cpp\zada.c `bb' undeclared (first use in this function)
356 C:\Dev-Cpp\zada.c `pomocny2' undeclared (first use in this function)
At top level:
379 C:\Dev-Cpp\zada.c syntax error before '&' token
C:\Dev-Cpp\zada.c In function `funkcia3':
392 C:\Dev-Cpp\zada.c `bb' undeclared (first use in this function)
394 C:\Dev-Cpp\zada.c `ucet' undeclared (first use in this function)
394 C:\Dev-Cpp\zada.c `pomocny' undeclared (first use in this function)
At top level:
409 C:\Dev-Cpp\zada.c syntax error before '&' token
C:\Dev-Cpp\zada.c In function `funkcia7':
411 C:\Dev-Cpp\zada.c `ucet' undeclared (first use in this function)
411 C:\Dev-Cpp\zada.c `pomocny' undeclared (first use in this function)
411 C:\Dev-Cpp\zada.c `bb' undeclared (first use in this function)
C:\Dev-Cpp\zada.c In function `main':
426 C:\Dev-Cpp\zada.c `banka' undeclared (first use in this function)
426 C:\Dev-Cpp\zada.c syntax error before "slsp"
427 C:\Dev-Cpp\zada.c `slsp' undeclared (first use in this function)
473 C:\Dev-Cpp\zada.c `ucet' undeclared (first use in this function)
473 C:\Dev-Cpp\zada.c `pom1' undeclared (first use in this function)
473 C:\Dev-Cpp\zada.c `pom2' undeclared (first use in this function)
C:\Dev-Cpp\Makefile.win [Build Error] [zada.o] Error 1
|
|
Registrovaný: 09.05.09 Prihlásený: 09.05.09 Príspevky: 5 Témy: 2 | Napísal autor témy janka1412: 09.05.2009 19:41 | |
|
proste v C++ to ide ale ked to dam iba do c tak tam toto vyhodí.....
|
|
Registrovaný: 30.05.07 Prihlásený: 29.03.14 Príspevky: 641 Témy: 46 |
a preco by to malo byt v C? podmienka je aby to islo v nix systemoch nie?
takze je tam par chyb kde mas toto }; a ma tam byt iba toto } (ale nie zas vsade!)
potom #include <conio.h> nahrad s #include <ncurses.h> lebo conio je kniznica pre dos a ncurses pre nix systemy a potom budes musiet aj prepisat vsetky getch() na getchar(), lebo getch() je iba v tom conio a v ncurses je getchar...
neviem ci to bude potom fungovat ale nebudu tam aspon errory
|
|
| Stránka: 1 z 1
| [ Príspevkov: 5 ] | |
Podobné témy | Témy | Odpovede | Zobrazenia | Posledný príspevok |
---|
| Zadanie v C++ ale potrebujem aby to slo pod OS- Unix systemo v Operačné systémy Unix a Linux | 2 | 505 | 09.05.2009 18:59 ac.milan | | unix a C v Assembler, C, C++, Pascal, Java | 8 | 997 | 07.12.2008 21:34 Logik | | zadanie c++ v Assembler, C, C++, Pascal, Java | 4 | 1012 | 06.06.2008 18:25 pccom | | C++ zadanie v Assembler, C, C++, Pascal, Java | 2 | 641 | 14.03.2017 16:27 void | | Zaverecne zadanie z C++ v Assembler, C, C++, Pascal, Java | 4 | 1419 | 14.06.2007 15:38 juho | | nokia c-5 zadanie hesla v Smartfóny a tablety | 2 | 496 | 06.11.2011 11:06 cyypo | | zadanie v C++ priklad na elektrotechniku, pomozte mi pliiis v Assembler, C, C++, Pascal, Java | 4 | 1604 | 09.06.2006 14:40 Harlequin | | fungovala by táto zostava komponentov ? v PC zostavy | 6 | 696 | 27.08.2019 22:03 D4rk1N0 | | Nokia Lumia 920 sa vznietila. Uhasili ju a fungovala ďalej v Novinky | 7 | 500 | 13.09.2014 9:17 Semp | | Unix Benchmarks v Operačné systémy Unix a Linux | 3 | 1442 | 08.02.2014 10:25 polo | | IBM UNIX AIX v Operačné systémy Unix a Linux | 5 | 761 | 06.06.2008 22:39 FERDA23 | | Najpouzivanejsi unix/linux v Operačné systémy Unix a Linux | 28 | 4946 | 08.01.2008 15:51 Wheeler | | Unix pre desktopy - DesktopBSD v Operačné systémy Unix a Linux | 10 | 1031 | 08.06.2006 0:26 JanoF | | Vypis argumentov - Csh - UNIX v Assembler, C, C++, Pascal, Java | 0 | 649 | 07.10.2007 16:32 SAmo | | Tuke - zadanie v Assembler, C, C++, Pascal, Java | 8 | 2036 | 12.12.2017 11:58 Skippy | | kniha zadanie v Assembler, C, C++, Pascal, Java | 2 | 356 | 04.11.2017 16:56 camarovk19 |
| Nemôžete zakladať nové témy v tomto fóre Nemôžete odpovedať na témy v tomto fóre Nemôžete upravovať svoje príspevky v tomto fóre Nemôžete mazať svoje príspevky v tomto fóre
|
|