1 / 19

Tipi Vektor

Universiteti Shtet ëror i Tetovës Fakulteti i Shkencave Matematike-Natyrore Departamenti i Informatikës PROGRAMIM I Ligjerata 5 fisnik.dalipi @ unite.edu.mk fisnikd.wordpress.com. Tipi Vektor.

serena
Télécharger la présentation

Tipi Vektor

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. UniversitetiShtetëror i TetovësFakulteti i Shkencave Matematike-NatyroreDepartamenti i InformatikësPROGRAMIM ILigjerata 5fisnik.dalipi@unite.edu.mkfisnikd.wordpress.com

  2. Tipi Vektor • Nje vektor eshte nje koleksion objektesh te te njejtit tip. Secili object nuk ka emer te vecante, por ato mund te aksesohen nga pozicioni i tyre ne vector. Psh. nese do te deklaromin nje vektor a : int a[i]; atehere per te aksesuar elementin e pare te vektorit duhet te shkruajme a[0] • Dimensioni i nje vektori percaktohet nga nje konstante dhe jo nga nje variable. const int buf_size = 512 char input_buffer [buf_size]; Mr. Fisnik Dalipi

  3. Tipi Vektor • Nje vektor mund te inicializoj elementet e tij ne menyre eksplicite: const i = 4; int V[i]={0,1,2,3} • Vektoret 2 dimensionale (matricat) deklarohen si: int M[4][3] qe do te thote se kemi te bejm me nje matrice numrash te plote me 4 rrjeshta dhe 3 kolona. Mund edhe te inicializohen elementet e matrices si me poshte: • int M[4][3] = {{0,1,2},{3,4,5},{6,7,8},{9,10,11}}; Mr. Fisnik Dalipi

  4. Strukturat kontrolluese • Nje bllok instruksionesh eshte nje bashkesi instruksionesh (secili perfundon me (;)) qe grupohen ngakllapat { dhe }. Strukturat e kontrollit qe do te prezantojme me poshte kane nje parameter te quajtur statement qe i referohet nje instruksioni te vetem apo nje bllok instruksionesh. • if dhe else • Sintaksa eshte: if (kusht) statement • kusht eshte shprehja qe do te vleresohet nese eshte true atehere statement ekzekutohet dhe nese eshte false ky statement injorohet. Mr. Fisnik Dalipi

  5. Strukturat kontrolluese (if) • Per shembull: • if (x == 100)  cout << "x eshte 100"; • Nese statement eshte nje grup instruksionesh atehere perdoren kllapat • Nese duam te ndodh dicka kur shprehja vleresohet me false atehere perdoret: • if (kusht) statement1 else statement2 Mr. Fisnik Dalipi

  6. Strukturat kontrolluese (if) • if (x == 100)  cout << "x eshte 100";else  cout << "x nuk eshte 100"; • if (x > 0)  cout << "x eshte pozitiv";else if (x < 0)  cout << "x eshte negativ";else  cout << "x eshte 0"; Mr. Fisnik Dalipi

  7. Ciklet • Ciklet kane per qellim te perserisin instruksionet nje numer te caktuar heresh: • Cikli while. • Sintaksa eshte: • while (shprehje) statement • Fuksioni i tij eshte te perserise statement per aq kohe sa shprehja eshte true . • #include <iostream> • int main () • { • int n; • cout << "Fut numrin per Start > "; • cin >> n; • while (n>0) { • cout << n << ", "; • --n; • } • cout << "Zjarr!"; • return 0; • } • Dalja:Fut numrin per Start > 88, 7, 6, 5, 4, 3, 2, 1, Zjarr! Mr. Fisnik Dalipi

  8. Ciklet (vazhd.) • Cikli do-while. • Sintaksa e tij eshte: • do statement while (kusht); • Funksionaliteti eshte i njejte pervec se kushti i do-while vleresohet mbas ekzekutimit te statement dhe jo para sit e cikli While. • Cikli For • Sintaksa eshte : • for (inicializim; kusht; ndryshim_vlerash) statement; • Fuksionaliteti i tij eshte te perserise ekzekutimin e statement, nje numer te caktuar heresh. Mr. Fisnik Dalipi

  9. Ciklet (vazhd.) • Nje cikel For funksionon keshtu: • 1, inicializim ekzekutohet. Zakonisht eshte nje vlere inicializuese qe sherben si ‘counter varible’. Kjo ekzekutohet vetem nje here.2, kusht vleresohet, nese eshte true cikli vazhdon, ne te kundert cikli ndalon dhe statement shperfillet.3, statement ekzekutohet. Si zakonisht mund te jete nje instruksion apo nje grup instruksionesh te futura ne { }.4, me ne fund, Cdo gje qe eshte specifikuar te zona ndryshim_vlerash ekzekutohet dhe cikli kalon te hapi 2. Mr. Fisnik Dalipi

  10. Ciklet (vazhd.) • Shembull • #include <iostream> • int main () • { • for (int n=10; n>0; n--) { • cout << n << ", "; • } • cout << "Zjarr!"; • return 0; • } • Dalja:10, 9, 8, 7, 6, 5, 4, 3, 2, 1, Zjarr! Mr. Fisnik Dalipi

  11. Struktura switch • Qellimi i switch eshte te kontrolloj per vleren e nje shprehje nese eshte e barabarte me vlera konstantesh. Kjo structure perdoret ne programet me shume zgjedhje dhe perdorimi i tij eleminon if-else ne seri apo te nderthurura. Sintaksa e kesaj strukture eshte: • switch (shprehje) {  case constant1:    Bllok instruksionesh 1    break;  case constant2:   Bllok instruksionesh 2    break;  .  .  .  default:    default Bllok instruksionesh  } Mr. Fisnik Dalipi

  12. Struktura switch (vazhd.) • Punon ne kete menyre: switch vlereson shprehje dhe kontrollon nese eshte ekuivalente me constant1, nese eshte atehere ekzekutohet Bllok instruksionesh1 derisa ndesh break dhe programi kercen jashte trupit te switch. • Nese shprehje nuk ishte ekuivalent me constant1 kontrollon nese shprehje eshte ekuivalent me constant2. Nese eshte ekzekutohet block of instructions 2 derisa ndesh break. Nese, shprehje nuk eshte ekuivalente me asnje nga konstantet atehere programi do te ekzekutoj instruksionet qe ndodhen te pjesa default: • Pjesa default eshte opsionale. Mr. Fisnik Dalipi

  13. Struktura switch (vazhd.) Kodet e meposhtmejaneekuivalente Switch if-else • switch (x) { • case 1: • cout << "x eshte 1"; break; • case 2: • cout << "x eshte 2"; break; • default: • cout << " vlere e panjohur" ; } • if (x == 1) { • cout << "x eshte 1"; } • else if (x == 2) { • cout << "x eshte 2"; • } • else { • cout << "vlere e panjohur"; • } Mr. Fisnik Dalipi

  14. Switch (vazhd.) • Perdorimi i break ben te mundur kercimin e pikes se ekzekutimit ne funt te switch • Vini re switch mund te perdoret per te krahasuar nje shprehje me konstante te ndryshme. Keshtu qe nuk perdorim dot psh (case (n*2):) apo (case (1..3):) sepse nuk jane konstante te vlefshme. Mr. Fisnik Dalipi

  15. Instruksionet e kercimit • -break • Perdorimi i break ben qe te dalesh nga cikli edhe nese kushti per fundin e ketij cikli nuk ehste plotesuar. Perdoret per te perfunduar nje cikel te pafundem apo per te forcuar fundin e nje cikli, para perfundimit te tij natyral . Per shembull, perpiqemi te perfundojme nje numerim(count_down) para se ai te mbaroj normalisht: Mr. Fisnik Dalipi

  16. Instruksionet e kercimit (break) • // break shembull • #include <iostream> • int main () • { • int n; • for (n=10; n>0; n--) { • cout << n << ", "; • if (n==3) • { • cout << “numerimi nderpritet!"; • break; • } • } • return 0; • } • Dalja: • 10, 9, 8, 7, 6, 5, 4, 3, numerimi nderpritet! Mr. Fisnik Dalipi

  17. Instruksionet e kercimit (continue) • Instruksioni continue shkakton qe ne program te kapercehet pjesa e instruksioneve pas continue, njesoj sikur te kishim mberitur te fundi i bllokut te instruksioneve. Ne kete menyre ai shkakton me force te kaloj pika e ekzekutimit te iteracioni vijues i ciklit. Per shembull me poshte do te kapercejme 5 ne numerim(count_down) : Mr. Fisnik Dalipi

  18. Instruksionet e kercimit (continue) • // continue shembull • #include <iostream> • int main () • { • for (int n=10; n>0; n--) { • if (n==5) continue; • cout << n << ", "; • } • cout << "Start!"; • return 0; • } • Dalja: • 10, 9, 8, 7, 6, 4, 3, 2, 1, Start! Mr. Fisnik Dalipi

  19. PYETJE?

More Related