Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 6

ASSIGNMENT IN C++ PROGRAMMING

QUESTIONS
1. what is C++
C++ is a powerful general-purpose programming language. It can beused to create small
programs or large applications. It can be used to make CGI scripts or console-only DOS
programs. C++ allows you to create programs to do almost anything you need to do.
2. Who is written C++

BJARNE STROUSTRUP
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. Describe the purpose of the following Syntax and Grammar
a) #
- A hash sign (#) are directives for the pre-processor.
b) #include
- The directive #include tells the pre-processor to include a standard file
c) iostream.h
- 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 <iostream> tells the preprocessor to include the iostream
standard file. This specific file (iostream) includes the declarations of the basic standard

input-output library in C++, and it is included because its functionality is going to be used
later in the program.

d) int main()
- This line corresponds to the beginning of the definition of the main function. The main
function is the point by where all C++ programs start their execution, independently of its
location within the source code. It does not matter whether there are other functions with
other names defined before or after it - the instructions contained within this function's
definition will always be the first ones to be executed in any C++ program. For that same
reason, it is essential that all C++ programs have a main function.
e) function
- A function is a block of code that has a name and it has a property that it is reusable i.e. it
can be executed from as many different points in a C Program as required.
f) count
- The standard output, normally the screen.
g) <<
- The bitwise left shift (<<) shifts operator bits to the left.
h) Hello World\n;
- This line is a C++ statement. A statement is a simple or compound expression that can
actually produce some effect. In fact, this statement performs the only action that generates
a visible effect in our first program.
i) \n
- (new line) Moves the active position to the initial
position of the next line.
j) ;
- the separation between statements is specified with an ending semicolon (;) at the end of
each one, so the separation in different code lines does not matter at all for this purpose.
k) 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 any
errors during its execution. This is the most usual way to end a C++ console program.
4. Give 5 mathematical operators and 6 relational operators:

MATHEMATICAL OPERATORS
1
2
3
4
5

Symbol

Meaning

addition

subtraction

multiplication

division

modulo

RELATIONAL OPERATORS
Symbol
1
2
3
4
5
6

Meaning

==

Equal to

!=

Not equal to

<

Less than

>

Greater than

<=

Less than or equal to

>=

Greater than or equal to

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

a. Go to
goto allows to make an absolute jump to another point in the program. This unconditional
jump ignores nesting levels, and does not cause any automatic stack unwinding. Therefore, it is
a feature to use with care, and preferably within the same block of statements, especially in the
presence of local variables.

b. While
- while loop repeated until condition becomes false.
- Programmer specifies an action to be repeated while some condition remains true.

c. Break and Continue


The break statement
break leaves a loop, even if the condition for its end is not fulfilled. It can be used to end an
infinite loop, or to force it to end before its natural end. For example, let's stop the countdown
before its natural end:

The continue statement


The continue statement causes the program to skip the rest of the loop in the current iteration,
as if the end of the statement block had been reached, causing it to jump to the start of the
following iteration. For example, let's skip number 5 in our countdown:

d. While True
A while(true) statement repeatedly executes a target statement as long as a given condition is
true.

e. Do / While
The do/while repetition structure is similar to the while structure,
- Condition for repetition tested after the body of the loop is executed
- This prints the integers from 1 to 10

f. Jump / loop
Loops repeat a statement a certain number of times, or while a condition is fulfilled. They are
introduced by the keywords while, do, and for.

g. If / else
if (condition) statement

Where condition is the expression that is being evaluated. If this condition is true, statement is
executed. If it is false, statement is ignored (not executed) and the program continues right
after this conditional structure. For example, the following code fragment prints x is 100 only if
the value stored in the x variable is indeed 100:

if (condition) statement1 else statement2


prints on the screen x is 100 if indeed x has a value of 100, but if it has not -and only if not- it
prints out x is not 100.

You might also like