Kis ZH megirasa A kis ZH feladatai: Az oldal aljan 2. nagy ZH megbeszelese Bitmuveletek ------------ -negalas: ~ -es & -vagy | -xor -bitleptetes >> - balra 2-vel szorzas << - jobbra 2-vel osztas unsigned: meguresedett bitek 0-val feltoltodnek signed: ? gepfuggo ? Maszkolas: FA: A 4. bitig az osszes bit 0-ra allitasa (int) a&~15 Az osszes bit 1-re allitasa a 4. bit-ig a|15 FIGYELEM: & != && | != || pl: 3&12=0, de 3&&12 != 0 Rekurzio -------- FA: szamitsuk ki, hogy a sakktabla 1,1 elemerol mely elemek erhetok el es legkevesebb hany lepesben huszarral! (hf befejezni) Mutatok es tombok ----------------- szoros kapcsolat, minden tombindexeles vegrehajthato mutatokkal is pl double tomb[5], *tombpointer, szam; tombpointer=&tomb[0]; szam=*tombpointer; //szam=tomb[0]; (tombpointer+3) // a tomb 3. elemere mutat tombpointer++ // a tomb kovetkezo elemere Adattipusok definialasa ----------------------- uj adattipusok letrehozasa typedef kulcsszo pl typedef double valos; fuggveytipus definicio: typedef int (*ft) (double x); ft elojel; int sign(double a){ if (a>0.0){ return 1;}else{return -1;} } main(){ ft = & sign; cout << (*ft)(-23.9); } A kis ZH feladatai: ------------------- 1., #include #include using namespace std; int szamol(int a, int b[], int *c){ if (a!=0) { *c = ++b[0]; cout << " Elotte: a = " << a; cout << "\n b[0] = " << b[0]; cout << "\n *c = " << *c << endl; szamol(a-1, b+a, c); cout << " Utana: a = " << a; cout << "\n b[0] = " << b[0]; cout << "\n *c = " << *c << endl; return(b[0]); } else { return (0);} } // szamol() int main() { int t[] = {7,5,3,1}; int g, i, e = 2; int *f = &e; g = szamol(e, t, f); cout << "e= " << e; cout << " *f= " << *f; cout << " g= " << g << endl; for (i = 0; i< 4; i++){ cout << "t[" << i << "] = " << t[i] << endl; } cout << endl; system("PAUSE"); return 0; } 2., #include #include using namespace std; int szamol(int a, int b[], int *c){ if (a!=0) { *c = b[0]++; cout << " Elotte: a = " << a; cout << "\n b[0] = " << b[0]; cout << "\n *c = " << *c << endl; szamol(a-1, b+a-1, c); cout << " Utana: a = " << a; cout << "\n b[0] = " << b[0]; cout << "\n *c = " << *c << endl; return(b[0]); } else { return (0);} } // szamol() int main() { int t[] = {7,5,3,1}; int g, i, e = 2; int *f = &e; g = szamol(e, t, f); cout << "e= " << e; cout << " *f= " << *f; cout << " g= " << g << endl; for (i = 0; i< 4; i++){ cout << "t[" << i << "] = " << t[i] << endl; } cout << endl; system("PAUSE"); return 0; } 3., #include #include using namespace std; int szamol(int a, int b[], int *c){ if (a!=0) { *c = b[a]++; cout << " Elotte: a = " << a; cout << "\n b[0] = " << b[0]; cout << "\n *c = " << *c << endl; szamol(a-1, b+a-1, c); cout << " Utana: a = " << a; cout << "\n b[0] = " << b[0]; cout << "\n *c = " << *c << endl; return(b[0]); } else { return (0);} } // szamol() int main() { int t[] = {7,5,3,1}; int g, i, e = 2; int *f = &e; g = szamol(e, t, f); cout << "e= " << e; cout << " *f= " << *f; cout << " g= " << g << endl; for (i = 0; i< 4; i++){ cout << "t[" << i << "] = " << t[i] << endl; } cout << endl; system("PAUSE"); return 0; }