Sie sind auf Seite 1von 7

EXERCISE SHEET

ASSIGNMENT IN C++ PROGRAMMING


Questions
1. What is C++?
C++ is a general purpose programming language. It has imperative, object oriented and
generic programming features, while also providing the facilities for low level memory
manipulation.
2. Who is written C++?
Bjarne Stroustrup
o 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,[4] a visiting professor at Columbia University, and works
at Morgan Stanley.

Bjarne Stroustrup
3. Describe the main purpose of the following syntax and grammar
#
o 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.

#include
o Tells the pre-processor to include a standard file

iostream.h
o 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

int main()
o 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.
Function
o Allow to structure program in segment of code to perform individual tasks.

cout
o cout represents the standard output stream in C++, and the meaning of the entire
statement is to insert a sequence of characters.

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

Hello world\n
o 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 of the current line. Though the sequence is
represented by two characters, it takes up only one character's worth of memory space.
Hence the sequence \n is called the newline character. The actual procedure to start a
new line is system-dependent but that is handled by the C++ standard library
transparent to you.

\n
o '\n' is the newline character. When the newline character is output to the console, the
console breaks a new line.

;
o

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 most common
syntax errors is indeed to forget to include some semicolon after a statement)

Return 0
o 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

1.

Add

2.

Subtract

3.

Multiply

4.

Divide

5.

Modulo

Relational Operators
Symbol

Meaning

1.

==

Equal to

2.

!=

Not equal to

3.

<

Less than

4.

>

More than

5.

<=

Less than or equal to

6.

>=

More than or equal to

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


Go To
o A loop statement allows us to execute a statement or group of statements multiple
times and following is the general from of a loop statement in most of the programming
languages.
o A common use of go to is to transfer control to a specific switch-case label or the default
label in a switch statement. The go to statement is also useful to get out of deeply
nested loops.

While
o A while statement conditionally executes a statement zero or more times? As long as a
Boolean test is true.
o To find the first occurrence of a value in an array.

Break And Continue


o Break statement is used to come out the loop. Continue statement is used to continue
the loop but skip the execution of the remaining statements in the loop.
o Use the break keyword to stop the loop and the continue keyword to skip one loop
cycle and continue to the next.

While True
o Executes statement repeatedly until expression evaluates to zero.

Do/While
o Executes a statement repeatedly
(the expression) evaluates to zero.

until

the

specified

termination

condition

Jump/Loop
o Execute a sequence of statements multiple times and abbreviates the code that
manages the loop variable.

If/Else
o An if statement can be followed by an optional else statement, which executes when the
boolean expression is false.

Das könnte Ihnen auch gefallen