10
ASSIGNMENT : C++ PROGRAMMING 1. Who is Written C++ ? Bjarne Stroustrup Bjarne Stroustrup , a Danish computer scientist, began his work on C++'s predecessor "C with Classes" in 1979The motivation for creating a new language originated from Stroustrup's experience in programming for his Ph.D. thesis. Stroustrup found that Simula had features that were very helpful for large software development, but the language was too slow for practical use, while BCPL was fast but too low-level to be suitable for large software development. When Stroustrup started working in AT&T Bell Labs , he had the problem of analyzing the UNIX kernel with respect to distributed computing . Remembering his Ph.D. experience, Stroustrup set out to enhance the C language with Simula -like features. C was chosen because it was general-purpose, fast, portable and widely used. As well as C and Simula's influences, other languages also influenced C++, including ALGOL 68 , Ada , CLU and ML .

ASSIGNMENT c++

Embed Size (px)

DESCRIPTION

ASSIGNMENT c++

Citation preview

ASSIGNMENT : C++ PROGRAMMING

1. Who is Written C++ ?

Bjarne Stroustrup

Bjarne Stroustrup, a Danish computer scientist, began his work on C++'s predecessor "C with Classes" in 1979The motivation for creating a new language originated from Stroustrup's experience in programming for his Ph.D. thesis. Stroustrup found that Simula had features that were very helpful for large software development, but the language was too slow for practical use, while BCPL was fast but too low-level to be suitable for large software development. When Stroustrup started working in AT&T Bell Labs, he had the problem of analyzing the UNIX kernel with respect to distributed computing. Remembering his Ph.D. experience, Stroustrup set out to enhance the C language with Simula-like features. C was chosen because it was general-purpose, fast, portable and widely used. As well as C and Simula's influences, other languages also influenced C++, including ALGOL 68, Ada, CLU and ML.

2. State statements below and give an example application in C++ Program.

a. Go toGoto statement is used for unconditional jump, makes difficult to trace the control flow of program and should be avoided in order to make smoother program.

EXAMPLE:

b. While

The test of expression takes place before each execution of the loop; therefore, a while loop executes zero or more times. expression must be of an integral type, a pointer type, or a class type with an unambiguous conversion to an integral or pointer type .A while loop can also terminate when a break , go to, or return within the statement body is executed. Use continue to terminate the current iteration without exiting the while loop.  continue passes control to the next iteration of the while loop.

EXAMPLE:

c. Break and Continue

BREAKIn C++ break statement is used for the termination of the loop statement and switch case statement. Below is the syntax of the break statement.

EXAMPLE:

CONTINUEThe continue statement forces the next iteration of the loop to take place, skippingremaining code in between.

In the case of the for loop as soon as after the execution of continue statement, increment/decrement statement of the loop gets executed. After the execution of increment statement, condition will be checked.

In case of the while loop, continue statement will take control to the condition statement.

In case of the do.while loop, continue statement will take control to the condition statement specified in the while loop.

EXAMPLE:

WHILE TRUEThis is commonly called "infinite loop". Yet it is not technically infinite - it will stop once control flows through break.

EXAMPLE:

DO / WHILEThe test of the termination condition is made after each execution of the loop; therefore,

a do-while loop executes one or more times, depending on the value of the termination

expression. The do-while statement can also terminate when a break, go to, or return statement is

executed within the statement body.

JUMP / LOOPA for loop is a repetition control structure that allows you to efficiently write a loop that needs to execute a specific number of times.

IF / ELSEAn if statement can be followed by an optional else statement, which execute when the boolean expression is false.