assignment c++ (muhammad rymi bin mohd rafizal)

Upload: muhammad-rymi

Post on 06-Jul-2018

226 views

Category:

Documents


0 download

TRANSCRIPT

  • 8/17/2019 Assignment C++ (MUHAMMAD RYMI BIN MOHD RAFIZAL)

    1/6

    1.Who is Written C++ ?

    BJARNE STROUSTRUP

    Stroustrup began developing C++ in 1978 (then called "C with Classes"), and, in his own

    words, "invented C++, wrote its early definitions, and produced its first implementation...

    chose and formulated the design criteria for C++, designed all its major facilities, and was

    responsible for the processing of extension proposals in the C++ standards

    committee. Stroustrup also wrote a textbook for the language, The C++ Programming

    Language. 

    Stroustrup was the head of AT&T Bell Labs’ Large-scale Programming Research

    department, from its creation until late 2002. Stroustrup was elected member of the National

     Academy of Engineering in 2004. He is a Fellow of the ACM (1994) and an IEEE Fellow. He

    works at Texas A&M University as a Distinguished Professor where he holds the College of

    Engineering Endowed Chair in Computer Science. He is also a visiting faculty in Computer

    Science Department at Columbia University. TMO University noble doctor since 2013

    In 2015, he was made a Fellow of the Computer History Museum for his invention of the C++

    programming language.

    2.a) Go to

     A goto statement used as unconditional jump from the goto to a labeled statement in the

    same function. 

    Syntax:

    https://en.wikipedia.org/wiki/C_(programming_language)https://en.wikipedia.org/wiki/C_(programming_language)https://en.wikipedia.org/wiki/C_(programming_language)https://en.wikipedia.org/wiki/C_(programming_language)

  • 8/17/2019 Assignment C++ (MUHAMMAD RYMI BIN MOHD RAFIZAL)

    2/6

     

    Example #1 Go to statement :

    Output :

    Different type of go to :

  • 8/17/2019 Assignment C++ (MUHAMMAD RYMI BIN MOHD RAFIZAL)

    3/6

    b) While

    While ( condition ) { Code to execute while the condition is true } The true represents a

    boolean expression which could be x == 1 or while ( x != 7 ) (x does not equal 7). It can be

    any combination of Boolean statements that are legal. Even, (while x ==5 || v == 7) which

    says execute the code while x equals five or while v equals 7. Notice that a while loop is thesame as a for loop without the initialization and update sections. However, an empty

    condition is not legal for a while loop as it is with a for loop.

    Example :

    c) Break and Continue

    It causes the execution flow to jump around and because it can make the flow of logic

    harder to follow

    Example :

  • 8/17/2019 Assignment C++ (MUHAMMAD RYMI BIN MOHD RAFIZAL)

    4/6

    d) While True 

    I'm curious about using a while statement with a true condition. What is the advantage of

    using a while(true) statement with break to exit the while statement over something like a for

    loop? I guess I'm just curious when a good time to use this technique would be? I saw it

    demonstrated in a quick sort algorithm at school today and was just curious about it. Insight?

    Example :

    e) Do \ White

    The do...while Loop is similar to while loop with one very important difference. In

    while loop, check expression is checked at first before body of loop but in case of

    do...while loop, body of loop is executed first then only test expression is checked.

    That's why the body of do...while loop is executed at least once.

    Example :

  • 8/17/2019 Assignment C++ (MUHAMMAD RYMI BIN MOHD RAFIZAL)

    5/6

    f) Jump \ Loop

    Cause a certain piece of program to be executed a certain number oftimes. Consider these scenarios:

      You want to execute some code/s certain number of time.

      You want to execute some code/s certain number of times depending upon

    input from user.

    Example :

    Output :

  • 8/17/2019 Assignment C++ (MUHAMMAD RYMI BIN MOHD RAFIZAL)

    6/6

    g) If \ Else

    The if...else executes body of if when the test expression is true and executes the

    body of else if test expression is false.

    Example :