8/10/2019 Assignment in C++ Programming
http://slidepdf.com/reader/full/assignment-in-c-programming 1/7
8/10/2019 Assignment in C++ Programming
http://slidepdf.com/reader/full/assignment-in-c-programming 2/7
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 anew 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.
8/10/2019 Assignment in C++ Programming
http://slidepdf.com/reader/full/assignment-in-c-programming 3/7
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
8/10/2019 Assignment in C++ Programming
http://slidepdf.com/reader/full/assignment-in-c-programming 4/7
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.
8/10/2019 Assignment in C++ Programming
http://slidepdf.com/reader/full/assignment-in-c-programming 5/7
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.
8/10/2019 Assignment in C++ Programming
http://slidepdf.com/reader/full/assignment-in-c-programming 6/7
Do/While
o Executes a statement repeatedly until the specified termination condition
(the expression) evaluates to zero.
Jump/Loop
o
Execute a sequence of statements multiple times and abbreviates the code that
manages the loop variable.
8/10/2019 Assignment in C++ Programming
http://slidepdf.com/reader/full/assignment-in-c-programming 7/7
If/Else
o An if statement can be followed by an optional else statement, which executes when the
boolean expression is false.