You are on page 1of 7

ASSIGMENT : C++ PROGRAMMING

QUESTIONS

1.Who is Written C++ ?

Bjarne Stroustrup

Bjarne Stroustrup (Danish: [bjn sd sdb];[2][3] born 30 December 1950) is a


Danish computer scientist, most notable for the creation and development of the widely usedC+
+ programming language.[4] He is a Distinguished Research Professor and holds the College of
Engineering Chair in Computer Science at Texas A&M University,[5] a visiting professor
at Columbia University, and works atMorgan Stanley.[6][7][8]
Bjarne Stroustrup (Danish: [bjn sd sdb];[2][3] born 30 December 1950) is a
Danish computer scientist, most notable for the creation and development of the widely usedC+
+ programming language.[4] He is a Distinguished Research Professor and holds the College of
Engineering Chair in Computer Science at Texas A&M University,[5] a visiting professor
at Columbia University, and works atMorgan Stanley.[6]

[7][8]

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." [11] Stroustrup also
wrote a textbook for the 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.[12][13]He is also a visiting faculty in Computer Science
Department at Columbia University.[14] ITMO University noble doctor since 2013[15]
In 2015, he was made a Fellow [16] of the Computer History Museum for his invention of the C++
programming language.

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


Program .

A)GO TO

B)WHILE

B)WHILE

In this example, a goto statement transfers control to the point labeled stop
when i equals 3. In this example, a goto statement transfers control to the point
labeled stop when i equals 3.

// goto_statement.cpp
#include <stdio.h>
int main()
{
int i, j;
for ( i = 0; i < 10; i++ )
{
printf_s( "Outer loop executing. i = %d\n", i );
for ( j = 0; j < 2; j++ )
{
printf_s( " Inner loop executing. j = %d\n", j );
if ( i == 3 )
goto stop;
}
}
// This message does not print:
printf_s( "Loop exited. i = %d\n", i );
stop:
printf_s( "Jumped to stop. i = %d\n", i );

C)Break and Continue

The following example shows how the continue statement can be used to bypass
sections of code and begin the next iteration of a loop.
// continue_statement.cpp
#include <stdio.h>
int main()
{
int i = 0;
do
{
i++;
printf_s("before the continue\n");
continue;
printf("after the continue, should never print\n");

} while (i < 3);


printf_s("after the do loop\n");
}

continue Statement (C++)


Forces transfer of control to the controlling expression of the smallest enclosing do, for,
or while loop.

Syntax
continue;

Remarks
Any remaining statements in the current iteration are not executed. The next iteration of
the loop is determined as follows:

In a do or while loop, the next iteration starts by reevaluating the controlling


expression of the do or whilestatement.

In a for loop (using the syntax for(init-expr; cond-expr; loop-expr)), the loopexpr clause is executed. Then thecond-expr clause is reevaluated and, depending
on the result, the loop either ends or another iteration occurs.

The following example shows how the continue statement can be used to bypass
sections of code and begin the next iteration of a loop.
// continue_statement.cpp
#include <stdio.h>
int main()
{
int i = 0;
do
{
i++;
printf_s("before the continue\n");
continue;
printf("after the continue, should never print\n");
} while (i < 3);
printf_s("after the do loop\n");

}
before the continue
before the continue
before the continue
after the do loop

See Also
C)WHILE TRUE
8

I often use this code pattern:

while(true) {
//do something
if(<some condition>) {
break;
}
}

Another programmer told me that this was bad practice and that I should replace it with
the more standard:
D)DO / WHILE
The following sample demonstrates the do-while statement:

// do_while_statement.cpp
#include <stdio.h>
int main()
{
int i = 0;
do
{
printf_s("\n%d",i++);
} while (i < 3);
}
F)JUMP / LOOP

How can I use a "goto" statement to break out of a loop


for(i = 0; (i < 9); i++)
{
for(j = 0; j < 9; j++)
{

//cout << " " << Matrix[i][j];


//cout << "i: " << i << endl;
if(Matrix[i][j] == 0)
{
//temp = 10;
[goto] ;
//break;
}

int i,j;
for(i = 0; i < 9; i++)
{
for(j = 0; j < 9; j++)
{
//cout << " " << Matrix[i][j];
//cout << "i: " << i << endl;
if(Matrix[i][j] == 0)
{
//temp = 10;
goto end;
//break;
}
}
}
end:
cout << i << " " << j << endl;

G)IF / ELSE
If the value of expression is nonzero, statement1 is executed. If the optional else is
present, statement2 is executed if the value of expression is zero. expression must be of
arithmetic or pointer type, or it must be of a class type that defines an unambiguous
conversion to an arithmetic or pointer type. (For information about conversions,
seeStandard Conversions.)
In both forms of the if statement, expression, which can have any value except a
structure, is evaluated, including all side effects. Control passes from the if statement to
the next statement in the program unless one of the statements contains
a break, continue, or goto.
The else clause of an if...else statement is associated with the closest
previous if statement in the same scope that does not have a
corresponding else statement.
For this sample to be unambiguous about if...else pairing, uncomment the braces.

// if_else_statement.cpp
#include <stdio.h>

int main()
{
int x = 0;
if (x == 0)
{
printf_s("x is 0!\n");
}
else
{
printf_s("x is not 0!\n"); // this statement will not be executed
}
x = 1;
if (x == 0)
{
printf_s("x is 0!\n"); // this statement will not be executed
}
else
{
printf_s("x is not 0!\n");
}
return 0;
}

x is 0!
x is not 0!

You might also like