You are on page 1of 6

ASSIGNMENT IN C++ PROGRAMMING

1. What is C ++ ?
C++ adds object-oriented features to its predecessor, C. C++ is one of
the most popular programming languages for graphical applications, such
as those that run in Microsoft Windows and Apple Macintosh
environments. C++ is named after C's increment operator. Below is an
example of a C++ program that prints Hello World!.

2. Who is written C++ ?

Bjarne Stroustrup , born 30 December 1950) 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 holds the College of
Engineering Chair in Computer Science at Texas A&M University, a visiting
professor at Columbia University , and works at Morgan Stanley.

3. Describethe purpose of the following syntaxand grammar


A. #
-

Lines beginning with a hash sign (#) are directives for the preprocessor. They are not regular
code lines with expressions but indications for the compilers preprocessor.

B. #include
-

Lines beginning with a hash sign (#) are directives for the preprocessor. They are not regular
code lines
with expressions but indications for the compiler's preprocessor. In this case the directive
#include

C. Iostream.h
-

Usually the compiler inserts the contents of a header file called iostream into the program.
Where it puts it depends on the system. The location of such files may be described in your
compiler's documentation. A list of standard C++ header files is in the standrat headers
reference

D. Int main ()
-

The main function is the point by where all C++ programs start their execution,
independently of its location within the source code. For that same reason, it is essential that
all C++ programs have a main function.The word main is followed in the code by a pair of
parentheses ()

E. Function
-

Allow to structure program in segment of code to perform individual tasks.

F. <<
-

The << operator inserts the data that follows it into the stream that preceds it .

G. Hello world\n
-

This line is a c++ statement. C++ strings are enclosed within double quotes (). The quotes
themselves are not part of the string and hence not printed. The sequence \n is used within a
string to indicate the end current line. Though the sequence is represented by two
characters , it takes up only one characters worth of memory space. Hence the sequence \n
is called the newline character.

H. \n
-

\n is the newline character, when the newline character is output to the console, the
console breaks a newline.

I. ;
-

This character is used to mark the end of the statement and in fact it must be included at the
end of all expression statements in all c++ programs (one of the mostcommon syntax errors
is indeed to forget to include some semicolon after a statement )

J. return 0;
-

The return statement causes the main function to finish . return may be followed by a return
code (in our example is followed by the return code 0), a return code of 0 for the main
function is generally interpreted as the program worked as expected without

4. GIVE 5 MATHEMATICAL OPERATORS AND 6 RELATIONAL OPERATES.


RELATION OPERATIONAL
SYMBOL
1)
2)
3)
4)
5)
6)

==
>
<
!=
>=
<=

MEANING
EQUAL TO
GREATER THAN
LESS THAN
NOT EQUAL TO
GREATER THAN OR EQUAL TO
LESS THAN OR EQUAL TO

MATHEMATIC AL OPERATES
SYMBOL
1)
2)
3)
4)
5)

+
*
/
%

MEANING
ADDITION OR UNRY PLUS
SUBTRACTION OR UNARY MINUS
MULTIPLICATION
DIVISION
REMAINDER AFTER DIVISION

5. STATE STATEMENTS BELOW AND GIVE AND EXAMPLE APPLICATION IN C++


PROGRAM

A. Go to
-

The goto statement is a control flow statement that causes the CPU to jump to
another spot in the code. This spot is identified through use of a statement label.

// 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 );
}

B. W
h
i
l
e

a)
b)
c)
d)
e)
f)
g)
h)
i)
j)

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

C. Break and Continue


intnPrinted = 0;

C) 1
D) 2
E) 3
F) 4
G) 5
H) 6
I) 7
J) 8
K) 9
L) 10
M) 11
N) 12
O) 13

for(intiii=0; iii < 100; iii++)


{
// messy!
if((iii % 3) && (iii % 4))
{
cout<< iii <<endl;
nPrinted++;
}
}

cout<<nPrinted<< " numbers were found"<<endl;

However, this can be rewritten as the following, which is easier to read:

1
intnPrinted = 0;

2
3
4

for(intiii=0; iii < 100; iii++)


{

// if the number is divisible by 3 or 4, skip this iteration

if((iii % 3)==0 || (iii % 4)==0)


continue;

7
8

cout<< iii <<endl;

nPrinted++;

10
}

11
12

cout<<nPrinted<< " numbers were found"<<endl;

13

D. While true
-

Excutes statements repeatedly until the spectified termination condition evaluates

E. Do/While
-

Excutes statements repeatedly until the spectified termination condition the


evaluates to zeros

F. Jump/Loop
-

Exucutes a sequence of statements multiple times and abbreviates the code that
manages the loop variable.

G. If/else
-

An if statements can be followed by an optional else statements , which executes


when the boolen expression if false

You might also like