0% found this document useful (0 votes)
40 views

CPP Notes - 01

Uploaded by

Nikhil Dongre
Copyright
© © All Rights Reserved
Available Formats
Download as PDF or read online on Scribd
0% found this document useful (0 votes)
40 views

CPP Notes - 01

Uploaded by

Nikhil Dongre
Copyright
© © All Rights Reserved
Available Formats
Download as PDF or read online on Scribd
You are on page 1/ 30
me? Fee —- cous <5 ‘Helle Git 5. veturh 0 + Cbool) — x VaWables > aht tat char, double bdclear SC ++ DATAL Types: categerised in three Grenrs i r bi array, function pointer fete : Local variables has higher precedence than ial sanaile <<_—7 This operator is called insertion 4 2% —__ Extraction operator ¥ float takes 4 bytes double takes 8 bytes long, double fakes 12 by tes #| Typecast 2 i tlodtiid = 34:40Fy F/F = Float} [lata deublece = 24/4 U7 7i/L + lena 5 double we can Use gmat) for Fo / tor L [lex 34:4 —» 8 Cdefault) ] 4-445 4 By default ib consider ¥ 34:4TF = 4 as a double SaaS Pi Saari be eA ¥ 76 + Reference Vawiables i: fleat x = 458° float By mo x! Reference variable couk ecm agg we cay alSo use C-4) Exit ing olor: cout << sew cout << Goumee cere Gs Se bw 4) 214 Kepresen wid th while dis out put > Order precedence and associativily Ci esese jp sais (4) Mee me end | Cais 44 endl el y 46 ce 2s end hi R4 i Tt Snes CSL Gas. ease Post iix Un apy 4 owl eH Bee pe) ; & Gear i M ultiplicadi vel Poe aes Additive Ne Shit t Bev Relational 43 >5 3 Equality =a le Biwise AND ». Bitwise OR A Logical AND oS Logica) OR 1 Conditions Pal _ Assignment 2Heee PSeiye =>>= Comm x Control Structure 2 i> Sequence — Nermal “there are Three ay Selection > if, else ihsuith type ck control 25 Loop for do while ete beuc ture Sen coe yes ste True ig cobsidered as 1 and _fals iS nsicdered as oO ese rt a We ne while C{rue) £ UiilenoGtwaey Ss 4 out << i<¢end\ / printtC® sed 13) en: i4+4¢ * i Output: Intinite leep Gulpub : Error a ic hie mG. aes Note 2 Break “used ih all loops and ih : witch statement ii) Continue Wed only in all loops like tor, do while, while ay) Switch slatement js valid for int and char ~ Pointer a Madiessi ich opera} or 5 nx = > _ Pere ternce operator Exeseaui es Coes ae fn he that means p paints oh pemark | Liest element ol _arkay Wel: mark [o] i x int Heckants | lot *( . out on Out pub {23 56 Explanation: firstly p ‘S pink which Ehenwehpeey Cy Inndae mene Comss. ww points chi (1) which is Morlemiis then aqaih (++) increments apply me: Trois al Goa then prin’ hence, 56 dis AMS To ee SECs eS int Cotati pian On aay, ae = x Pow Caen Gan Weems : a cou kaw, Get wee Carlie: : a Bh iS | Qut put | y = OLN ia] ple +(p+o) ou Cos Wage Cerny 2 (eS i 1 he 24 Ne a a4 ee ad * Structure ond Union Struct éomn 1 fypede® _steuct comp 4 int id r Aine ee i har Pow > chor fou - Floakb salary ; flout salary % suet 1 fe inf main C ) i main C ) beach comp a + | Geib t pals a-id = Qo: Onis ais? O = flea cout << a-id << end | couk<< avid < , o— i: = * Functisn uy TE Qunchion camel labter math ©) 4 i then Function prototype is _compulscy 2% Eunchion prototype fells the compile, aves | an assuteay that function came, atler maihc) functish Exe ‘mt sum Cint a, int b eh Function int maih CYL. PRE OUI i Cin >>a>> b | ] cout << sum (Cab) > Function cal] | re fur 6 * int sum Cint a int bYF hb G.= obly ( return (©: q : Te a Bani OSC Cint ine wees acceptab a. 7 x int | Sums Cini apply yi Hebhcicceptabl< or | we can wrile in Bee roid gCvoid) | void 4 s Go: both method indawern ee Cul aa hae turn Ov Tc See 1 WiredSoap: cpp } id g OF : ie peageay | cout << S Good morning ” sé i * Cat) by reference variable Yai wap yar @ Ane. J S@. Me Ds i Ve = tohile using painler Ee Gnt *a yet +b) brows: on temp = AG ° 1 ease: b= temp Th main) function Stoap var C x,y)? Lyssa, nelerence variables: Th main c) dancin Swap var ( bx 2S Using pointes _ erence . NEE \ Note : Tt is hot gaurantee thal oe Wmcihe is inline function Wis ar request “t } depend on compiler te acho eee Inline EuncYien Bl Thine funclion js likely oF mua be used when functioh 45 4+ cole. \ smail, and not used ih _Swilch/ loop 9 QTC Uhre 42) The “purpose oh inlihe) Tumetion 1S bo save time, when we call same Funchion ine Limes ip _main C) fdunetion t S7—there is _highly vecomanded That we new inti {nction Wy PE CUpsion and i ial in ki line Ex inline int product Citipeo ing by { return a* b * 4 int main ©) f ‘nt. vat bare a cout << Enter the svalue lof a and b” << fem aires cout <<" The product is” Kproduct Cab) << ¢ oul << ) \ i £2 ey Coub <4 ! 1 é Cndl (geuancas W y 24 end Le small oh this i Function , may dime: and dso Function ce is_ver ed inline il a : o in this code. be. call) same tunchioh — x Default Araument | Constant Arsgument SITE is necessary that default ariument is _on bight i BL deat imlerest Cink money | flood Factor =104) return mnchey * qaclor - IL dedaulh oegernent in Wadi 1 OSI. int ab im } ME m = 100000 | = | eout 44" You received’ <4 interest Cm ) <4 end iE 4 I/bbe We passing wo ohe value jh funclioh Lem Iso by debut af chese Jacher = 1-04 > lenut <<" You received ” << interest Cm 1:1) end |: Hi Wn aS Cxample lena) copic d fo Sache factor = 1-1 relurh 0 | Oulput 2 164 000 > default arguinend (RO: 010.0 vineerie wie passed is] valu *)| Constant aerument: § be Binplyeused arcament ean ( cons Float Factor) se. th (ea ca HT ted fibonacci series (ul I ie qh i nl a | Prefer: | cxne eel numa Recttes eras im T g Dl fades ial One eee ees _ Fibonacci » (fibo Cn= aaa ——— a Funclien Overloach ing = bi with differed Fanclicn with same name work Compilee identidied with the help of. oF orgie Yo which function it should | 4 Prefer progpon Function averloading Cit) Se ee procedure = oriente pasgeanmings * Nols ; a as) dlinect ae Lype a “siving nome = “Hello teri 1% * Sib cout << home 4 9 aA Output 5 Helle World 1 T ic + Classes and Object | Object Okects are independent unit and each hes its’ own identity just os object in real world 0 describe ‘Them _ this charucherislics aie ulso called obbribules Attributes mean it clescribes the current [ state of an abject ext: Ob, ects con have multiple attributes C the mug conus emply wed or lor ge) aoe. cuss might be fail of water another might be ma | x Objects also hove characteristics that ore used — | 12. imensio eschibe an she OoP. aia e adivibutes iy behavior —4) Th_pengeamming an objec is sell =conlained, with is sau en ale nc seperate trom 1 aT ai che sci be. hs Current state, Each exhibils is owh behavior whicl demonstrates whal they can do rs ee ee Note: By default class memes _ ’ iS private = > the class describe whats the object is_separate From the. object bse Th other jnowd’. 4! an clase déscribed obiectis | blueprint , de cription oe lef WE can use sare blue print Por cisea! + Ex= multiple ditferen! objects. Ee Exiulsame blueprint used t Creat muttiple laildings which is used ] baci for actually buildings the sheuct 2y Fach class has a harme and describe a atbeibules and behavior attributes are | we fore woper Lies = aa) a> Methad ic _ agin Fern fomila. class's ehavicr_, is__basi Jon that cle to_u class. ] Vethod ape similar. ts Nanchions = They cre |______ibleck of code [hat awe called) and [hey Can also perforin actions and. eeturh voles. e called instantiation T exis nome 3» Bank Account c : alimbulcd.: sLNGM MMO peccd bchavior i _apen@) close€) deposit ()- We. ct), QS Ges class the ala “character for crcating a bankihg, PRO gsc a a oe #1) De alawingi } retin © OEREOM, y hue lial Vefrition | the class ih couk <4" The, suime isms Sum -setdala(x,y, E m2. return O° aL J i pucks PT hes 1st Kees Prefer pregpesua t Cleisses Cte i OTe ~ Abstraction 1 The concept af absiractien js hat we Pocus oh tial qualitie pcs sl rather than the specific characleristics of one partictilae example Th short ibstraction mean focus ah the Ssen} ial qualitie of som eithivicy When you use cork youre actually Using the cout object at the class oS1ream Thi Stream data to result in standar output A qoocl real-world example is a book : when aw sheae the teem beck yOu Jon‘t know the exact Specifics ie: the page count, the color the size but you eld cl the ide oh og book - the abstraction of the book Absteaction acts as a Foinclation for the ie other £ orientation Jundamentals uch as inheritance and _polytneis phisin * Encap ulation ? Dl Encapsulolicn is alse catled as dala hiding and and black boxine,” 2) Encapsulation allows us be hide detail of a class Yealizabion . Paice: oe ty, awl Canali the (oy y Aate is. ss aa a re Plexible 6 ha i i pe alia ni f other park of code = aia olf ecting : ida eee ect in a in = [] ss encapsulate on —alyettis —atnibate. he ahd methad = ote 1 structure Ih C +h 1S dypedel ~ docsh't need) to add_aditionally ace Variable to structure. * To find length se szitg = ~\ Ex ih meth) a | tring name =“ Hello mobo”: cout << name | Output Hella) mete, 3 (fans int main’ Cy g - ii sixing name =“ Helle moto” | out S Using namespac stl. dg ocx. +#include < ics treat * ! int main CY ink ja tdeut = char fi i Cie string pame =~ Vikolp monas ” cout <4 hame << end | + for {=o i cname length © ~ j +4) 4 if Chame atC c= Nod olhidivened icubed wacie’ 1 hame at i4_\I_pame ila Ge) AO UV heme, sobGi) ss DU 4s) Col 4 + 7 out There are’ << Count <<" vowels present in _stying ” <4 endl ° : returh O° Vikalp monas Output i Theme are 4 yawels present in string X ot Tt mean heck ubtil ‘x? =x Th means check or disslay je only for! x? Ane ther example 7 mire Note : u" inh itemId floods int iter Price (100) 7 int ¢ounher | public _ cid inikCounler C)d counter = 0 aid sel Price Gow, , void display Peice CO, roid Shopst i sebPhice G) 4 a £ i Du a cout <<" Eater Tell Vaca iret now. * thew Toute i cout <<"Ehler Price ot yours ier’ << ec: | cin >> item Price Leoounter 1) aa Counter ++) 4 void shop 2° displayPrice Cy for Cint 1207 }ccountele s yee) cout <<" The Pricarch Hew with Td” a3 ten Cec Mess ile! 7 /" salary is privat | cout <<* Enter the id leNetiee tule: Demeed of employee é< endl: variables inside the. cih >> iol | class abject es _void getid Cuoi d) cout The id of this etmplyee is” «id << endl: t . 7 int moih ©) Fmplayee tl ea or Cindi 0° 1464o ik) Pe ay r Pb Cid get Td fans Prcther) ceample 2 Tut US s2ignd Tut 25-1 an aii ee = Piendia 6 Functions -++— _* Class Complex e a Rian comm een ERD con lic E void! set Nuenles GBs Wass /aene i) i GQ. Se ee a = ne —— q as. it otd printNum ber Ov ——— lI cota <4) You win num lembign mecleeae TT << b <<", 7 i 1 : uM fe : + & Complex surnComplea Ceomplex Ol Covplex 2) complex 6 3° ig o3: set Number (Cola +07: ai Goi: bt o2:! wechurbodgil 1 Loot wed ae We are petu i [ int main CY £ value O23 hence J Complies ai ¢ um ccm weed to create | ci-setNuwmber C1 4) + conn, hd_al C1. _printNumbe ¢)« point Rl aa | properties of | 4 Dunction comes ch actich | Hence_u Weed! {0 Beck ih complex class —— I cr set Number (5 ay VW C2: print Number C ‘ Sum= SsumComplex Ceci al came printNumber ©): Siu | Soom 7 S Ww - — | i Propertics ot _Idviend functions, t ) Net in the scope af class) means sumcamplox has acess to private members at complex _¢ lass Lut scm plex iS not member ot clas: complex | a5! Since Jif is not in the scope of the class it ‘annot be called trom the abi ck of That cles eile ur Complex Q)== Thvalid 2 Con be invoked without the help of any object 4) Usually contains The objects as argument s) Can be declared inside public of private secbich b the class ETE cannot acess the members clirectly by their hames and need objects — name + member — name to to acess ony Wem beps qT Jutred => Pow weference of this proyras * We can make whole clu cite ey dniend and give acess ho any wember ee af MKT 2 More heed to study friend Junction with the same names oS ay TE is used to initialize the alyects cl 29 TH is automatically invoked whenever an is_created eS 4) Cans true WG) cE bReWE oat ee cungam ent is called defaalt fons feu 2 sheuld be declare hve. tha publi cliss E 62 Do hot have vetueh + Pe Gna _they Penh ot _ weturb Value S Th can have, default agement, 8y We cannot fete TS theite — s Ex 2 atte eae me cla Comm plex — é i Chiat) el public Complex (void ) Complex GRY) => _paramelerize void» print Number ©) constructor & Goud << Your! number 9x4 axe << b<< “iccendl ie Complex 2% Complex (void) fl default constructor £ Complex Cint x iniy)=--” parameterized uso constructor Wet ob 5 int mai C , 2 = Gorrpllexer ae Yow orale em pcint Number ©) + 2 prin t Namber iz. 3 print Numberc yj * rCturh 6% _ output ; Your number Is 16 +01 | Your umber 1§ Jo +01 Your numer 1S ole +04 an bhi public x Connie (ME eve Constructo” eid print Number ©) 4 Tl out <2 Your number gms sem oe i Com plea: Complex Cint x indy => Th | f a pavometenized consi |! oq 2S — a i } k end i int_moin C) 2 — | Tin plicit cal) | Con plicx en CAN Gp ae a- print iNumber C) * | Complex L= Consiont) Sie = a Co ein Numbers Ce % Explicit F veefurh 6! + ee 3 . Your i Warber LS. Tuto3Z0.1/ 20k BT ate = ONS, or verload ing 2 class Complex fyi |g public Complex C) { ato: pr stom Complea Cink x indy ) IP if we suse complex tht x ‘inty = 5) QS at =a? gives GN eyeroye be ee because compiler not 3 recognized to _inuck Cornplex Cink x) £ which constructor Qex? So we didwt used Leo: default constructors ih _cons bructove veal print Num bere Cn) { overloadin og th coub& Your number jg” f Complex co 3y c3 prin {Number ONE Compler_c1 4, 6): c1- print Nunbe eC) returh 6 31 | Complex o2 (5) * Output: Your numer iS 44 61 C2: prihtNumler C) } f Sl AL ‘Ono = ! # include 4 iostreom? usih amespuce std, la i ph i | eee a int _datat dalar dota, public » - B z imple Cinta No tbeed sntc2 3%) = | dafat= a< : f | dala 2= & alee data 3 =e aN 3 eid_printbata C) x x Ce void simple 1 priht Dalad) i a cout <<" The value of datlad data 2, Al ig. <4 datal "dala 2d¢" and” di int _maih ©) £ im ple SC ihe ee S-ppihtData C)? | returh 6! 2. 3 Ce N Output: The value ot dabad dake2 Be dates alii aaa V2,\2 and 3 ee ad Numbe class , int a public. t Number Cint num) a = hum * cs adh pain © 4 out <* Your number ig “<4 a << endl | | x . ee GD ned Number b C59! L_@utput + b- print ©)? | Your number is § 5 * class Number { filinviee ue public 4 Number) f { Nambere Cint num) £ CES wenn Y void print C) eh cou 46" Noumbinumberianis Muzaa <« endl’ we int main C) Output! Rem?) Nuwberova, i ‘1 Nour Nember iS 5 a= Number(5) Q Tee); lta

You might also like