Algorithm
Algorithm is a step-by-step procedure developed to
solve a problem before writing an actualprogram.
Algorithm is a complete procedure or plan that
describes the logic of aprogram.
Flow Charting
Symbols
Flow line: A line with an arrow head represents the
flow of control between various symbols in a
flow chart.
• Terminal symbol:
start Stop
• Input/output Symbol
Decision making in
C++
Decision making is about deciding the order of execution
of statements based on certain conditions or repeat agroup
of statements until certain specified conditions aremet.
C++handles decision-making by supporting the following
statements,
if statement
switch statement
conditional operator statement
goto statement
Decision making with If
statement
The if statement may be implemented in different
forms depending on the complexity of conditions tobe
tested. The different formsare,
Simple if statement
If....else statement
Nested if....else statement
else if statement
Simple if statement
The general form of a simple if statement is,
if (expression
{
statement-inside;
{
statement -outside;
If the expression is true, then 'statement-inside' it will be
executed, otherwise 'statement-inside' is skipped and
only 'statement-outside' is executed.
Example
:#include< iostream.h>
int main( )
{
int x,y;
x=15;
y=13;
if (x >y )
{
cout <<"x is greater thany";
getch();
}
If..else statement
The general form of a simple if...else statement is,
if( expression )
{
statement-block1;
{
else
{
statement-block2;
}
If the 'expression' is true, the 'statement-block1' is executed, else
'statement-block1' is skipped and 'statement-block2' is executed.
Example
:void main( )
{
int x,y;
x=15;
y=18;
if (x >y )
{
cout <<"x is greater thany";
}
else {cout <<"y is greater than x";
}
}
Nested if....else
statement
The general form of a nested if...else statement is,
if( expression )
{
if( expression1 )
{
statement-block1;
}
Else
{
statement-block 2;
}
}
else
{
statement-block 3;
}
if 'expression' is false the 'statement-block3' will be executed, otherwise it continues to perform the test
for 'expression 1'. If the 'expression 1'is true the 'statement-block1' is executed otherwise 'statement-
block2' is executed.
Switch
statement
. switch statement :- this is multiple conditional
statement switch check the condition if condition is true
then perform the statement and totally depend upon the
value of variable otherwise perform the defaultstatement
Prototype :- switch < expression>
Case <statement >
Case <statement >
Case <statement >
Case <statement >
default <statement >
Go to
statement
A go to statement provides an unconditional jump from the goto
to a labeled statement in the samefunction.
SYNTAX :
The syntax of a go to statement in C++is:
go to label;
..
.
label: statement;
Where label is an identifier that identifies a labeled
statement. A labeled statement is any statement thatis
preceded by an identifier followed by a colon (:).
Flow
chart

C statements

  • 2.
    Algorithm Algorithm is astep-by-step procedure developed to solve a problem before writing an actualprogram. Algorithm is a complete procedure or plan that describes the logic of aprogram.
  • 3.
    Flow Charting Symbols Flow line:A line with an arrow head represents the flow of control between various symbols in a flow chart. • Terminal symbol: start Stop • Input/output Symbol
  • 4.
    Decision making in C++ Decisionmaking is about deciding the order of execution of statements based on certain conditions or repeat agroup of statements until certain specified conditions aremet. C++handles decision-making by supporting the following statements, if statement switch statement conditional operator statement goto statement
  • 5.
    Decision making withIf statement The if statement may be implemented in different forms depending on the complexity of conditions tobe tested. The different formsare, Simple if statement If....else statement Nested if....else statement else if statement
  • 6.
    Simple if statement Thegeneral form of a simple if statement is, if (expression { statement-inside; { statement -outside; If the expression is true, then 'statement-inside' it will be executed, otherwise 'statement-inside' is skipped and only 'statement-outside' is executed.
  • 7.
    Example :#include< iostream.h> int main() { int x,y; x=15; y=13; if (x >y ) { cout <<"x is greater thany"; getch(); }
  • 8.
    If..else statement The generalform of a simple if...else statement is, if( expression ) { statement-block1; { else { statement-block2; } If the 'expression' is true, the 'statement-block1' is executed, else 'statement-block1' is skipped and 'statement-block2' is executed.
  • 9.
    Example :void main( ) { intx,y; x=15; y=18; if (x >y ) { cout <<"x is greater thany"; } else {cout <<"y is greater than x"; } }
  • 10.
    Nested if....else statement The generalform of a nested if...else statement is, if( expression ) { if( expression1 ) { statement-block1; } Else { statement-block 2; } } else { statement-block 3; } if 'expression' is false the 'statement-block3' will be executed, otherwise it continues to perform the test for 'expression 1'. If the 'expression 1'is true the 'statement-block1' is executed otherwise 'statement- block2' is executed.
  • 11.
    Switch statement . switch statement:- this is multiple conditional statement switch check the condition if condition is true then perform the statement and totally depend upon the value of variable otherwise perform the defaultstatement Prototype :- switch < expression> Case <statement > Case <statement > Case <statement > Case <statement > default <statement >
  • 12.
    Go to statement A goto statement provides an unconditional jump from the goto to a labeled statement in the samefunction. SYNTAX : The syntax of a go to statement in C++is: go to label; .. . label: statement; Where label is an identifier that identifies a labeled statement. A labeled statement is any statement thatis preceded by an identifier followed by a colon (:).
  • 13.