Professional Documents
Culture Documents
Questions 1.: Assignment: C++ Programming
Questions 1.: Assignment: C++ Programming
QUESTIONS
1. Who is written C++
Bjarne Stroustrup
Bjarne Stroustrup is a Danish computer scientist, most notable for
the creation and development of the widely used C++ programming
language. He is a Distinguished Research Professor and holdsAt the
College of Engineering Chair in Computer Science at Texas A&M
University, a visiting professor at Columbia University, and works
at Morgan Stanley.
Born at December 30, 1950 (age 64), Aarhus, Denmark.
Education learning at Aarhus University, Churchill College,
Cambridge, University of Cambridge.
Live at New York City, New York, United States.
Has been reward a Grace Murray Hopper Award.
int main ()
{
// Local variable declaration:
int a = 10;
// do loop execution
LOOP:do
{
if( a == 15)
{
// skip the iteration.
a = a + 1;
goto LOOP;
}
cout << "value of a: " << a << endl;
a = a + 1;
}while( a < 20 );
return 0;
}
b) WHILE
A while loop statement repeatedly executes a target
statement as long as a given condition is true.
#include <iostream>
using namespace std;
int main ()
{
// Local variable declaration:
int a = 10;
return 0;
}
#include <iostream>
using namespace std;
int main ()
{
// Local variable declaration:
int a = 10;
// do loop execution
do
{
if( a == 15)
{
// skip the iteration.
a = a + 1;
continue;
}
cout << "value of a: " << a << endl;
a = a + 1;
}while( a < 20 );
return 0;
}
II. BREAK
The break statement has the following two usages in C++:
int main ()
{
// Local variable declaration:
int a = 10;
// do loop execution
do
{
cout << "value of a: " << a << endl;
a = a + 1;
if( a > 15)
{
// terminate the loop
break;
}
}while( a < 20 );
return 0;
}
d) WHILE TRUE
unconditional loop
while( true ) {
doSomething();
if( condition() ) {
break;
}
doSomethingElse();
}
e) DO / WHILE
Unlike for and while loops, which test the loop condition at
the top of the loop, the do...while loop checks its condition at
the bottom of the loop.
A do...while loop is similar to a while loop, except that a
do...while loop is guaranteed to execute at least one time.
The syntax of a do...while loop in C++ is:
// 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");
}
f) JUMP / LOOP
A C++ jump statement performs an immediate local transfer of
control.
break;
continue;
return [expression];
goto identifier;
g) IF / ELSE
if(boolean_expression)
{
// statement(s) will execute if the boolean expression is true
}
else
{
// statement(s) will execute if the boolean expression is false
}