Assignment in C++ Programming Questions 1. What Is C++: Bjarne Stroustrup (Born 30 December 1950) Is A Danish

You might also like

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

Assignment In C++ Programming

Questions
1. What is C++
C++ is an object oriented programming (OOP) language, developed by Bjarne Stroustrup,
and is an extension of C language. It is therefore possible to code C++ in a "C style" or
"object-oriented style." In certain scenarios, it can be coded in either way and is thus an
effective example of a hybrid language.
C++ is a general purpose object oriented programming language. It is considered to be an
intermediate level language, as it encapsulates both high and low level language features.
Initially, the language was called 'C with classes as it had all properties of C language with
an additional concept of 'classes. However, it was renamed to C++ in 1983. It is pronounced
"C-Plus-Plus."
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. Describe the purpose of the following Syntax and Grammar

#
A hash sigh are directives for the per-processor

#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 <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.

iostream.h
input output stream header file Provides functionality to use an abstraction
called streams specially designed to perform input and output operations on
sequences of character, like files or strings.Objects cin, cout are from
iostream header

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. The word main is
followed in the code by a pair of parentheses (()). That is because it is a
function declaration: In C++, what differentiates a function declaration from
other types of expressions are these parentheses that follow its name.
Optionally, these parentheses may enclose a list of parameters within
them. Right after these parentheses we can find the body of the main function
enclosed in braces ({}). What is contained within these braces is what the
function does when it is executed.

function
Allow to structure programs in segments of code to perform individual tasks.

cout
cout represents the standard output stream in C++, and the meaning of the
entire statement is to insert a sequence of characters (in this case the Hello
World sequence of characters) into the standard output stream (which usually
is the screen). cout is declared in the iostream standard file within the std
namespace, so that's why we needed to include that specific file and to
declare that we were going to use this specific namespace earlier in our
code.

<<
The bitwise left shift to shifts operator bits to the left.

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.

\n
Moves the active position to the initial position of the next line.

;
The separation between statements is specified with an ending semicolon at
the end of each one sentences.

return0
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
Symbol
Meaning

Relational Operators
Symbol
Meaning
(<)

Less than

Division

1
2
3

(>)
(<=)

Greater than
Less than or equal
to

Multiply

(>=)

Greater than or
equal to

+=

add and assign

==

Equality

!=

Inequality

1
2
3

+
/

add
subtract

4
5

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


a) Go to
Allow 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
thee same block of statements, especially in the presence of local variables.

b) While
Conditionally executes a statement zero or more times? As long as a
Boolean test is true.

c) Break and Continue


- 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 forceit to end before its natural end. For
example, lets stop the countdown before its natural end:
-

The continue statement cause the program to skip the rest of the loop in the
current iteration, as if the end of the statement block had beenreached,
causing it to jump to the start of the following iteration.

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

e) Do/While
- Do statement conditionaly executes a statement one or more times.
- For statement evaluates a sequence of initialization expressions and then,
while a condition is true, repeatedly executes a statement and evaluates a
sequence of iteration expressions
f) Jump/Loop
- Loop repeat a statement a certain number of times, or white a condition is
fulfilled . They are introduced by the keywords while, do , and for.
- Jump statements allow altering the flow of a program by performing jumps to
specific location.

g) If/else
- If statement selects a statement for execution base on the value of a Boolean
expression. An if statement may optionally include an else clause that
executes if the Boolean expression is false
- 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.

You might also like