You are on page 1of 111
5 Mist crcincernste << (] /groups/Smurfs.On.The.way TLV peal Goayll alll paws alg aut 1,4 acdlgigll anil la pSiaal Gay edi (++C) 2 ciguila Ciljlag clbaill Yo Aadigll Asli Asybll 4algll pad 1,4 yoyalill laa ple algicill YSey Cy Ciliysill Go ayjoll Ja elyle Vag AdjLu Gigi Aliul :Ayébeal Ciliysi gidg gi Cy 4algll yaujso Uo >a! Aayiag lil 29 LABIAL yA pSiaulja yd alaillg Gyagill pS! (isi ullsig ailapu alll Ley yssaly pSiles allo Yo ligauii SiSipgyll - y-ollufll ala CH: * High level programming language. © Compiler: convert form (c++) to (incline language) First Example: SADIE cys Galil Areal gsheall C pty p plans Aalead yo SU sh a 1a . // a first program in cet . #include . int main () i . cout <<"welcome to c++"; . return 0; 4 reas sal // comment (#43): Baad gl eUlae Yh eal pl dale y Gad Lib gg Cle jal) Gb pels Y (//) Gehl 54i eat phastals ge yell p22 22 Gill yd Be Ce PTs eb li oh ISS gl gb Gabel i AUS Sy 2. #include < iostream.h> CLAY DRY! SLL ole gt LS oles yl Ce Be cin >> é 3d oll cout<< : gal ous (Meth) ad plang Mia) AKI ele stal Oy22 (cout) Ji (cin) yl eal BLS Nady 3. int main(): Melos se dsS 48 (return 0) 4! ole ell gol Ge eid Ya dw wD LS ol es [return O] 5 [int main] ol gi Hes col) CUS Y gs el pl Ua [void main()] esta) Sr tmauslimengineer.info facebook.com/muslim.engineer.page. SiSijigill poli Aiol 4.{ 9: left brace (main) VW ayan Yay dhs } 0: right brace (main) dope ts Bes eg ead Se Sly eel ll Uy DES [void main()] 4! [int main()] ci Webs Lat A pea ansl dibs oS J ABY{} cea gl Gy main ll dala GAS (jal) ea JS 5. return 0; (Wong eset gl Su Y) abil Glas Sat (cout) output 4\sa!) ji qed Bitte po LE! (cout) Ul ear > cout<< : cual (<<) 344 (cout) a clon > OM Galil Lae Gas aaa gi OI Guy OLS J ae Feld > @ 1: cout <<" welcome to c++"; eal gb gt US welcome to cH Selo: galt pil p gs La @ b2: cout << 5+3; (8) ZAM eos (3) 22 (5) ap Danka as eal es rail > AM) Bae ps Nae ayy pe gh ACH Le gh LT aoe > (small letter)’ to ay = ga Gali pal AUS gt Lead! Cay all cue SiSizigyil - y-sllufll ali em i#tinclude void main() { cout << " muslim engineer"; } cout << "Hi"; Ex: #include int main() { cout << " muslim engineer"; cout << 5; t y \n @ ex: PB glial f error lass ea pd Ie qe dl AS se Rell pl aye Ge muslim engineer ii ada; eli Le return Su d9n5¢ OY 5 il) alas Vy fun eile ds eke glans Y geal 3h 8 error (as gl gall chet 8) > see ghey cout << " Muslim\nEngineer"; Uy Hae pag uae Ugg Ansel Abell Gag | y\ @ex: (\) ae! cout << " Muslim Engineer\\"; +Y Om: cout <<" Muslim Engineer’ (") deta aah etl pi A Saye yall al! a > Musi Engineer BD [ius engineer => ‘Muslim Engineer" muslimengineer.info facebook.com/muslim.engineer.page. SiSizigill palin Ail >\t Filise play Deby ABS AAS JS SUL Gl) cde ol) ALS aut Bayap Ls Yay ool) Abel a3 Ox cout << "Muslim\tEngineer" = Muslim Engineer cout << "1234567\tEngineer"; 1234567 Engineer cout << "1\tEngineer"; 1 Engineer cout << "\t\tHi"; Ales US oh bie! le) (aie A via: beep “p= jue w\e: (Gam Ge Weld Le gat) slaudl Sad Spall eat @ex: cout << "Hello\r"; eee 5s MuslimEngineer cout << "MuslimEngineer"; MOM als) Lae Ja 8S Gf Gey ye pall Reh pal gb Sag0 yall HELM pl I ares end]: 3 ate shu (\n) Migs aid esis pod Se Ex: cout << "Muslim"; = Muslim cout << endl; Engineer cout << "Engineer"; LB Baal gb ye LES Se Oy Oy 3 (cout) TAS Gy Sle pe FeLi WY sgl, > &: cout << "Muslim"; cout << endl; = cout<<"Muslim"<< endi<<"Engineer"; cout << "Engineer"; facebook.com/Smurfs.On=Fhe.Way. SiSipgyll - y-ollufll ala (cin) DEY > Enter le laiwall 5 148 Ria) podteall Ge Gilly Com eat pl ol} ad DS2Y cin pl padi (cout uSe) cin>> ceed (>>) 34 (cin) Ol Foe OS Oy pital Hy pote ilo 8 Oe Job 6 gL (cin) DRI ef ae ew Ay pill Abe pacts ll ae gi Fae ye eal pdb peal pglall Gin xd to aly Gos sll fag cl A9b A10 1Ab : Ease Y stll di iw AB lv AB: @ the cH ey: gh Bj ype UNS Ue Be LI SIO auto, break, case, char, const, continue, default, do, double, else, enum, extern, float, for, goto, if, int, long, register, return, short, signed, sizeof, static, struct, switch, typedef, union, unsigned, void, volatile, while... eet gh pals) Lede Last ob y dy x5 Aaa! dalall dena p> datatype variable name r 1 data type I gl sil os cus Geen Ex: -2,-1, 0, 1, 2..... Geet EX! -2.3, 4.2, 0.200 Ge yo ae da Jou Ex: *, A, E,-, #, Ex: include void main() Baal y Hy od dlagy OH kts AD Cay pat {int x, y, res; ————___» aw ua, cin >> x >>y; (y 9x lpg Daal pastel Ge Ll) JY! ya res=xty; = —__»y 5x ci stall seme gslutres satel) 18 cout << "the summation is "; cout << res; (res jill 48) gd de tmauslimengineer.info facebook.com/muslim.engineer.page. road ena gi linte sae oS Sup Ys Cath ley yx Ata aS DAS Gam ol] A all ogy Enter ¢J DS2Yi clits 3 qtidl Aa) Oe meee A Sh p JE LAS yh 20 5x 810403 we 4) 20 4110 Day Ud y__tes 20 res ysl) i Ai Sy lb Ca ap CU alas gall a sy res res = 10+ 20 =30 30 2 UN Rely; eal pl p shy the summation is30 J = etl te otal passin stall Ags ake g ()) Aple Aeliy 52 pall owe 2 intx, y, res; ;) ah sit int x; Abedie phot j3tU pi Senay int y; int res; (compiler) cb gas 92 sie DS Edy pane ie Ul gle je ye) AD bi apeal) sual) ash 2 gis > & int x; 10 4285 <— (10.6) Last cins>x; int ¢ 53 ex gt OY Ex: double x; 9.5 y5 <— (9,5) Lal cin>> x; 5.0 33 <— (5) Ul (0) ADL we JS ly ei pl ps etd A peed iS Bab oat LI facebook.com/Smurfs.On=Fhe.Way. SiSipgyll - y-ollufll ala Ex: b patel 36 QA Gilles geld pl p dy Ln int a=10; Cob cy Abad aya.) IS, lag pte LAs Sa ahd c pall Li cin>>b,c; (cin>>b>oc; Beall SS I ey Geta ad eal pl Ally GS) nyse Aad pa 1 Ex: a int a=10; 7 100 =a => => cout << a; 100 wieual) Gland) £3 (+) est (-) cael C) sepa ({) Rast (modulus) (%) = 8; hi apace steed lial y audi IS CJS 13h Au os eee oO SU é Ky ple alse! liad) gf asad ye col GIS 1) : (gote + cate) dS sae pele eA 5. 0/3.0=1.667 7% =3 } 1 fs tna ct > 4%7 =4 7 10%5 =0 4 Owais Aad Lose) go LN Ob Alaa Go anal Lascll IS 5 (modulus) 8 By glial YS 1) > tmauslimengineer.info facebook.com/muslim.engineer.page. SiSijigill poli Aiol jlo} Leal) lglg EF Cell ol asl oe () al BON (Y cel A tall oe % cael ol Jule - Geel ol) lal <= Hl al) Shale IS (= uses) (and (Gs Gem) (or (WY Gea) f= Y= yaax? + bx +c yaa*x*x + b*K +c O-o@ kad x>Y is x greater than y? x=y is x greater or equal y? is x less or equal than y? is x equal y? is x not equal y? wu iiaivialy i statement Seal li ca condition b A ols} > 8S Y statement Qleall 8 118 condition 3) Sp (;) 4s sie Aol a9 5s Y (if) Mee gh AR SiSizigyil - .-ollulil ~ & #include void main() {int a,b; cin >> a>>b; /[a=10, b=5 if (a>b) =5 9 a=10 cout <<"a is greater than b”; ode Sah pdt! gli yo A le) } (qt al Sa ae el if(10>5) > cae > sda Bam | aisgreater thand eeigh Yet Bub L wus » y & #tinclude int main() {int x,y; cout <<"Enter two integers\n"; cin >> x >>y; //x=3, y=7 7 { cout < se oily oe 584 (char) MI pas x Ay =| | cout << x; a jal dal Lg =E] cout << x< The if selection structure: ~ Ex: #include void main() {int grade; cin >> grade; if (grade >=60) else cout <<"failed"; t if (condition) statement 1 else statement 2 statement 13448 cave b yl ISI > statement 2 this statement 2 44 4d cae bl IS yp statement 1 getlis facebook.com/Smurfs.On=Fhe.Way. SiSizigyil - y-sllufll ali AaB baal j Ue: (ifelse) Ue US ig Si pk Se > cout << (grade>=60 ? "passd" : "failed"); (condition) {if} (st1) (else) (st2) Ex: if (grade >=60) tee opp y Gully GY ed SL cout <<"passed\n"; if Ups tet s2else cout <<"Good\n"; fq else cout <<"failed\n"; 2 fd al ce calealh ay pall Ex: int grade =60; if (grade >=60) {cout <<"passed\n"; cout <<"Good\n"; } =) passed Good else cout <<"failed\n"; if (grade >=60) else coils if I tlap 24: Le pill Us {cout <<"passed\n"; cout <<"Good\n"; Passed } = Good else cout <<"failed\n"; cout <<"bad\n"; } qe ot Lal OS gl ob SY Laie ly LL 6S etc (bad), (failed) if 8 tl le ps5 Juss any ide SLI cif 4) dle Gals Gam [rassea Good iS muslimengineer.info facebook.com/muslim.engineer.page. SiSizighl palin Airl > Nested if/else structure: raked deal - alas > if (condition 1) CB cee if esr (condition 1) JS 19 (9 statement 1 — if (grade >=90) Good luck cout <<"A"; else if (grade >=80) //grade = 80 : Sen > Good luck else cout <<"C"; Merade=50 = cout <<"\nGood luck" tai = Good luck (eee o PAakal) 3all Akal 3g Akal 43a if (condition 1) if (condition) if (condition 1) statement 1 statement 1 statement 1 if (condition 2) else else if (condition 2) statement 2 statement 2 statement 2 else statement 3 all cdal cdal BphdSphdd wy (jf) LL aoly bby Lyd Gy se sphasyhs d ay aids iy. (else)} co cA A cee SY) al ce et ast .loop facebook.com/Smurfs.On=Fhe.Way. SiSizigyil - y-sllufll ali > The switch Multiple selection structure: og sheall (case) ti ge ed pl Gog ate J cul ase sat od (switch) de > Ledalad (switch) $ Set LID case di cm si G8 switch (10) 8S ds > a- case 12 c-case5 d-case7 Y Lily (switch) | 42s (case) ayny Ld cee soy (cH) dee gh > :(switch) 1 43 Ls (case) a> 5 13) -1 eth (case) 3 (break) o> 5 3) T (case) 41 ay M3) (case) ti ctl ats (case) 3 (break) aay ¢ 15 435s Ge Bl yaa (default) 4 3 <(switch) Jase (case) = 6 WY -2 > & include int main() {int x; cout<<"enter an integer:\n"; cin>>x; Mf x=2) ————_> (2) gst (x) 48 JS switch (x) 22s) switch I oR {case 1: ——> (+) cath! passa) dt a Aba (switch2) 1 aes LY (case 2)-li ye Cady gal yl a ie faa "Kis2"5 Las 5 (case 2) i 5355 yall Leall Sa: eali pl a he break; (cout) dell ys} default: (break) Lai styl 5 cout<<"value of x unknown"; } ———_— switch te return 0 ; i Shag gill (}) say Deal Ss eal pd Gay Cues switch dbep clei! :(break) 4b) > switch Ji Ags (case) a+ (switch) Stbi pic se Sty Gy LAS! (default) Mee enter an integer: 2 xis2 muslimengineer.info facebook.com/muslim.engineer.page. SiSizigill palin Ail errr cswitch Meal GL a switch (variable) { case expression 1: statement 1; case expression 2: statement 2; default: statement ; } (}) (default) tI a; ts SUSE case toe Sat el ll he (break) SAH > &: switch (10) (case) Ub tes gy Jl 3g se = 10 {ost aged gels Y cout <<" Mechanical Team" << endl; cout << " Muslim Engineer " << break; Mechanical Team } Muslim Engineer Ex: switch (10) (break) 255 2» lls Muslim Engineer oa: ¥ {case 10 : cout <<" Mechanical Team"; break; pasnelt cout <<" Muslim Engineer "; = fae i Ex: switch (10) {case 10 : cout <<" xis 1" << endl; case 2 cout << "xis 2" << endl; default : cout <<" xis unknown " << endl; } (break) 2525 ae Gay deal) JS a5 Ls xist xis2 x is unknown, facebook.com/Smurfs.On=Fhe.Way. SiSipgyll - y-ollufll ala (case) I 238 (break) 25>5 CS aly ei US! gb ase 50 GLb (case) JUS > (switch) Al gals: oles) Soe gl eal oe break -1 ell le A case -2 wy & Hinclude void main() {int x, y; cin>> x >> y; /[x=5 y=5 switch (xty) —* switch 10 cust {case 10: cout << "value is 10" ; break; case 3: cout << "value is 3" ; break; cava 10 value is 10 cout << "value is 100 " ; break; aes } cout <<"\n"; cout << x+y; } Ex: include void main() { char (x): — inty, 2; ——> bee difaod cout << "Enter an operator"; cin >> x; Ifx=+ AND cd gtd J cout << "\nEnter two integers"; cin< Logical Operators Abia) coulea Ua pas ON Aa tall bead LEY Cotbed obs Gary Ge CH UI Gf lila Lat ~ Pig ll Dealt A Geesstecly Jeni yy & i#include gh pb dleg (3 ls ye Led void main() Bist axe 5 gst J pSl x Ang cas inte gh pl eal 45 True b ya fi bless) ney ate 5 coe lx Lad US 15) LA cout << "hello"; eae P es else Ales 3825 False (hls L 52) cout << "welcome"; } viol gh gia aS IS IY} pane Lats Gy if lag Jab se gh Bde Ex: if (45) cout << "hello"; bed = cout << "welcome"; Boe pads (CH) dane y deme coll (90< x < 100 Sh) AS pall Ls ball ee dugetl > rel 1 && (and). 2- || (or). 3-! (not). and 90< x <100 ———+ x >90 && x <=100 Sisto iil - yy glleufll alaiil AD See SS G8 Gal oS ey le ELL ods ee igh ee Oy > 1) && (and): - cae Cull oS; Slane Goh pil US le 3 LS eee eee} LL (or) :=qenee SA Os Gee by Ah ce sh IS 1 Condition A feted False 3) E (not) : 4a p8l) Sas 9 sft True > Ex:- int x; cin>>x; — //x=80 mes if (X >=80 && x<=90) if (80>=80 && 80<=90) cout<<" A”; (True) (True) else if (Ture && True) cout << “B”; if True spe Goce (True) 9 (If) Hh dats (i Se Gosia > A (else) I dap Sales tmauslimengineer.info facebook.com/muslim.engineer.page. if (X>=80 || X<=90) ———————+ jf (g0>=80 | |80<=90) cout<< “A”; (True) (True) if (Ture | | True) if True else cout << “B” o Ex: Grad =60 ; a >=50) — if (!(60 >=50) z if ( (Ture) cout << “Failed” ; if (false) a { oo Ales Guy else =f] cout <<" Passed” ; > Notes: - & cout << True ; = deotsctase; Sp EE] > Ex:- cout<< (171| 0); (T) (F) > (TIF) > (7) | facebook.com/Smurfs.On=Fhe.Way. SiSipgyll - y-ollufll ala ys cout << (10 && 0) (tT) (F) (T&&F) > (F) > cout< &:- “{ If (X=4) LAY (if ) Hae Sy Latta Le coats (capsthe) Le tae coutte” B* false} y8) joy Ail od pall ce cual True bi) jy atl gd jie ple Y AD gl OS IL y Ex:- intx= 5; a if (x=! 6) Xel6 cout <<” yes” ; >X=0 “{ else If(0) (False) cout<< “No” ; int x= 5 ; if (& = 6) cout<<“ yes” ; X1e6 (5#6) > (True) If (True) else cout<<“ No” ; .Touslimengineer.info facebook.com/muslim.engineer.page. SiSizigill palin Ail > Increment and Decrement operates : - aly ie Lead gh ak i (+4X) or (X++4) (--X) or (K--) ++x: pre increment = increment (x) by (1), then use the new value Baal) Lagll pasado 1 bey atl jlo td) JS 8 LEY) gS Le > X++: post increment = use the current value then add (1) 11 Nae 4) apy (3 yl pay Wate yet a LEY GS Lave LI ~ Ex:- # include < iostream.h> {int main () int c=5 ; cout << c< 22243 D 2-443 2=7 cout <<2< Good else cout<< “ Bad” ; = BS Gy all He Si Byte Gy all OS (cH) Lee eo AW AB CS ie SY SZ 6 AS DECK ae SKS YSZ ISM The while Repetition structure : - =: (While) Mg! GL) Sapa} Initialization value While (condition) Statement (s) Increment /decrement condition > Ex:- int product =2 ; while ( product < = 1000) Product =2 * product ; —- cout < Initialization (. Condition (¥ Increment /decrement condition (* FA (while) gl ee sh els ne cS SY (While) e+ 25a) Lt Gant 3p (While) ol Aes Sg) Subai une I jle 1B aus 981 836 (while) @« btll ponds Awhile) gli Aap 538 ll Gans cols Le Bl) eae cis NSa yg sl tmauslimengineer.info facebook.com/muslim.engineer.page. SiSizigill palin Ail = 2 Gall DN que g product (initialization) (2) +3 44 U34.5 product 4a) 3% Lie (1 (2<=1000) (while) a+ 25> sal! pill aad (1 (increment) iss (While) is Mee Ssh Gobi Gane b A gf Le (F Product (new)}= product(old) * 2 Product =2* 2=4 (4<=1000) : 425855 (While) @« 25> 5) pS) ols 8h be ao (# gee kd product=2*4=8 2 while sb tL Js) Ss (¢ ceeeey be yl! lead (1024) col} (product) i 28 cd ois NSay (1 deta al oo 5 (while) Uae 3) deal gl) Gadd GbLL Sug 5/5655 a: pall Gl) G0 (product) dd Al del lly Zell! pl (1 Neral - abd > GIS (condition) tI cea os 5 (loop) i Gi(1 A} cae deal! gai (loop) J oth Ate on 81 385 bs i 1 (2 Ex: ~ product =2 ; Product while (product <=2) ae 4 {cout<< product << endl ; pave bo 3 Lah Sey product =2*product ;} cout << product; —__, =, kis b ya Ub Sy = lotes: - 1) while (0) (false): —> 2) while (any number) (True): ——» sl Bz}: Le (condition) I 93% of Gay (while) 2 3) deal! 8 385 3 Uo S158) 8» (condition) i Gast o> yi Laie al Go Gla facebook.com/Smurfs.On=Fhe.Way. Sisto iil - yy glleufll alaiil > Ee include void main () {int total, GradeCounter, grade, average; Total =0; GradeCounter =1 ; while (GradeCounter <= 10) Enter grade : 98 {cout<< “enter grade: “ ; Enter grade : 71 tetrad =» |' total =total +grade ; “ GradeCounter +=1;} Class average : 81 Average =total /10 ; cout<<" class average is” < (bls el Sby ae uz (statement(s)) i dlp Sat ys ol gBY! abd eae (condition) I ys 1 (Y 38/8 (condition) 3) Vase: 2 (increment/decrement) 3 (loop - ve <4) (increment /decrement) 2!) a>: Y GELS (condition ) I YS 1 (é sak _——, for (initialization ; condition ; increment/decrement) Statement; (2 )a— es yr # include int main () { for (int counter =1 ; counter <=10 ; counter ++) cout << counter <<\n; NLS gles pl 1S” (1) Uh 48 ghel (counter) skid Gy py BS (4 "(eG y: BE Y) (error) Hy v (1<=10) «<—-_ (counter <=10) & 4) Yast (2 (1) gg sta gill (counter) tt isis Xela oy Aa Ubll dhe 4s (3 aaly ide counter 38%) ke 815 945 countert++ <«— (increment) 3 ae (4 (2) gs+e counter I c-_t 7 Se 5 Sclbll Ae S85 ¥(2<=10) Si 8b pi) Gand (5 ety (1 0) Ll) yon (10) ester (counter ) I jiaiall gl) Jui Lie (6 (11) eed ( counter ) ) le wits fi (return 0; ) Ay Hela Hap oz pth Adel Sao Lt (11<=10) 2 5) yaa (7 weal old facebook.com/Smurfs.On=Fhe.Way. SiSipgyll - y-ollufll ala { foe deal Qs qnee yi y S Leste dhe ye JS) Sah Uy > Ex:- # include < iostream .h> ean ‘vend asain Sum=sum+ number {int sum =0; sum=0+2=2 for (int number =2 ; number <= 100; number +=2) 4<= 100 sum+snumber ; Sum= sum + number cael cout <<“ sum is :” << sum ; } Sum= sum + number Sum=6+6=12 sum number z sf Sr => 102 Note : - Ag hits GNA Seal abe, 1) for (int j=2 ;}< =80;j 2) int j=2; forlj; j<=80 ;j+=5) 3) int js for (j=2 3] <= 80; j=} > Ex:- for (char cout << x<< endl; tmauslimengineer.info facebook.com/muslim.engineer.page. The (do — while ) structure : - Do{ Statement (s) } While (condition); - dike Dy (do -while ) ss. 5 (while ) Les oa Gall (1 eal a8 FY L 8 end (While) dhe gb ok Japill Gasit i_Ygi Seal! 58 (do -while) se 35 ak (error) =z ¥!_ 3 while (condition ) 23 (;) 4s site Hold aay Gany (¥ y Eee i include int main () {int count = 1; oe (te cout << counter<<“ “; } cet BB IS NY enue while (+4 counter <= 10) ; cout < Beatie phn) 11<=10 & x iz x x a 1 facebook.com/Smurfs.On=Fhe.Way. SiSipgyll - y-ollufll ala ~ Ex:- include void main () {int counter =10 ; Do{ cout << counter << “\t” ; = 1 } while (++ counter < =10 ) ; welcome cout << endl ; cout <<”welcome” ;} A Weg Sanh y Spo Alea) ad eli) of YI Sad ke bls GIS bl of ce pe Ml ey (do -while) les See QsLul [5 The break instruction : - » & # include int main () {int n; for (n =10 ;n>0;n-) {cout < Ex:- #include void main() {for (int n=10 ; n>0;n—-—) { if (n==5) 1 Continue => cout << n<< “,";} } (loop gi S25. sall desl JS) Loan: das get -:(continue) ¥ (while do -while ) } continue to condition (for) > continue to increment /decrement ost (if) Hee Gee aye ye AY nen (if) bd Oy Lee 84 (continue) Gh JAI > geo US Weltal tl Leal (loop) A gb oss Gl deal) (Shes}) cba couts Ex:- int x =0; while (x!=5) feet; Continue ; cout< exit loo facebook.com/Smurfs.On=Fhe.Way. Sisto iil - yy glleufll alaiil £5 Chapter (3): - Arrays (até sinaal!) =: Bed LN Gel) Data type Array name [size] ; Data type: (int, float , double ,char ,....... > Ex:- int A [10]; (integer) ¢#!c (A) 2834) 68 ely (10) Jan sipdie0 123456789 A= [3 ]2]3]4]5]6]7|8]9]10 (Size -1) + setizy Aral Ce Lila fay gd Deal Bye hy gh gieeall pul paths Beal) palie Ge pole yond y AlO] <——— Broa ds) pot) yod > De AI] Al2] cout << A[O] ; size => Wiad) 2a U5 jAdi Yio > dk (5) Naka pineal od] (puolie) i las) qeetie LG (5) op ay 4H endl (size) GIS HE - «ISI J jolie (6) DEY ja Ys Bi) pote =) OSE pb chs doodlh Jats jolie JY [(0)=(size-1)] (.for)<—(loop) esi () [, Loted gga hasty (¥ -Tuslimengineer.info facebook.com/muslim.engineer.page. @ &: ifinclude void main () {inti, N[10}; = for (i=0 ; i<10 ; i++) tooo{ wince, cout << “Element “ <<"\t” <<"value” << endl; for(i=0 ; i< 10 ; i++) Loo { couteccice “\t’<< N[i] < 1x10 ¥ N(1]=0. ————> 2<10 v N[2]=0 (0) JS N(O] ais A os (0) Ja Nf] Sob Bos 910 N[9]=0 to<10 & All (Loop) fazs n[10] Badedi pole del) 218i (for) dp Leet (7 (size-1) <—— (9) facebook.com/Smurfs.On=Fhe.Way. SiSizigyil - y-sllufll ali @ &- #include void main () {int n [10] =(32, 27 , 64,18 ,95, 14, 90, 70, 60, 37}; Goad ssl ib coute< “Element “<<”\t” << “value” << endl ; Ba ginenall JAI putin } Fi geal LL! (for) tee for ( int i=0 ; i< 10 ; i++) coute< ic<”\t” << nf] << endl ;} = > Notes :- 2) int [10] ={0}; he 58 al gall gee 0 1 a al 4 0 i} 0 oO 0 2) int n[5] ={32,27,64,18,95,14}; size < Uji pole 2x OY (error) gly 5< 6 3) int n[5] ={32 ,27 , 64, 18}; 3 4 18 0 size > jaa) poll xe he Jil) pee Sho + — 5 > 4 muslimengineer.info facebook.com/muslim.engineer.page. SiSijigill poli Aiol 4) int n [5] =(1}; ie JS) GAS Sip ASU (1) Jd By do Bos 0 1 2 3 4 1 [fo fo [is 5) intn[ ]= (1,2,3,4,5} (errorusd) (g-) <—— (size) Jerdoud i » size =5 25d pottall are Un, La) poliell axe UMS ye (size) I ast galt pl ads © Constant variable : - @ &:- # include int main () {const int x=7; cou cased —| return 0; oh Wy Hpbi ag athe} Gey (constant) plasty jhe je WY - 7 Aad «ead git Seer Vy (error) HU > @ &:- Const int x=5 ; Error xe; } (x) cout < void main () {const int arraysize =10 ; int], s [arraysize] ; for (j=0 ;] void main() { Const int arraysize=10; int n [arraysize] =[3,7,9,5,4,11,8,6,13,1]; cout<< “Element “<<"\t” <<" value” <<"\t"<<”shape” < (19) JS) 92 os (20) ge Badia > (error) ei al phe: Gps y= (21) 3} (20) Ulssi st - EAB Bll Se (\0) ce dS pss Lay (error) les YG (17) 31 (18) WEST 3) - @ &:- Char x [5] ="str"; @ &x:- include void main () { char string! [20] ,string2 [] =” Mechanical Team “; cout << “Enter a string:"; cin >> string1; //Muslim Engineer cout<< “string! is :“ << string 1<< “\n string 2 is : “ ; << string 2<<”\n”; for (int i=0 ; string1 [i] != “\0‘; i++) cout << string! [i] <<‘ ‘; Enter a string: Muslim Engineer cout < String] is : Muslim String2 is : Mechanical Team Muslim Engineer cin >> string1 ; } LAS gl uy cout<. 5245) Lary (Muslim Engineer) (Muslim) Sit Abid (Muslim) deeb » si: (string) 48 sued dels sie (7 ALIS (Mechanical Tear) dels gs: (string2) iad delsb oe (£ (space )-i 5 (Muslim Engineer ) 4S 43 25> 54! (space) I oe GA dia Abad i Gass) Gass (Muslim Engineer) 2a i «(Mechanical Team) 44S (3 sas 3,he (space) -} Usd (Mechanical Team) 2a 3 Li JAY) 2433 i! (space) Ue (cin) ays (15) Ge 8 Le (Mechanical Team) 4S 3 Hig yall ase S Sls BL ee 441 dis (Tab, Enter, Space ) cal 8 (cin) 9) plata! we 4) fils La pt Aba (@agall) ZalSl ods Zeb Lis J 1) OSs (space) sy Stith Luis) Gaal ald yl pds y LAS} cin>> string 1; cout << string]; pote ledy ym JSS patel ye lb Ye gl OL (cin) LE pl lest Ge ge « Upelaley 8 yt 250) ale ele sad I Multiple subscripted Array (Matrix) : ~ Array (Goal!) spall name row Column @ Ex: AL3]I4]; CO GR eae A[O][0] | ALO}{4] | ALO][2] | AfO][3] AlAI{0] | AL2I4] | AL2{2] | AT1I131 Al2]{0] | Al2}{4] | A(2)12) | A2I13] Sisto iil - yy glleufll alaiil @ & int b[2][2] ; co ca pioltol [bio] ] = = aAat ba} fo) [bfayfay | 2= FeV we Cout< EF sSSalyS pile Ha gh (9 (for) laste (¥ @ &x:- int b [2] [2] = {{2,2}, 13,41}; cout << b[0][ (matin) ged he Has a on hy Lyall ely JM) Hy yl itl Ml os at co c1 1 2 >> biol 3 4 int b [2] (2) = {{4) , {3,43}; co b 0 a ke a (SLY fy 3 {jie pd (matrix) Ex: int array [2] [3] = {1,2,3,4,5}; coc rof1|2 Aa’ Gs) BV plastid go Le afa|[s Ex:( int b[2][3] ; for (int i=O j <2 ;it+) ——* (0-1) 4H! (For) tb dap plsaiy for ( int j=0 ; j<3 ;j ++) ——» (0-2) s=%) cin >> BUDE] (size-1) cell pial Ce {8 (for) di ayse Losey .Touslimengineer.info facebook.com/muslim.engineer.page. SiSizigill palin Ail 3 Chapter (4) : Function (function gigi > (use defined function) Aig ay padtuall a dg 95 (1 (Built-in function): (Jats) eb ae B38 (1 § Built-in function: math function teal!) cs Sy} = 1 Ug Leolalt ABSA) Lay jet Cee (math function) plsiul dS > # include =: (int) vats (double variable) a= det Gol etsy > Let x: double Same of Math Function : - 1) ceil (x): Tete te OSI col} sad) cout<< ceil (9.2) ——> 10.0 2) Floor (x): Gewese heal gl) sal cout<< floor (9.2) ———> 9.0 cout<< floor (-9.8) ———> -10.0 3) Cos (x): Ut cour e 4 6) Pow(x,y) : X” cout << pow (2,4) ——> 16.0 (2*= 16) 7) Sqrt (x): Vx cout << sqrt (9.0) ——> 30 facebook.com/Smurfs.On=Fhe.Way. SiSipgyll - y-ollufll ala 8) Fmod (x,y) (y) cle (x) Aad By hs cout << f mod (13.657 ,2.333) ——> 1.992 5 2.333 | 13, 657 11.665 1.992 @ &:- cout<< pow (2,, sqrt (9.0)) Pow(2,3) (2° =8) Use Defined Function :- eA A. gillne eih yy peal a ms ch STL CLI SS Al tad gy We esl gf Vasily oH tele ty telat ppabe Bige pastel) JS ytd pedi CLI SY gat ol w 1) Function prototype 2) Function call 3) Function definition Se ce etd Go (function) 255 (compiler) -I| G24 - : (function prototype) i385 - Ae sista (function eu) (function) i slesiai oISs- : (function call) 4 [function-l! te: si 2) 48 si] (function ) i G23: (function definition) 485 - @ Ex:- #finclude int square (int); > 1) function protype int main () {int x; cin>> x; cout < 2) function call return 0; } int square (int y)~) ———*® dhe ogy Ls { return y*y ; ——— 3) function Definition muslimengineer.info facebook.com/muslim.engineer.page. SiSizigill palin Ail Wil plac | y alae Nh cena gi ob este le OI SY! el jal oe ojo US nat OD pg - Eby ek te sie (function prototype) os - return value type function name (parameters); (double ,int, void , float ) (main) coll dea) Lali ¢ 53 ase (return value type) ps > ‘Ganall se) integer dea! ji Ledll ¢ 3 int > Oh Gaeall ye ve Leal jl aallg § <—— double stelisasY <— void Amain) JI 3 cocky Ge gill G89) aul 5 (functionname) ¥ (function Defibition) 3! Uji Aaa) gs 35% sk (parameter) % Aqgesall 22) integer Abe pldealle 9 int: be Tell oe ve Hs plete 53 float Ala yo dadoesi Y void (;) Us site Lol 252.5 54 (Function Defintion) ce (function prototype) I) jus) > @ &:- 1) int square (int) ; Ainteger) & 33 + Aa8 Dit 5 Ja up sis (square) aul SSI Ge Ble 2) int square (void); = int square ( ); Ad gl due Ys (integer) ¢ 8 Os Led DEL ¢ sh (square) dau! OSI ce 8 3) void square (int) ; Ad gl Jake Y, (integer) ¢ 93 G+ Led Dla h sis (square) duu! O18 Ce 3 le 4) void square (void); «Ld gl Dial Y5 he be pds Y (square) dau! oI Bl Ge Ble facebook.com/Smurfs.On=Fhe.Way. Sisto iil - yy glleufll alaiil ~~ Function cell: parameter cl} Alot; dau! 32h Ce (function) i cle stal » gi Square (x) OLS el parameter -) thee p> rAaal Log ae. Y 4 le (function prototype) a pi Laie (1 void square (int); 52085 (cout) etal psi plait (function) AI cle sish jyey Y Lali obs (ib square (x) css) ojlesial Js Lai ap 5: Y 4) le (function prototype) -I a ai Laxie (¥ int square (void) ; cout << square( ); —:(function) 4! 54 (parameter) 252 Y lal ois i - dalla» JS GI! (function prototype) JIS Gs ett 3 (function) 29%5 c+ SEL » 98 (1 int main ; 2(function call) cel! Saoi o co!} Abell cut phstty galt pd da fas (2 cout<< square (x) ; cout<< square (10) ; function ) is! sks 5 (10) (parameter) > function definition inty =10 cee go} (return) ce) den! Lasts 5 43 82 yo pall unl! 425, (function definition) aa US (€ (main) 41 4 (function) i ete us) Jas 3! (return ? Bysleall dag return y*y; Lal Jad 3 - Y*y =10 *10 =100 >>> return Go); (return) 15 sLaal deal jt Leal Abe Ye ets (main) J 94 (function) i gab i gi - «@ (return) +> 5:24 (void square (int) +3 e> 2 ¥ (function) I ols 3) -: Mead y (function definition} tmauslimengineer.info facebook.com/muslim.engineer.page. SiSizigill palin Ail @ &: #include int square (int) ; ————>_ (int) 8 ce Uy da yas DB void main ( ) {for (int x=1 ; x<= 10 ; x++) coute<'square (x) <<" "; 149 16 25 36 49 64 81 100 coute< endl; } int square (int x) {return x*x ; } localin main. = ——® — (main) i 8 yeas (x) pete = A local in function ——+ (function) i 28 Gaal (x) jaiall ge Gilisy Er:~ #include (int) € 5! Ge G43 (main c+ Jai: - int addition (int ,int );_ t————> = «(prototype) 4) 4a 3 int ase5 - void main() Adel (return) 295 { cout<< addition (5,3); t int addition (int a, int b) { int x; => Xeatb; ES return x ;} .(function prototype) 4 (parameter) I 3 pee 255) (1 int x ( double, float , char) ; cout< int square (itty) ———> ; Age bay Function { definition) return y*y; } int main () Us Ge dali La { cout< t inty=5 v 5.5 “nh, aa int y= =) ag fh Aa Gay (vr Function prototype ———> int add (int, int); Function call ——> _ couts< add (x,y) Function definition > _ int add (int a, int b) Bi int add (int a,b) is Error. -: (function definition) I 3 (¢ ae square (int y) 2) void square (int y) { 2 : sel 35 (error) ual return; ——> return yy pe Gan } fash Ud Aad LES Gy she ce Gf BY ole sta 2 (yoid) GIB CIS (2 AOU JBY! cleat! ig 8) @ &:- void x (int y) { cout<< “school” << endl; } void main ( ){ (error) cout< int maximum (int ,int int) ; void main ( ) {inta,b,c; cout << “enter three integers “; cin>> a>> b>>c ; //a=22,, b =85, c=18 cout <<“ maximum is :” << maximum (a,b,c); } int maximum (int a, int b, int c) {int max =a; if (b >max ) Enter three integer max =b ; 22 8 18 if(c> max) = Maximum is : 85 max =c ; return max ; } % Function prototype: Aus (; Asie Mold eee 5 coms) 1) Name of function. 2) Type of data returned by the function. 3) The number of parameter. 4) The type of parameter and the order in which there parameter are expected . Note : - Defining a function parameter again as a local variable in the function is a syntax error . @e void max (int x, int y, int z ) aust jae YY (error) (local) facebook.com/Smurfs.On=Fhe.Way. Sisto iil - yy glleufll alaiil Ed Header files : 1) ifinclude 2) dfinclude 3) include = —» :random [0-32767] @ &:- # include include void main ( ) intl; tsrand (); = cout < void oddeven (void); int main () {intx; ciN>>x 5 Oddeven ( ); return 0; } void oddeven (void) { intx; preted! Asay Gy aed qld yp cin>>x ; rss pa dS IY if (x % 2 ==0) cout <<"even “; else cout << “odd “; } tmauslimengineer.info facebook.com/muslim.engineer.page. SiSizigill palin Ail Ei Scope Rule : qed dak { } ale tee pil ees ce le cut yy New scopel Functi call @ &:- include void a (void) ; void b (void) ; void c (void) ; void d (void) ; intx=1; ———> (global variable) <= (int main) J3 jd) Gap? p> int main ( ) \(funetiom + main) xl JS ade a yy int x =5 ; ee —> (5) AM vats (global) 4 (local) 2954 {int x =7; ) Lasts} tel (local) oS cout < a() ;25 26 ® b();50 51 c(j;1 10 a();25 26 b();54 52 c();10 100 d() ;100 cout << x< (5) void a (void ) {int x =25; ——> Local in function cout < 25 4x —> 26) Wet cout << x<< endl} ——> (26) void b (void) {Static int x =50; ——> Local in function cout< 60 ion 44K; —> 6 Wet cout << x;} — @ void c (void) . {cout< (J) Global (x=1) X*=10; ——> (10) gs (x) ei cout (49) void d (void ) ze {cout< 1 Lng Beli ( [Fs PexIE ear ee Poss nrery cows pec ucen Bue Ge JS) Llosa ale Lp Ui jae LS pal Cle alas (Static) 3 (Global) ( Global < Local < new scope: 3A: cys!) (7 void a (void) ; ( aa (function definition) 4 Sats dala (functiom) -I ele-siul ate (return) +3 ¥ (parameter) +>: ¥ (main) 3 a(y); No parameter a eearoo Long int —————> 2147483647 Unsigned long int > (04294967294) = Unsigned long int = unsigned long gg hss 8 jill Jy eal sae gl cis paee daa Long int num ; eae huss Bay oes cin >>num ; int fact =1 ; for (int counter =num ; counter > = 1 ; counter-- ) Fact* = counter ; ~: (Recursion) 4} Use 8 & AN=4*3! 4*6=24 3*2! 3*2=6 baru 2152 10! 4421 O!=1 ————> (base case) 2 tmauslimengineer.info facebook.com/muslim.engineer.page. SiSizigill palin Ail @ &: #include Unsigned long int function (unsigned long int ) ; int main ( ) {for (int i=0 ; i<=20 ; i++) cout<< i<. (recursion)! 3 () ~ 1! 38x (Function)H! ele sit «3 (recursion) A (7 (main) 3 3 (a facebook.com/Smurfs.On=Fhe.Way. Sisto iil - yy glleufll alaiil Reference and reference parameter: 285 USN pata pt Le oles» Ot ce he (eo vli(reference)) > cee Sl, Lai pth 3) (§) : & 88 (reference > §Y=X : de Y is reference to x Ex:- #include void main ( ) {intx =3 , §y =x; cout<< x< cout<< x<< y; i Sb Cashatia (x) 9 (Y) S48 ob (x) Jeo (¥) ci te (1 ‘Laas 9) 3% ge yatall gaa} pao ae (¥ FBS LS (Qo. oa) died ja hes oh ay (F (3) Wie Rass AB eel iy (x) 99 Uitedl jadi Gilad JEU gd E25 odio (y) Cel 9 (x) eal tal C98 I aes (€ 18a 5 (int) & 54 Gs (y) Gs Ol ee (int) & 93 (x) AS 13) Ex include void main () { intx=3,§y; ——————> Error (Reference variable cout< int SquareByValue (int); void SquareByReference (int§); void main ( ) {intx=2,2=4; cout<< x<< SquareByValue (x) ; cout< _ square by value (2); (function definition) int square by value (int a) int a=2 @ finan - rnin @ returna*=a > a=a*ta > a=2*2=4 (x) 448 HG Y (a) Ue le 5p gl a (2) a (x) 2 081 (4) 3h (a) cael [27] 4 (function call ) square by reference (2) square by reference (4); (function definition) int square by reference (int §cref) int §cre cref a _ . Function (2) 448 3s Ge (cref) 448 le st gl (Al | (2) Return cref*=cref > cref=cref*cref D cref=4*4=16 @) (16) (2) 4as8 Cnsual Lila s (16) (cref) 448 Cruel .mouslimengineer.info facebook.com/muslim.engineer.page. SiSijigill poli Aiol 3 Static array: 18 Ul (static) Uap cf Leaks y Boece IS Ups se a dete rent @ &- #include void staticArray1(void); void Autoarray2 (void); void main ( ) {StaticArrayl( ); AutoArray2(_); StaticArray1( ); AutoArray2( ); } void staticArray1(void) {static int array 1[3]; for (inti=0 ; i<3 ; i++) cout<< array [i]<< for (i=0 ; i<3; i++) cout<<(array [i]+=5)<<” t void AutoArray2(void) {int |; array2[3]={1,2,3}; for (i=0 ; i<3;i++) cout< facebook.com/Smurfs.On=Fhe.Way. Sisto iil - yy glleufll alaiil 2 Aa ye) hy gine doles 1591 (for) dhe pati > jclbi ei ———» 0 0 0 Wgaedl pole Ge pate KS cle (5) Ji Sh 420) (for) Abe pty teeth, Athi ti ———> 0 0 0 AutoArray2(_): (function) 4 cleats; Udy (main ol) eas - (3) Weepary Mb dios Ub: p23 a9 5 (function definition) .l} 4 Oct Array2 [1 | 2 | 3_ = ed) Chests delay 191 (for) the eat delhi gti ———> 123 w) Weel geal 28 janie US gle (5) Jail Sal 5, A508 (for) dhe ody felbl i ——_» 678 static Array ( ) : (function)-i clestsl; Lads (main) ol! aes - Kinae 25 joel Zeal, 4 oall la Lay é 0 1 2 5 5 5 Array 1 i) 1 2 Array 10 10 10 Auto Array2( ) (function) -\ clesual; Uiais (main) ll aa! - et gS hy et LYN yo Aja Bll Gye BB gel 0 Array2[_1 0 Array2[_6 tmauslimengineer.info facebook.com/muslim.engineer.page. SiSizigill palin Ail @ &:- #include int main ( ) {cons tint array 1[3] =(10,20,30}; Array1[0]+=10; Array1[1]*= Array! [2 for (int i=0 ; i<3;i++) cout< void modifyArray (int [] ,int ); void modifyElement (int); void main () { cons tint arraysize =5; inti, a [arraysize}={0,1,2,3,4}; for (i=0 ; i (a) endl ce Qt pet Selb Modify Element (a[3]);}_ .——+Call by value void modifyarray (int bl J, int size) { for (int j=0; j call byreference <——— td modify Element (a[3]) st pale + Ha pied) aul clesiulaie call by value =<——— dd &3 Pointers: Pointers contains address of variable that has specific value int *prt ; Prt is a pointer to integer value. @ ex: int int *prt =§x ; (x) ole int y=5; int ** =8y; (x) ELEY DE oe pe Ce Ble Ai Exz- #include (5) Jd 43 O55 (y) 2 Geet dL) (y ptr) 25h Gap Sy (yptr) 25 (y) Bll ols oe void main () {inty=5; int *yptr ; Y ptr=Sy; y ey plese 0x006 tmauslimengineer.info facebook.com/muslim.engineer.page. 1) couts< y; 2) cout<<*yptr; 3) cout< void main( ) Any address {int a; int *ptr; => Any address Aa7; 7 Ptr=§a; —— (ptr) (a) als Gust > (a) ye teh ——> (a) Use teh cout<<*ptr; ——> oJ SY) eye del cout<<§a; cout coutcexc<” “eyccendl; coutc<*pe<”“=b) max=a; else max =b; =D max = (a>=b) a:b; MEng.Samer A. Hamed Page 1 of 3 facebook.com/Smurfs.OmThe.Wz SiSiptapll - .-ollufll alpijil Exmple 2 #include void main () { int a,b,max; cin >> a>>b; cout<=b)|(a<6) ? a:b; cout << max << endl; fh rere er Switch structure Y General syntax of the switch statement is : ‘Switch ( expression ) a Case value 1: Statement 1 Break; Case value 2: statement 2 break; default : statements 3 MEng.Samer A. Hamed Page 2 of 3 muslimengineer.info facebook.com/muslim.engineer-page. Switch case analysis : 1. test the expression, if the value for case 1 , then apply statement I ....break. 2. if the test of the expression for case 1 is false , go to test case 2 .. 3. if there is no case is true , then the compiler will execute the default case ... example 1 #include void main Q char { ‘ Renin ens OS tags A Rockear switch (t) 0K Bee 1 yah cout<<"jan"< ere x always = Bie —> error Kexes => error CHDK > error ea pee ean ay) explicit data Cour & 10 /i( double)X 3 3 bo ‘ devble (x) Aversion, MEng.Samer A. Hamed Page 3 of 3 facebook.com/Smurfs.OmThe.Wa} SiSisigtil - olla aLailill What is the outpt #include void main() cout void main() tb=8. b=((a/4 || a>S)?-at+a), cout << b < void main() t int a int b-8, b=((al=5 || a>5)?-a:++a); cout void main () { intt; cin >>t; switch (t) { case 1: cout<<"jan"< void main () { char z='c'; switeh(z){ nl cout<<"you are welcome\n"; case 'q! case'p' case 'c" cout<<"in\n", cout<<"ok\n";break, cout<<"balqa applied university”; break; default: cout<<"jordan"; 3 3 #include void main () { int bao-239; | int 6.1; cout< void main () { double s=4.77; cout<< s< void main () int s6.77,1-4.6.2=3, double v=3.6; cout<< t< void main () if (6<2*5) cout <<"HI"; cout <<"ALL", 3 ** static_cast ( Example : Y Static_cast (7.9) =7 Y Static_cast =3 Y Static_cast(25)=25 ¥ Static_cast(65)="A’ Y Static_cast(‘8”)=56. .Muslimengineer.info facebook.com/muslim.éfigineerpage. double x=2; X=10/4.0 + 9*x; cout< void main() { int x=3,y=2, 2=47 switch (xty++) { case 1: cout<<” "<<"; breal case 5: cout< void main() { int 2=8,a=10,A=9; if (2>=A && z/2) { cout < void main () { int x=15, y=3; cout< b) cout << "a" << endl; Se _ cout<<"Hi \\ "<<"cout<<\"Hi\" Hil in jutS<"Hi"; iff 3%6) cout<<3; else cout<<6; eee MEng.Samer A.Hamed muslimengineer.info facebook.com/muslim.engineer-page. int n=13; iffn>4.0) cout<9) { cout<<"Hello"; } else cout<<"Bye"; int x= if (x < 0) if (y.> 0) couts< 2; char c= ‘a switch (c) { case ta! :cout<<"0"; case 'b':case 'c':case ‘d': cout<<"1";break; cout<<"2"; cout<<"3"; break: default: cout<< MEng Samer A.Hamed facebook.com/Smurfs.OmThe.Wa} SiSisigitl - yolluufil all Hinclude void main () f { if (a>'b'|66>static_cast(A')) cout<<"#*#"< void main () t if (5<3) cout<<"*"; else if (7==8) cout<<"&"; else cout<<"$"; } #include void main () fint n; cin>>n; switch (n%6) { n=6 > the output is space... case 1 n=8 > the output is 8 case 2: case 3: case 4: cout< void main () t int a; cin>>a; iffa>0) switch (a) t case I:a=at+3; case 3:a++5 break; case 6:a=at+6; case 8:a=a*8; break; default: an; } else a=at2; } #include void main () const int a=5 int g=5; cin>>a; att a-g+2 \\ i cannot do any changes ona } facebook.com/Smurfts.OmThe.Way. Ait Lag Sate Ll aiSsull dalgl Jglill as .muslimengineer.info facebook.com/muslim.engineer.page. SiSsinl gull palin Aial Hinclude ‘void main(){ int f=3; doff=F*4;}while (f<=20); cout< ‘void main(){ int f=3; do{cout<<"all"; fess} while (F<=9); Hincludeciostream.h> void main(){ int 6; while (f=3) { coute<2*fe<™; “A ) facebook.com/Smurfts.OmThe.Way. SiSislo stl - yy ollarfil aba iil #includeciostream.h> ‘void main(){ int a[5]={3,2,6}; for (int i=0;i<4;i+4) alalill=alil; forli=0;l<4;i+4) cout< void main(){ int al91=(7,5,6,4,2}; int 2; int x ‘void main(){ int dof x=x-1; cout<=2); } MEng.Samer Hamed = muslimengineer.info facebook.com/muslim.éfigineerpage. SiSsinl gull palin Aial Hinclude ‘void main(){ int x{5]=(4,5,3,5,7}; for (int i=1;i<=3;i++}{ for (ir =3;)+4) coutcct4xlj}<<""; cout< void main(){ inta; for (a=3jacSja~){ if (a<2) break; else if(a==3) continue; a=1;} cout< void main(){ int all=(2,3,3,4,4,3,2,2,1); int D{+(5,6,7,8,2,3,5,2,1); char c[]="OneMoreTry"; for (int i=0;i<5;i+4) {int d=alil; int e=b{d]; coutceclel; }b Hincludeciostream.h> void main(){ for (int i=1;i<=9;1+=3); coutc=9) —coute ‘void main(){ for (int i=1;i==6;i++) {eout<<"*"; is=2;}} Nothing #include void main(){ int i=0,2=2,c=5; while (i<10) {it=z; switch (i) { case 2:c=c+1; case 4:c=c+2; default :c=c+3; v cout<> ali]; 3. int a[4]; for (i=03i<=3;3i++) afiJ=2+1; 4, a[0|=2, a[3]=9 .......et 5. int [ J= {12,3}; printing Y int a[5]={1,3,4,6,7}; cout << a[0]<< a[1]<< a[2]<> afi]; for (i=0;i<=4;i++) cout< void main() { int a[4]=(8,2,5,9}5 for (int i=0;i<=3;i++) { for (int j=0;j<=3;j++) cout<<+ta[j|<<" "; cout< A multidimensional array can be initialized in its declaration much like a_one- dimensional array. > The values are grouped by row in braces. >If there are not enough initializers for a given row, the remaining elements of that row are initialized to 0. int list [4]BIE {42.3.1}, (15,25,13},{20,4,7},{11,18,1 SiSisigitl - yolluufil all int a [2] [2]= {1,3,4,5}; int a [2] [2]= {1,3,4,5,6}; int a [2] [2]= {1,3,4}; HAHA HAH AA int list [3][3]={{1,2,3},{1,1,1},{0,0,0}}; int s1=0,s2=0; for(int i=0;i<3;i++) for (int j=0;j<3:j++) if(i!=j) sl+=list[i][j]; else s2+=list[i][j]; cout<< s1<<" "<> afi][jl; for (i=0;i<=4;i++) for (int j=0;j<=3;j++) cout<> a: if Cayo) Switch Ca) . Case 4: Case 3: Couk <* you are welcame \n’ 3 Case dg case "p's Case to's Couk (inn 3 cout Coe; break: 2 -muslimengineer.info facebook.com/muslim.engineer-page. StS poe palin Aad ample we 4 lpi 3 CinSst5 oe Case 43 Cant jan’ Kendis Case 22 Cout= 0) coute<*\Eene + facebook.com/Smurfs.OmThe.Wa} ASA gigs ~ olan abl [void main 0 switch (20+) { cdse 2ecout<<2<<™ ";breaky case 3: ifle=3) cout<=2) coutc<"#"; else cout<<* } int af3]=(46,1,237 cout<a[1]) cout<=0;i. coute 2:0) ‘continue; cout << “computing\n"; } double K[SI={1-1,2.2,3.3}7 int i=0; while (k[i] <3) f. coutc< KI]; ie double k(3]={1.1,2.2,3.3}; int 4=0; dof lcoutce REI; dees 3 while (k[4]<3) ; facebook.com/Smurfs.OmThe.Wa} SiSiptapll - .-ollufll alpijil int a[3]=(0}; int i=0; for(i; <3; ) i coute=0;4--) eayswtsy ig (atilsa coutcca [i]; } # iestream.h> void main() int List (3][3]={{1,2,3},{1,1,1},{0,0,0}3; int s1=0; -[ant s2=0; for(int i=0;1<3;i++) for (int 5=0;3<3;5++) dfGt=jf slimlist li} [5]; else s2telist (4 [5]; cout<< slcc" — "< Using namespace std; > header for the functions in each program . int addition (int,int); > function prototype. // int addition : the value which is returns from the function below int main (){ int z; > z type will be as the int type z=addition (5,3) > function call cout << “ the result is “ << z<< endl; return 0 } int addition ( int a,int b) { > function body ... intr; -r=atb; ~return r ; -muslimengineer.info facebook.com/muslim.engineer-page. SiSizigill palin Aial #include Using namespace std; int addition (int,int) int main (){ int z; int x,y; cout << “ enter two values “ << x<> x >>y; z= addition( 5,3);// call 1: using integers. cout<<”the result is “<0)<0 ... parameter passing ... true or false. (1 or 0) Return 0; 3 int addition (int a, int b ){ // body int r; r= atb; return r ; } ASA gigs ~ olan abl # include Using namespace std; int addition (int a, int b ); returna+b; 3 // here we can skip prototype and transfer all body below the main to above the main (here instead of defining z ,r....ete we can use return a+b. int main ( ) { int x; x= addition (10 , 20); cout << x << endl; return 0; 3 mae ees -muslimengineer.info facebook.com/mus! i ~ # include Using namespace std; int addition ( int a, int b ); char fun (int); int main( ){ int x=5 ,y=5; cout< 10 Floor (10) =» 10 Floor (=104) = -14 Sgrt (4) > 2 muslimengineer.info m/muslim.en 4S Example. pon (2,3) = 92% pow(y, 2) = 4 = 16 (4) tog (4s in {3g} Veqig (a) > [0.6) Veq 1 ( toca) > {aI 10 = loooe Is) Cos Cx) Sin G)_, tan OO) --- iz) (ae) w Obs (i) dos (1) exp(s)= 2 = 14 facebook.com/Smurfs.OmThe.Wa} SiSiptapll - .-ollufll alpijil aera en Ss : Floak a= —4.9 5 Cout < paw (Ploor(a) , 2) 5 y = w( =5,9) = 25 = -muslimengineer.info m/muslim. $iSi plo - yp olLanll ala 1-What is the output of the following code? bool xB) float 2=5.2; cout<<24; 32 2-What is the output of the following code? int x=4; i=; coutse) outset; i 5 4 45 54 3-What is the output of the following code? jntw=LE VeE2+3*1/6-5>= cout<3.2) wR, cout< 8il 2011 1010 810 2011 d* none 14-What is the output of the following code? ~ int flint a, int b) {cout< {oout<-2) {ifs} continue; cout< 7 © Bor 8 © None 25-What is the output of the following code? int flint 2=8) {ahs retum z; ahs cout<

You might also like