01 Sample Programs c++

Embed Size (px)

Citation preview

  • 8/9/2019 01 Sample Programs c++

    1/78

    Sample programs continued…..

    Programs related to

    Basic data types

    Basic Operators

    Operator precedence

    Loops

    If  Switch

    Case

    Cin

    Cout

  • 8/9/2019 01 Sample Programs c++

    2/78

    WRI! C"" CO#! O SW$P WO I%!&

  • 8/9/2019 01 Sample Programs c++

    3/78

    #include

    using namespace std;int main(){

    int a, b, c;couta;

    coutb;

      c=a;

    a=b;b=c;cout

  • 8/9/2019 01 Sample Programs c++

    4/78

    'I%# (! &R!$!R O' WO &I)!%

  • 8/9/2019 01 Sample Programs c++

    5/78

    note

    cout   num-err/ to read through 0ey-oard11111 if you use 2uotes

    message will -e displayed

    e3traction operator

  • 8/9/2019 01 Sample Programs c++

    6/78

    4include5iostream6using namespace std/

    int main789

    int num:; numrst num-er ?=/

    cin 66 num:/cout 55 =please enter the second

    num-er ?=/

    cin 66 num

  • 8/9/2019 01 Sample Programs c++

    7/78

    Write c"" code to >nd greatest; secondgreatest and the least of three num-ers

    & O S

  • 8/9/2019 01 Sample Programs c++

    8/78

    &R!$!R O' (R!! %*+B!RS4include5iostream6using namespace std/int main789int a; -; c/

    cout55=!%!R %*+B!R: ? =/cin66a/cout55=!%!R %*+B!R< ? =/cin66-/ 111111111 or conert into single line e3?cin66a66-66c/cout55=!%!R %*+B!RD ? =/cin66c/if7a6- EE a6c EE -6c8

    9cout55a55= IS &R!$!S.Fn,/ C$% B! CO+BI%!# OR #I)I#!#111111111111111cout55-55= IS S!CO%# &R!$!S.Fn,/cout55c55= IS L!$S.=/@else if7a6- EE a6c EE c6-89cout55a55= IS &R!$!S.=55endl/ I% PL$C! O' F% 7C$RRI$&! R!*R%81111111

    cout55c55= IS S!CO%# &R!$!S.=55endl/cout55-55= IS L!$S.=

    l if7- EE - EE 8

  • 8/9/2019 01 Sample Programs c++

    9/78

    else if7-6a EE -6c EE a6c89cout55-55= IS &R!$!S.=55endl/cout55a55= IS S!CO%# &R!$!S.=55endl/cout55c55= IS L!$S.=/@else if7-6a EE -6c EE c6a8

    9cout55-55= IS &R!$!S.=55endl/cout55c55= IS S!CO%# &R!$!S.=55endl/cout55a55= IS L!$S.=/@

    else if7c6a EE c6- EE -6a89cout55c55= IS &R!$!S.=55endl/cout55-55= IS S!CO%# &R!$!S.=55endl/cout55a55= IS L!$S.=/@

  • 8/9/2019 01 Sample Programs c++

    10/78

  • 8/9/2019 01 Sample Programs c++

    11/78

    Operator precedence

  • 8/9/2019 01 Sample Programs c++

    12/78

    Continued…..

  • 8/9/2019 01 Sample Programs c++

    13/78

    >nd 3 …

    GH"J5:K

  • 8/9/2019 01 Sample Programs c++

    14/78

    $nswer..

    GH:

    GHA

  • 8/9/2019 01 Sample Programs c++

    15/78

    O 'I%# (! S*+ O' WO %*+B!RS

  • 8/9/2019 01 Sample Programs c++

    16/78

    4include5iostream6using namespace std/

    int main 789int no:;no

  • 8/9/2019 01 Sample Programs c++

    17/78

    O #I)I#! $ %*+B!R WI( $%O(!R

  • 8/9/2019 01 Sample Programs c++

    18/78

    4include5iostream6using namespace std/

    int main789oat 2uotient; remainder/int no:;no

  • 8/9/2019 01 Sample Programs c++

    19/78

    CL$SSI' (! O$L %*+B!R O' #$S I%P* I%O !$R; W!!T

  • 8/9/2019 01 Sample Programs c++

    20/78

    4include5iostream.h6using namespace std/int main789long num; temp; days; wee0; year/char ch/

    do9cout55=!%!R (! O$L %*+B!R O' #$S ? =/cin66num/yearHnumDN/tempHnumQDN/wee0Htemp/daysHtempQ/cout55=Fn=55year55= years = 55 wee0 55 =wee0s = 55 days 55 = days.=/cout55=FnFnRepeatU 7yn8 ? =/cin66ch/@while7chHHVyVMMchHHVV8/return A/@

  • 8/9/2019 01 Sample Programs c++

    21/78

    #ISPL$ +O%( CORR!SPO%#I%& OI%P*; *SI%& I'!LS!CO%SR*C

    #ISPL$ +O%( CORR!SPO%#I%& O I%P*;

  • 8/9/2019 01 Sample Programs c++

    22/78

    *SI%& I'!LS!CO%SR*C4include5iostream6using namespace std/

    int main789int n/cout55=!%!R $ %*+B!R L!SS ($% OR !*$L

     O :< ? =/cin66n/

    while7n6:

  • 8/9/2019 01 Sample Programs c++

    23/78

    cout55n55= I+PLI!S +$.=/else if7nHHN8cout55n55= I+PLI!S *%!.=/else if7nHH8cout55n55= I+PLI!S *L.=/else if7nHHJ8cout55n55= I+PLI!S $*&*S.=/else if7nHHX8cout55n55= I+PLI!S S!P!+B!R.=/else if7nHH:A8cout55n55= I+PLI!S OCOB!R.=/else if7nHH::8cout55n55= I+PLI!S %O)!+B!R.=/else if7nHH:

  • 8/9/2019 01 Sample Programs c++

    24/78

    +O%( #ISPL$ *SI%& SWIC(

    4include5iostream.h6

  • 8/9/2019 01 Sample Programs c++

    25/78

    int main789int m/cout55=!%!R $ %*+B!R ? =/cin66m/while7m6:

  • 8/9/2019 01 Sample Programs c++

    26/78

    9case : ? cout55=$%*$R=/-rea0/case < ? cout55='!BR*$R=/ -rea0/case D ? cout55=+$RC(=/ -rea0/case K ? cout55=$PRIL=/ -rea0/case ? cout55=+$=/ -rea0/case N ? cout55=*%!=/ -rea0/case ? cout55=*L=/ -rea0/case J ? cout55=$*&*S=/ -rea0/case X ? cout55=S!P!+B!R=/ -rea0/case :A ? cout55=OCOB!R=/-rea0/case :: ? cout55=%O)!+B!R=/ -rea0/case :< ? cout55=#!C!+B!R=/ -rea0/@

    return A/@

  • 8/9/2019 01 Sample Programs c++

    27/78

    #ISPL$ +!$%I%& O' &R$#!S *SI%& SWIC(C$S! SR*C*R!

    i l d i h

  • 8/9/2019 01 Sample Programs c++

    28/78

    4include5iostream.h64include5conio.h6oid main789clrscr78/char ch/

    cout55=!%!R &R$#! ? =/cin66ch/switch7ch89case VaV?case V$V?cout55=Fn!GC!LL!%=55endl/-rea0/

    case V-V?case VBV?cout55=Fn&OO#=55endl/-rea0/

    case VcV?

  • 8/9/2019 01 Sample Programs c++

    29/78

    case c ?case VCV?cout55=FnO.T.=55endl/-rea0/case VdV?case V#V?cout55=FnPOOR=55endl/

    -rea0/default?cout55=FnI%)$LI# &R$#! ?=55endl/@getch78/@

  • 8/9/2019 01 Sample Programs c++

    30/78

    4include5iostream.h64i l d 5 i h6

  • 8/9/2019 01 Sample Programs c++

    31/78

    4include5conio.h64include5process.h6oid main789oat num:;num

  • 8/9/2019 01 Sample Programs c++

    32/78

    9 case " ? result 77num:den:8"7num

  • 8/9/2019 01 Sample Programs c++

    33/78

    $ S$+PL! PRO&R$+ O PRI%

  • 8/9/2019 01 Sample Programs c++

    34/78

    4include5iostream.h6*sing namespace std/

    Int main 789int num/for 7numH:/ num5H:AA/ num ""89cout 55num55=Ft=/@Return A/

    @

  • 8/9/2019 01 Sample Programs c++

    35/78

    O #!!R+I%! $ PRI+! %*+B!R.

  • 8/9/2019 01 Sample Programs c++

    36/78

    4include5iostream.h6*sing namespace std/int main 789long num; fact/ int count/cout 55 =!%!R $ %*+B!R ? =/cin 66 num/for 7 factH:; countHA/ fact5Hnum

  • 8/9/2019 01 Sample Programs c++

    37/78

    PRI% (! +*LIPL!S O' $ %*+B!R *SI%& $#OW(IL! LOOP/

  • 8/9/2019 01 Sample Programs c++

    38/78

    4include5iostream.h64include5conio.h6oid main789int num; multiHA/clrscr78/cout55=FnPL!$S! !%!R (! %*+B!R ? =/cin66num/cout55=Fn(! +*LIPL!S O' = 55num 55= are? =55endl 55 endl/do9multi""/

    cout 55num 55 = G = 55 multi 55 = H =55num1multi 55 endl/@ while7multi5:A8/getch78/@

  • 8/9/2019 01 Sample Programs c++

    39/78

    PRI% (! +*LIPLIC$IO% $BL! O' $ %*+B!R*SI%& $ 'OR LOOP/

  • 8/9/2019 01 Sample Programs c++

    40/78

    4include5iostream.h64include5conio.h6oid main789int num; multi/

    clrscr78/cout55=FnPL!$S! !%!R (! %*+B!R ? =/cin66num/cout55=Fn(! +*LIPL!S O' = 55num 55= are? =55endl 55 endl/for7multiH:/ multi5H:A/ multi""89cout55 num55= G = 55multi 55 = H = 55

    num1multi 55endl/@getch78/@

  • 8/9/2019 01 Sample Programs c++

    41/78

    O #ISPL$ S!RI!S ?

  • 8/9/2019 01 Sample Programs c++

    42/78

    4include5iostream.h64include5conio.h6oid main789int sumHA; i;n; t/clrscr78/cout55=!nter the num-er of terms ? =/cin66n/cout55=Fn=/for7iH

  • 8/9/2019 01 Sample Programs c++

    43/78

    PRI% (! 'IBO%$CCI S!RI!S

    4include5iostream.h64include5conio.h6oid main78

  • 8/9/2019 01 Sample Programs c++

    44/78

    oid main7891'IBO%$CCI S!RI!S 1char choice/do9

    clrscr78/long dou-le num; aH:; -HA; count/cout55=!%!R (! %*+B!R O' !L!+!%SR!*IR!# ? =/cin66num/cout55=FnFn=/for7countH:/ count5Hnum

  • 8/9/2019 01 Sample Programs c++

    45/78

    4include5iostream.h64include5conio.h6oid main78

  • 8/9/2019 01 Sample Programs c++

    46/78

    oid main789long dou-le >rst; last; sum / char choice/do9clrscr78/

    cout55=FnFnPL!$S! !%!R (! 'IRS !R+ ?=/cin66>rst/cout55=FnFnPL!$S! !%!R (! L$S !R+ ?=/cin66last/for7sumHA/>rst5Hlast/>rst""8sumHsum">rst/cout55 =FnFn (! 'I%$L S*+ IS ? = 55 sum/cout55=FnFnPR!SS O R!P!$ !LS! !GI

    PR!SSI%& $% T! ? =/cin66choice/@while7choiceHHVyV MM choiceHHVV8/@

  • 8/9/2019 01 Sample Programs c++

    47/78

    O C$LC*L$! (! S*+ O' #I&IS I% $ %*+B!RR!*R% O

    I%#!G4include5iostream.h64include5conio.h6

    oid main 789long num; digit; sum/clrscr78/cout 55 = !%!R $ %*+B!R ? =/cin 66 num/for 7sumHA/ numYHA/ numHnum:A89

    digitHnumQ:A/sumHsum"digit/@cout 55 =Fn(! S*+ O' (! #I&IS ? =55sum/getch78/@

    QKAAHHA8 ZulianHDNN/else

  • 8/9/2019 01 Sample Programs c++

    48/78

    else ZulianHDN/switch7month89case :? Zulian H A/case

  • 8/9/2019 01 Sample Programs c++

    49/78

    R!*R% O I%#!G4include5iostream.h6*sing namespace std/Int main78/9

    clrscr78/int num; a;-;c;d/cout55=!%!R $ %*+B!R ? =/cin66num/aHnum/-Hnum/cHnum/dHnum/cout55=Fn=55num55= is assigned to a;-;c and d ?=55endl/cout55=""a H = 55 ""a55=Fn- H =55-55=Fnc"" H = 55 c""55endl/cout55=d H = 55 d55endl/cout55=a H =55a55=Fn- H =55-55=Fnc H=55c55=Fnd H =55d55endl/

    getch78/

  • 8/9/2019 01 Sample Programs c++

    50/78

    S*+ O' $LL !R+S O' $% $RR$ I%P* B (!*S!R R!*R% O I%#!G4include5iostream.h64include5conio.h6

    oid main789clrscr78/ long oat num\:A]; sumHA; yH:/cout55=Fn!nter :A elements for the array ?=55endl55endl/for7/y5H:A/y""89cout55=Fn!ntry ? =55y55endl55endl/

    cout55=!nter ? =/cin66num\y]/ sum"Hnum\y]/@cout55=FnFnhe sum all the elements entered forthe array is ? = 55 sum/getch78/@

    o ma n9int array\:A]; countHA; sum:HA; sum

  • 8/9/2019 01 Sample Programs c++

    51/78

    sumDHA/clrscr78/111111111input11111111111111cout55=Fn!%!R :A %*+B!RS 'OR (! $RR$ ?=55endl55endl/

    for7countHA/count5:A/count""89cin 66 array\count]/@111111111111process11111111111for7countHA / count5:A / count""89if7countQ

  • 8/9/2019 01 Sample Programs c++

    52/78

    F F F /cin.getline7str; A8/lenHstrlen7str8/cout55=Fn!%!R $ C($R$C!R? =/cin.get7ch8/agHVnV/

    for7countHA/str\count]YHlen/count""89if7chHHstr\count]89agHVV/-rea0/@@

    if7agHHVV89cout55=Fn=/cout.put7ch8/cout55= is contained in the string ? FnFn=/cout.write7str;len8/@else

     

    4include5iostream.h64include5conio.h64include5ctype.h6

  • 8/9/2019 01 Sample Programs c++

    53/78

    yp4include5string.h6oid main789clrscr78/char str\A]/

    int agH:/cout55=Fn!%!R $ SRI%& ? FnFn=/cin.getline7str;A8/for7int iHA/ str\i]YHVFAV/i""89if7islower7str\i]889agH:/

    str\i]Htoupper7str\i]8/@@if77agHH:8MM7str\i]HHVFAV889cout55=Fn*PP!RC$S! SRI%& IS ?FnFn=/cout55str/@

  • 8/9/2019 01 Sample Programs c++

    54/78

    O PRI% (! C*B! O' $ %*+B!R *SI%& $'*%CIO% R!*R% O

  • 8/9/2019 01 Sample Programs c++

    55/78

    I%#!G4include5iostream.h64include5conio.h6oid main789

    oat cu-e7oat8/oat 3;y/clrscr78/cout55=Fn!%!R $ %*+B!R ? =/cin663/yHcu-e738/cout55=Fn(! C*B! O' =55355= is = 55 y/getch78/

    @oat cu-e7oat s89oat n/nHs1s1s/return n/@

    char ch/int i/oat amt\A]; -ig/

  • 8/9/2019 01 Sample Programs c++

    56/78

    oat large7oat array\];int n8/clrscr78/for7iHA/i5A/i""89cout55=!%!R !L!+!% %*+B!R ? =55i":55= ?

    =/cin66amt\i]/cout55=W$% O !%!R +OR!U 7%8? =/cin66ch/if7chYHVyVEE chYHVV8-rea0/@if7i5A8

    i""/-igHlarge7amt; i8/cout55=Fn(! L$R&!S !L!+!% O' (! $RR$IS? =55-ig55endl/getch78/@oat large7oat array\]; int n89

    1PR!'IG $%# S*''IG R!*R% OI%#!G4include5iostream.h64include5conio h6

  • 8/9/2019 01 Sample Programs c++

    57/78

    4include5conio.h6oid main789int num/oid su^37int8/

    oid pre>37int8/clrscr78/cin66num/pre>37num8/su^37num8/getch78/@oid pre>37int n8

    9cout55=Fn=55""n/cout55=Fn=55n/@oid su^37int n89cout55=Fn=55n""/cout55=Fn=55n/

    @  

    I%#!G4include5iostream.h64include5conio.h6

  • 8/9/2019 01 Sample Programs c++

    58/78

    oid pyramid789static int nHA/int p; m ;2/n""/

    for7pH:/p5Hn/p""89for72HA/25Hnp/2""8cout55V V/mHp/for72H:/25Hp/2""8cout55m""55V V/cout55endl/

    @cout55endl/@oid main789int i/clrscr78/for7iHA/i5/i""8

    4include5conio.h6

    int lcd7int a;int -89int i;ZH

  • 8/9/2019 01 Sample Programs c++

    59/78

    int i;Z

  • 8/9/2019 01 Sample Programs c++

    60/78

    4include iostream.h4include5conio.h6int summat7int >rst;int count8/oid main789clrscr78/unsigned long a; -; sum/cout55=Fn!%!R (! 'IRS !R+ ? =/cin66a/cout55=Fn(OW +$% %*+B!RS $R! O B!$##!#? =/cin66-/sumHsummat7a;-8/

    cout55=(! S*+ IS ? =55sum55=Fn=/getch78/@int summat7int >rst;int count89unsigned long i; sHA;ZH>rst/for7iHA/i5count/i""8s"HZ""/

    return s/

    O ILL*SR$! (! C$LL B )$L*! +!(O# O''*%CIO% I%)OTI%&R!*R% O I%#!G

  • 8/9/2019 01 Sample Programs c++

    61/78

    R!*R% O I%#!G4include5iostream.h64include5conio.h6oid main789

    clrscr78/int change7int8/int originalH:A/cout55=(! ORI&I%$L )$L*! IS ? =55original/cout55=FnR!*R% )$L*! O' '*%CIO% C($%&!78IS ? =55change7original8/cout55=Fn(! )$L*! $'!R '*%CIO% C($%&!78

    IS O)!R ? =55 original/getch78/@int change7int a89aH

  • 8/9/2019 01 Sample Programs c++

    62/78

    4include5conio.h6oid main789oid swap7int E; int E8/int aH; -HX/

    clrscr78/cout55=Fn(! ORI&I%$L )$L*!S $R! ? =/cout55=aH = 55a55= -H = 55- 55=Fn=/swap7a;-8/cout55=(! )$L*!S $'!R SW$P78 $R! ? =/cout55=aH = 55a 55 = -H = 55- 55=Fn=/getch78/@

    oid swap7int E3; int Ey89int temp/tempH3/3Hy/yHtemp/cout55=(! SW$PP!# )$L*!S $R! ? =/cout55=aH = 55355 = -H =55y55=Fn=/

    O I%)OT! $ '*%CIO% $TI%& %O $R&*+!%S$%# R!*R%I%&%O )$L*!R!*R% O I%#!G

  • 8/9/2019 01 Sample Programs c++

    63/78

    4include5iostream.h64include5string.h64include5conio.h6oid func7oid8/oid main789clrscr78/func78/getch78/@oid func7oid89

    char name\

  • 8/9/2019 01 Sample Programs c++

    64/78

    oid err[msg7oid8/do9cout55=!%!R +$RTS ? =/cin66mar0s/

    if7mar0s5AMMmar0s6:AA8err[msg78/@while7mar0s5AMMmar0s6:AA8/return mar0s/@oid err[msg7oid89cout55=+$RTS $R! O* O' :AA=55endl/cout55=FnPL!$S! !%!R +$RTS B!W!!% A O:AA=/cout55=FnR $&$I%=/getch78/@oat calcperc7int s:;int s

  • 8/9/2019 01 Sample Programs c++

    65/78

    for7rDH/ rD5HD/ rD""89goto3y7rD;:N8/cout55=1=/goto3y7rD;

  • 8/9/2019 01 Sample Programs c++

    66/78

    !R%$R OP!R$OR4include5iostream.h6

    4include5conio.h6oid main789int countHA/int num:H; num

  • 8/9/2019 01 Sample Programs c++

    67/78

    %!S!# !R%$R OP!R$OR R!*R% OI%#!G

    4include5iostream.h64include5conio.h6oid main789int countHA/int num:H

  • 8/9/2019 01 Sample Programs c++

    68/78

    4include 5iostream6

    4include 5string6using namespace std/int main 789string user[name/cout 55 =Please enter your name? =/cin 66 user[name/cout 55 =(i = 55 user[name 55 =Fn=/

    @

    doesnt consider a space….characters uptospace or enter 0ey are considered for cout

    If you want to put two strings together; 0nown as appending one string onto anotuse the "sign?

  • 8/9/2019 01 Sample Programs c++

    69/78

    use e s g4include 5iostream64include 5string6using namespace std/int main 78

    9string user[>rst[name/string user[last[name/cout 55 =Please enter your >rst name? =/cin 66 user[>rst[name/cout 55 =Please enter your last name? =/cin 66 user[last[name/string user[full[name/

    user[full[name H user[>rst[name " = = " user[last[name/cout 55 =our name is? = 55 user[full[name 55 =Fn=/@

    If you want to put two strings together; 0nown as appending one stringonto another you can use the "sign?

  • 8/9/2019 01 Sample Programs c++

    70/78

    onto another; you can use the "sign?4include 5iostream64include 5string6using namespace std/int main 78

    9string user[>rst[name/string user[last[name/cout 55 =Please enter your >rst name? =/cin 66 user[>rst[name/cout 55 =Please enter your last name? =/cin 66 user[last[name/string user[full[name H user[>rst[name " = = " user[last[name/cout 55 =our name is? = 55 user[full[name 55 =Fn=/@

     o read complete line till a

  • 8/9/2019 01 Sample Programs c++

    71/78

    carriage return is detected getline7 cin; user[>rst[name; VFnV 8/

    it neglects new line character

     he little secret of oating point num-ersI want to let you in on something a-out oating point num-ers li0e oat or dou-legood in practice; since they can represent a huge range of alues. he ma3imum arepresent is a-out :.J :ADAJ. hats a num-er with DAJ _eros at the end of it. Bu

  • 8/9/2019 01 Sample Programs c++

    72/78

    ep ese s a-ou J A DAJ a s a u -e DAJ e os a e e d o uonly J-ytesdoesnt that mean it can store only

  • 8/9/2019 01 Sample Programs c++

    73/78

     his allows the computer to store really -ig num-ers -y putting a ery large num-But the none3ponent part cant store DAA digits; it can only store a-out : digits. :digits of precision when you wor0 with oating point num-ers. If youre dealing wi

    alues; then the dierence -etween the num-er the computer stores; and the actuery small. If youre wor0ing with huge alues; well; youre going to hae large a-the relatie error is small. 'or e3ample; if I had only two digits of precision; I couldX.D :A miles from the sun. hats ery close; in relatie terms; to the right alBut in a-solute terms; its KK thousand milesY hats nearly twice the circumferenccourse; thats using only < digits of precision. With :; you can get a lot closer for amillion. In most cases; the ine3actness of oating point num-ers wont aect you

    someserious num-er crunching or scienti>c computing; -ut when it matters; it matters.

    String comparisonsC"" string o-Zects allow you to use all of the comparisons that you learned a-ouin this chapter.

  • 8/9/2019 01 Sample Programs c++

    74/78

    By comparing string o-Zects; we can write our password chec0erY4include 5iostream64include 5string6using namespace std/

    int main 789string password/cout 55 =!nter your password? = 55 =Fn=/getline7 cin; password; VFnV 8/if 7 password HH =3y__y= 8 9 cout 55 =$ccess allowed= 55 =Fn=/ @ else

     9 cout 55 =Bad password. #enied accessY= 55 =Fn=/ returning is a conenito stop the program return A/ @ continue onwardY@

  • 8/9/2019 01 Sample Programs c++

    75/78

    Lets loo0 at an e3ample of using Boolean and to create a passwordprogram that chec0s for -oth ausername and a password.4include 5iostream6

  • 8/9/2019 01 Sample Programs c++

    76/78

    4include iostream4include 5string6using namespace std/int main 789

    string username/string password/cout 55 =!nter your username? = 55 =Fn=/getline7 cin; username; VFnV 8/cout 55 =!nter your password? = 55 =Fn=/getline7 cin; password; VFnV 8/if 7 username HH =root= EE password HH =3y__y= 8 $le3 $llain 7www.cprogramming.com8 NX 9 cout 55 =$ccess allowed= 55 =Fn=/ @ else 9 cout 55 =Bad username or password. #enied accessY= 55 =Fn=/ returning is a conenient way to stop the program return A/ @ continue onwardY@

    O 'I%# (! ROOS O' $ *$#R$IC !*$IO%R!*R%

    O I%#!G

  • 8/9/2019 01 Sample Programs c++

    77/78

     O I%#!G4include5iostream.h64include5conio.h64include5math.h6

    4include5process.h6oid main789oat a;-;c;root:;root

  • 8/9/2019 01 Sample Programs c++

    78/78

    deltaH7-1-87K1a1c8/if7delta5A8cout55=FnI+$&I%$R $%#CO+PL!G ROOS.=/else if 7delta6A8

    9root:H7-"s2rt7delta887