c++ hands-on lectures

Upload: shiba-tatsuya

Post on 27-Feb-2018

230 views

Category:

Documents


0 download

TRANSCRIPT

  • 7/25/2019 C++ Hands-on Lectures

    1/23

    C++ HANDS-ON

    LECTURESSource code in c++

  • 7/25/2019 C++ Hands-on Lectures

    2/23

    Lesson 1

    1) //Program: Display Greetings

    2) //Author: Ima Programmer

    3) //Date: August 13 2!1"

    #) $include %iostream&

    ") $include %string&

    ') using namespace std(

    )

    *) int main) ,

    -) cout %% .ello 0orld. %% endl(

    1!) cinget)(

    11) return !(

    12)

  • 7/25/2019 C++ Hands-on Lectures

    3/23

    Lesson 2 Naming Variables

    1) $include %iostream&(

    2) using namespace std(

    3) int main)

    #) ,

    ") int apples(') apples 4 3(

    ) int oranges(

    *) oranges 4 "(

    -)

    cout%%.5here are .%%apples%%. apples.%%endl(1!) cout%%.5here are .%%oranges%%. oranges.%%endl(

    11) cinget)(

    12) return !(

    13)

  • 7/25/2019 C++ Hands-on Lectures

    4/23

    Lesson 3

    1) $include %iostream&(

    2) using namespace std(

    3) int main)

    #) ,

    ") int apples(

    ')

    apples 4 3() int oranges(

    *) oranges 4 "(

    -) int 6ruits(

    1!) 6ruits 4 apples + oranges(

    11)

    12) cout%%.there are .%%apples%%. apples.%%endl(13) cout%%.there are .%%oranges%%. oranges.%%endl(

    1#) cout%%.there are .%%6ruits%%. 6ruit.%%endl(

    1") cinget)(

    1') return !(

    1)

  • 7/25/2019 C++ Hands-on Lectures

    5/23

    Lesson

    1) $include%iostream&

    2) using namespace std(

    3)

    #) int main )") ,

    ') int apples 4 3(

    ) int apples 4 "(

    *) cout%% apples(-) cinget)(

    1!) return !(

    11)

  • 7/25/2019 C++ Hands-on Lectures

    6/23

    Lesson ! "a#$ema#i%alO&era#ors

    1) $include %iostream&

    2) using namespace std(

    3)

    #) int main)") ,

    ') int 8 4 12-(

    ) int y 4 "(

    *) cout%%.5he product is .%%89y(-) cinget)(

    1!) return !(

    11)

  • 7/25/2019 C++ Hands-on Lectures

    7/23

    Lesson ' (loa# an) Do*bleT&e

    1) $include %iostream&

    2) using namespace std(

    3)

    #) int main)

    ") ,') doule ;eight 4 3!!!!!1(

    ) doule < 4 3!!!!!1(

    *) doule total 4 ;eight +

  • 7/25/2019 C++ Hands-on Lectures

    8/23

    Lesson , T$e %inS#a#emen#

    1) $include %iostream&

    2) using namespace std(

    3)

    #) int main)

    ") ,

    ') int 8(

    ) cout%%.>nter an Integer ?alue:.(

    *) cin&&8(

    -) cout%%.@ou hae >ntered .%%8%%endl(

    1!) system.pause.)(

    11) return !(

    12)

  • 7/25/2019 C++ Hands-on Lectures

    9/23

    Lesson T$e C$ar T&e

    1) $include %iostream&

    2) using namespace std(

    3)

    #) int main)") ,

    ') char character 4 BtB(

    ) cout %%character(

    *) cout%%endl(-) system.pause.)(

    1!) return !(

    11)

  • 7/25/2019 C++ Hands-on Lectures

    10/23

    Lesson . T$e /ooleanT&e

    1) $include %iostream&

    2) using namespace std(

    3)

    #) int main)") ,

    ') ool smart 4 true(

    ) cout%%smart(

    *) cout%%endl(-) cinget)(

    1!) return !(

    11)

  • 7/25/2019 C++ Hands-on Lectures

    11/23

    Lesson 10 n#ro)*%#ion #o S#a#emen#

    1) $include %iostream&

    2) using namespace std(

    3) int main)

    #) ,

    ") i6 6alse)

    ') ,

    ) cout%%.i Cy name is .%%endl(

    *) cout%%.0hat is your name.(

    -)

    1!) cinget)(

    11) return !(

    12)

  • 7/25/2019 C++ Hands-on Lectures

    12/23

    Lesson 11 Rela#ionalO&era#ors 4ar# 15

    1) $include %iostream&

    2) using namespace std(

    3)

    #) int main)") ,

    ') ool Eoolean 4 3 4 3(

    )

    cout%%Eoolean(*) cinget)(

    -) return !(

    1!)

  • 7/25/2019 C++ Hands-on Lectures

    13/23

    Lesson 12 Rela#ionalO&era#ors 4ar# 25

    1) $include %iostream&

    2) using namespace std(

    3) int main)

    #) ,

    ") ool Eoolean 4 44)(') i6 Eoolean)

    ) ,

    *) cout%%.5his is 5rue.(

    -)

    1!) cout%%Eoolean(

    11) cinget)(

    12) return !(

    13)

  • 7/25/2019 C++ Hands-on Lectures

    14/23

    Lesson 131) $include %iostream&

    2) using namespace std(

    3) int main)#) ,

    ") int apples ananas(

    ') cout%%.>nter the numer o6 ananas.%%endl(

    ) cin&&ananas(

    *) cout%%.>nter the numer o6 apples.%%endl(

    -) cin&&apples(

    1!) i6 apples%ananas)

    11) ,

    12) cout%%.5here are more ananas .(

    13)

    1#) i6 apples&ananas)

    1") ,

    1') cout%%.5here are more apples .(

    1)

    1*) i6 apples44ananas)

    1-) ,

    2!) cout%%.5he numer o6 apples and ananas are eFual.(

    21)

    22) cout%%endl(

    23) system.pause.)(

    2#) return !(

    2")

  • 7/25/2019 C++ Hands-on Lectures

    15/23

    Lesson 1 Di6eren# VariableT&e

    1) $include %iostream&

    2) using namespace std(

    3)

    #) int main)") ,

    ') int apples43 oranges4" ananas4(

    ) oat cash42* mass4-*1"(

    *) cout%%mass/apples%%endl%%cash9apples(-) cinget)(

    1!) return !(

    11)

  • 7/25/2019 C++ Hands-on Lectures

    16/23

    Lesson 1! ElseS#a#emen#

    1) $include %iostream&

    2) using namespace std(

    3)

    #) int main)

    ") ,

    ') int apples4" oranges43(

    ) i6 apples % oranges)(

    *) ,

    -) cout%%.more oranges.%%endl(

    1!)

    11) else

    12) ,

    13) cout%%.more apples.%%endl(

    1#)

    1") cinget)(

    1') return !(

    1)

  • 7/25/2019 C++ Hands-on Lectures

    17/23

    Lesson 1' n%remen#De%remen#

    1) $include %iostream&

    2) using namespace std(

    3)

    #) int main)") ,

    ') int rocHs4" coins41(

    ) coins 4 rocHs+3(

    *) cout%%coins(-) cinget)(

    1!) return !(

    11)

  • 7/25/2019 C++ Hands-on Lectures

    18/23

    n%remen# De%remen#1) $include %iostream&

    2) using namespace std(

    3)

    #) int main)

    ") ,

    ') int rocHs4" coins41(

    ) char choice 4 J(

    *) cout%%K0ould you liHe to uy a rocH 6or 1 coinL(

    -) cin&&choice(

    1!) i6 choice44yJ)11) ,

    12) coins 4 coins M 1

    13) rocHs 4 rocHs +1

    1#) cout%%K5hanH youL

    1")

    1') else

    1) ,1*) cout%%K5hatJs too adL(

    1-)

    2!) cout%%endl%%Kcoins: K%%coins%%endl(

    21) cout%%KrocHs: L%%endl(

    22) systemKpauseL)(

    23) return !(

    2#)

  • 7/25/2019 C++ Hands-on Lectures

    19/23

    n%remen# De%remen#

    1) $include %iostream&

    2) using namespace std(

    3)

    #) int main)") ,

    ') int N 4 (

    ) N +4 "(

    *) cout%%N(-) cinget)(

    1!) return !(

    11)

  • 7/25/2019 C++ Hands-on Lectures

    20/23

    T$e 7$ile loo&

    1) $include %iostream&

    2) using namespace std(

    3)

    #) int main)

    ") ,') int n4!(

    ) ;hilen%4")

    *) ,cout%% n %%endl(

    n 4 n + 1(-)

    1!) cinget)(

    11) return !(

    12)

  • 7/25/2019 C++ Hands-on Lectures

    21/23

    7$ile loo&$include %iostream&

    using namespace std(

    int main),

    int 8(

    char choice 4 yJ(

    ;hile choice 44 yJ)

    ,

    cout%%K>nter an integer alue 6or 8: L(

    cin&& 8(i6 8O2 44 !)

    ,

    cout%%K>enL%%endl(

    else

    ,

    cout%%KddL%%endl(

    cout%%K0ould you liHe to enter another alue %y/n&L(

    cin&&choice

    system KpauseL)(

    return !(

  • 7/25/2019 C++ Hands-on Lectures

    22/23

    7$ile loo&1) $include %iostream&

    2) using namespace std(

    3) int main)

    #) ,

    ") int loop 4 !(') oat numer sum 4 !(

    ) char choice 4 yJ(

    *)

    -) ;hile choice 44 yJ QQ choice 44 @J)

    1!) ,

    11) cout%%K>nter a numer: L(

    12) cin&&numer(

    13) sum +4 numer(

    1#) loop++(

    1") cout%%K>nter another numer %y/n& L(

    1') cin&&choice(1)

    1*) cout%%Kthe sum o6 all numer is: L%%sum%%endl(

    1-) cout%%Kaerage: L%%sum/loop%%endl(

    2!) system KpauseL)(

    21) return !(

    22)

  • 7/25/2019 C++ Hands-on Lectures

    23/23

    Logi%al O&era#ors

    1) $include %iostream&

    2) using namespace std(

    3)

    #) int main)

    ") ,

    ') int a41 c4*(

    ) cout%%Kenter a alue that is not et;een L%% a %%Kand K%% c%%endl(

    *) cin%% (

    -) i6 a& QQ &c)

    1!) ,

    11) cout%%KcorrectL%%endl(12)

    13) system KpauseL)(

    1#) return !(

    1")