Вы находитесь на странице: 1из 7

ASSIGMENT: C++ PROGRAMMING

QUESTIONS
1.Who is Written C++

Bjarne Stroustrup, a Danish computer scientist, began his work on C++'s predecessor "C
with Classes" in 1979. The 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.[7] 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.
Initially, the class, derived class, strong typing, inlining and default argument features were added
to C via Stroustrup's "C with Classes" to C compiler, Cpre.
In 1983, it was renamed from C with Classes to C++ ("++" being the increment operator in C).
New features were added including virtual functions, function name and operator overloading,
references, constants, type-safe free-store memory allocation (new/delete), improved type
checking, and BCPL style single-line comments with two forward slashes ( // ), as well as the
development of a proper compiler for C++, Cfront.
In 1985, the first edition of The C++ Programming Language was released, which became the
definitive reference for the language, as there was not yet an official standard. The first
commercial implementation of C++ was released in October of the same year.]
In 1989, C++ 2.0 was released, followed by the updated second edition of The C++
Programming Language in 1991.[10] New features in 2.0 included multiple inheritance, abstract
classes, static member functions, const member functions, and protected members. In

1990, The Annotated C++ Reference Manual was published. This work became the basis for the
future standard. Later feature additions included templates, exceptions, namespaces, new casts,
and a boolean type.
After the 2.0 update, C++ evolved relatively slowly. In 2011, the C++11 standard was released,
adding numerous new features, enlarging the standard library further, and providing more
facilities to C++ programmers. After a minor C++14 update, released in December 2014, various
new additions are planned for 2017.

2.State statements below and give an example application


in C++ Program.
a.Go To
A goto statement provides an unconditional jump from the goto to a labeled
statement in the same function.
goto label;
..
.
label: statement;

b.While
A while loop statement repeatedly executes a target statement as long as a
given condition is true.
while(condition)
{
statement(s);
}

c.Break and Continue


The continue statement works somewhat like the break statement.
Instead of forcing termination, however, continue forces the next
iteration of the loop to take place, skipping any code in between.
For the for loop, continue causes the conditional test and increment
portions of the loop to execute. For the while and do...while loops,
program control passes to the conditional tests.
#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;
}

The break statement has the following two usages in C++:

When the break statement is encountered inside a loop, the loop is


immediately terminated and program control resumes at the next statement
following the loop.

It can be used to terminate a case in the switch statement (covered in the


next chapter).

If you are using nested loops (i.e., one loop inside another loop), the
break statement will stop the execution of the innermost loop and start
executing the next line of code after the block.
#include <iostream>
using namespace std;

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

#include <iostream>
using namespace std;

int main() {
int number, i = 1, factorial = 1;
cout<< "Enter a positive integer: ";
cin >> number;

while ( i <= number) {


factorial *= i;

//factorial = factorial * i;

++i;
}

cout<<"Factorial of "<<number<<" = "<<factorial;


return 0;
}
The while loop checks whether the test expression is true or not. If it is true, code/s
inside the body of while loop is executed,that is, code/s inside the braces { } are
executed. Then again the test expression is checked whether test expression is true or
not. This process continues until the test expression becomes false.

E ) Do / While :

do {
statement/s;
}
while (test expression);

The statement/s inside body of loop is executed at least once, that is, the statement/s inside
braces { } is executed at least once. Then the test expression is checked. If the test expression
is true, the body of loop is executed. This process continues until the test expression becomes
false. Since the body of loop is placed before the test expression in do...while loop, the body
of loop is executed at least once.

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.
do
{
statement(s);
}while( condition );

f.Jump/Loop
for(initialization statement; test expression; update statement) {
code/s to be executed;
}

The initialization statement is executed only once at the beginning of the for loop.
Then the test expression is checked by the program. If the test expression is false, for
loop is terminated. But if test expression is true then the code/s inside body of for loop
is executed and then update expression is updated. This process repeats until test
expression is false.

g.if/else
An if statement can be followed by an optional else statement, which
executes when the boolean expression is false.
if(boolean_expression)
{
// statement(s) will execute if the boolean expression is true
}
else
{
// statement(s) will execute if the boolean expression is false
}

Вам также может понравиться