Caute. Nasiel by sa tu nejky expert co by mi okomentoval a vysvetlil zdrojak k casti programu? prosiiim. program sa tyka evidencie.
tu je :
#include "datab.h"
void datab::ulozDoSuboru(void){
FILE *output = fopen ("data.dat", "wb" );
fwrite(Korcule,sizeof(zaznam),30,output);
fclose(output);
}
void datab::nacitajZoSuboru(void){
FILE *input = fopen( "data.dat", "rb" );
fread(Korcule,sizeof(zaznam),30,input);
fclose(input);
}
void datab::pridajZaznam(void){
int i=-1;
while((i<30)&&(Korcule[++i].Zmazane==false))
if(i==30){
printf("Databaza je plna .");
return;
}
Korcule.Zmazane=false;
printf("\n\n Znacku : ");
scanf("%s",&(Korcule.Znacka));
printf("Pocet koliesok : ");
scanf("%d",&(Korcule.PocetKoliesok));
printf("Seriove cislo : ");
scanf("%d",&(Korcule.SerioveCislo));
printf("Rychlost: ");
scanf("%f",&(Korcule.Rychlost));
printf("Prevedenie : ");
scanf("%c",&(Korcule.Prevedenie));
scanf("%c",&(Korcule.Prevedenie));
}
void datab::editujZaznam(void){
printf("\nZadaj cislo zaznamu ktory chces editovat (0-29)");
int i;
scanf("%d",&i);
if (Korcule.Zmazane){
printf("Zaznam neexistuje, neda sa editovat");
return;
}
printf("\n\nZnacku (%s): ",Korcule.Znacka);
scanf("%s",(Korcule.Znacka));
printf("Pocet koliesok (%d): ",Korcule[i].PocetKoliesok);
scanf("%d",&(Korcule[i].PocetKoliesok));
printf("Seriove cislo (%d): ",Korcule[i].SerioveCislo);
scanf("%d",&(Korcule[i].SerioveCislo));
printf("Rychlost (%f): ",Korcule[i].Rychlost);
scanf("%f",&(Korcule[i].Rychlost));
printf("Prevedenie (%c): ",Korcule[i].Prevedenie);
scanf("%c",&(Korcule[i].Prevedenie));
scanf("%c",&(Korcule[i].Prevedenie));
}
void datab::zmazZaznam(void){
printf("\nZadaj cislo zaznamu ktory chces zmazat (0-29)");
int cislo;
scanf("%d",&cislo);
Korcule[cislo].Zmazane=true;
printf("Zaznam bol zmazany \n");
}
void datab::hladajZaznam(void){
printf("\n\nZadaj znacku korcul ktore chces najst :");
char s[20];
scanf("%s",s);
printf("\nid | Znacka korcul | Pocet koliesok | Seriove c. | Rychlost | Prevednie\n");
for(int i=0;i<30;i++){
if(!(Korcule[i].Zmazane))
if(NULL!=strstr(Korcule[i].Znacka,s))
printf("%2d %13s %14d %14d %10.2f %10c\n",i,Korcule[i].Znacka,Korcule[i].PocetKoliesok,Korcule[i].SerioveCislo,Korcule[i].Rychlost,Korcule[i].Prevedenie);
}
}
void vymen(zaznam &z1,zaznam &z2){
zaznam pom;
pom=z1;
z1=z2;
z2=pom;
}
void datab::zoradZaznamy(void){
for(int i=0;i<29;i++){
for(int j=i+1;j<30;j++){
if(!(Korcule[i].Zmazane && Korcule[j].Zmazane))
if( strcmp( Korcule[i].Znacka,Korcule[j].Znacka )>0 )
vymen(Korcule[i],Korcule[j]);
}
}
}
void datab::zobrazZaznamy(void){
printf("\nid | Znacka korcul| Pocet koliesok | Seriove c. | Rychlost | Prevedenie\n");
for(int i=0;i<30;i++){
if(!(Korcule[i].Zmazane))
printf("%2d %13s %14d %14d %10.2f %10c\n",i,Korcule[i].Znacka,Korcule[i].PocetKoliesok,Korcule[i].SerioveCislo,Korcule[i].Rychlost,Korcule[i].Prevedenie);
}
}
void datab::menu(void){
char znak=' ';
while(znak!='k'){
printf("\n\nDatabaza korcul : \n");
printf("p - Pridaj\n");
printf("e - Edituj\n");
printf("x - Zmaz\n");
printf("v - Vyhladaj\n");
printf("s - Zorad\n");
printf("z - Zobraz\n");
printf("k - Koniec\n");
printf("Vyber polozku z menu : \n");
znak=getch();
putch(znak);
switch(toupper(znak)){
case 'P':pridajZaznam();
break;
case 'E':editujZaznam();
break;
case 'X':zmazZaznam();
break;
case 'V':hladajZaznam();
break;
case 'S':zoradZaznamy();
break;
case 'Z':zobrazZaznamy();
break;
case 'K':break;
}
}
}
vysvetlenie zdrojaku C++
me ten kod nejde skomponovat nejake chyby
ale treba chyba je u me
Kód: Vybrať všetko
silent@silent-desktop:~/Plocha/a$ gcc evidencie.cpp -o evidencie
evidencie.cpp:1:19: error: datab.h: No such file or directory
evidencie.cpp:143:2: warning: no newline at end of file
evidencie.cpp:3: error: ‘datab’ has not been declared
evidencie.cpp: In function ‘void ulozDoSuboru()’:
evidencie.cpp:4: error: ‘FILE’ was not declared in this scope
evidencie.cpp:4: error: ‘output’ was not declared in this scope
evidencie.cpp:4: error: ‘fopen’ was not declared in this scope
evidencie.cpp:5: error: ‘Korcule’ was not declared in this scope
evidencie.cpp:5: error: ‘zaznam’ was not declared in this scope
evidencie.cpp:5: error: ‘fwrite’ was not declared in this scope
evidencie.cpp:6: error: ‘fclose’ was not declared in this scope
evidencie.cpp: At global scope:
evidencie.cpp:9: error: ‘datab’ has not been declared
evidencie.cpp: In function ‘void nacitajZoSuboru()’:
evidencie.cpp:10: error: ‘FILE’ was not declared in this scope
evidencie.cpp:10: error: ‘input’ was not declared in this scope
evidencie.cpp:10: error: ‘fopen’ was not declared in this scope
evidencie.cpp:11: error: ‘Korcule’ was not declared in this scope
evidencie.cpp:11: error: ‘zaznam’ was not declared in this scope
evidencie.cpp:11: error: ‘fread’ was not declared in this scope
evidencie.cpp:12: error: ‘fclose’ was not declared in this scope
evidencie.cpp: At global scope:
evidencie.cpp:15: error: ‘datab’ has not been declared
evidencie.cpp: In function ‘void pridajZaznam()’:
evidencie.cpp:18: error: ‘Korcule’ was not declared in this scope
evidencie.cpp:21: error: ‘printf’ was not declared in this scope
evidencie.cpp:25: error: ‘Korcule’ was not declared in this scope
evidencie.cpp:26: error: ‘printf’ was not declared in this scope
evidencie.cpp:27: error: ‘scanf’ was not declared in this scope
evidencie.cpp: At global scope:
evidencie.cpp:40: error: ‘datab’ has not been declared
evidencie.cpp: In function ‘void editujZaznam()’:
evidencie.cpp:41: error: ‘printf’ was not declared in this scope
evidencie.cpp:43: error: ‘scanf’ was not declared in this scope
evidencie.cpp:46: error: ‘Korcule’ was not declared in this scope
evidencie.cpp:51: error: ‘Korcule’ was not declared in this scope
evidencie.cpp: At global scope:
evidencie.cpp:65: error: ‘datab’ has not been declared
evidencie.cpp: In function ‘void zmazZaznam()’:
evidencie.cpp:66: error: ‘printf’ was not declared in this scope
evidencie.cpp:68: error: ‘scanf’ was not declared in this scope
evidencie.cpp:69: error: ‘Korcule’ was not declared in this scope
evidencie.cpp: At global scope:
evidencie.cpp:72: error: ‘datab’ has not been declared
evidencie.cpp: In function ‘void hladajZaznam()’:
evidencie.cpp:73: error: ‘printf’ was not declared in this scope
evidencie.cpp:75: error: ‘scanf’ was not declared in this scope
evidencie.cpp:78: error: ‘Korcule’ was not declared in this scope
evidencie.cpp:79: error: ‘NULL’ was not declared in this scope
evidencie.cpp:79: error: ‘strstr’ was not declared in this scope
evidencie.cpp: At global scope:
evidencie.cpp:84: error: variable or field ‘vymen’ declared void
evidencie.cpp:84: error: ‘zaznam’ was not declared in this scope
evidencie.cpp:84: error: ‘z1’ was not declared in this scope
evidencie.cpp:84: error: ‘zaznam’ was not declared in this scope
evidencie.cpp:84: error: ‘z2’ was not declared in this scope
evidencie.cpp:92: error: ‘datab’ has not been declared
evidencie.cpp: In function ‘void zoradZaznamy()’:
evidencie.cpp:96: error: ‘Korcule’ was not declared in this scope
evidencie.cpp:97: error: ‘strcmp’ was not declared in this scope
evidencie.cpp:98: error: ‘vymen’ was not declared in this scope
evidencie.cpp: At global scope:
evidencie.cpp:103: error: ‘datab’ has not been declared
evidencie.cpp: In function ‘void zobrazZaznamy()’:
evidencie.cpp:104: error: ‘printf’ was not declared in this scope
evidencie.cpp:106: error: ‘Korcule’ was not declared in this scope
evidencie.cpp: At global scope:
evidencie.cpp:111: error: ‘datab’ has not been declared
evidencie.cpp: In function ‘void menu()’:
evidencie.cpp:114: error: ‘printf’ was not declared in this scope
evidencie.cpp:123: error: ‘getch’ was not declared in this scope
evidencie.cpp:124: error: ‘putch’ was not declared in this scope
evidencie.cpp:126: error: ‘toupper’ was not declared in this scope
-
audiotrack
VIP
- Príspevky: 25958
- Registrovaný: 09 sep 2005, 18:39
- Kontaktovať používateľa:
Re: vysvetlenie zdrojaku C++
jasné že je problém u teba, ten zdroják nie je kompletný, chýbajú tam nalinkované niektoré knižnice atď atď..dagmarra napísal:...a vysvetlil zdrojak k casti programu?
dagmarra: čo konkrétne ti tam robí problém že tomu nerozumieš? celé sa mi to komentovať nechce, to by bol sloh
no napriklad mohol by si mi vysvetlit tento odsek?
void datab::ulozDoSuboru(void)
{
FILE *output = fopen ("data.dat", "wb" );
fwrite(Korcule,sizeof(zaznam),30,output);
fclose(output);
}
a tento znak && znamena and?
:: to co znamena?
Potom by si mi mohlo objasnit aj tento odsek
printf("\nid | Znacka korcul | Pocet koliesok | Seriove c. | Rychlost | Prevednie\n");
for(int i=0;i<30;i++){
if(!(Korcule.Zmazane))
if(NULL!=strstr(Korcule.Znacka,s))
printf("%2d %13s %14d %14d %10.2f %10c\n",i,Korcule.Znacka,Korcule.PocetKoliesok,Korcule.SerioveCislo,Korcule.Rychlost,Korcule.Prevedenie);
}
Nieco viem ale v niecom som si neni uplne ista.
dakujem
void datab::ulozDoSuboru(void)
{
FILE *output = fopen ("data.dat", "wb" );
fwrite(Korcule,sizeof(zaznam),30,output);
fclose(output);
}
a tento znak && znamena and?
:: to co znamena?
Potom by si mi mohlo objasnit aj tento odsek
printf("\nid | Znacka korcul | Pocet koliesok | Seriove c. | Rychlost | Prevednie\n");
for(int i=0;i<30;i++){
if(!(Korcule.Zmazane))
if(NULL!=strstr(Korcule.Znacka,s))
printf("%2d %13s %14d %14d %10.2f %10c\n",i,Korcule.Znacka,Korcule.PocetKoliesok,Korcule.SerioveCislo,Korcule.Rychlost,Korcule.Prevedenie);
}
Nieco viem ale v niecom som si neni uplne ista.
dakujem
-
audiotrack
VIP
- Príspevky: 25958
- Registrovaný: 09 sep 2005, 18:39
- Kontaktovať používateľa:
je to metodia triedy datab. datab je nejaký object, ktorý ma viac vlastností a funkcii. Jednou z nich je aj ulozDoSuboru(void). To void v zátvorke znamená že nevstupuje žiaden parameter. Všetko čo robí táto funkcia je to, že otvorí súbor data.dat na zapisovanie a zapamätá si na tento súbor smerník. Pomenovaný je ako output. Potom do neho zapíše čo treba a nakoniec ho zavredagmarra napísal:no napriklad mohol by si mi vysvetlit tento odsek?
void datab::ulozDoSuboru(void)
{
FILE *output = fopen ("data.dat", "wb" );
fwrite(Korcule,sizeof(zaznam),30,output);
fclose(output);
}
áno, && je and, || je or. Tie dve dvojbodky znamenajú že funkcia patrí danému objektu.dagmarra napísal:
a tento znak && znamena and?
:: to co znamena?
vypíše na riadok postupne hlavičku: značka korcul, pocet koliesok... oddelené zvislou ciarou. Potom prejde 30 záznamov nejakého pola a pre každý prvok si zistíč ie nie je zmazaný, ak nie je tak či obsahuje značku a ak áno, tak vypíše riadok ktorý sa skladá zo značky, počet koliesok... vlastne to isté ako máš v hlavičke tabulkydagmarra napísal:
Potom by si mi mohlo objasnit aj tento odsek
printf("\nid | Znacka korcul | Pocet koliesok | Seriove c. | Rychlost | Prevednie\n");
for(int i=0;i<30;i++){
if(!(Korcule.Zmazane))
if(NULL!=strstr(Korcule.Znacka,s))
printf("%2d %13s %14d %14d %10.2f %10c\n",i,Korcule.Znacka,Korcule.PocetKoliesok,Korcule.SerioveCislo,Korcule.Rychlost,Korcule.Prevedenie);
}
Nieco viem ale v niecom som si neni uplne ista.
dakujem
to zvýraznené: %2d %13s %14d %14d %10.2f %10c\n je formátovací reťazec. Označuje čo a ako vypísať. Každá hodnota výpisu začína percentom, potom ide počet miest, a potom znak (d pre číslo, s pre reťazec, c pre znak..). za čiarkami idú premenné ktoré sa za tieto percentá dosadia, ich počet musí sedieť. Znak \n znamená nový riadok