SlideShare ist ein Scribd-Unternehmen logo
1 von 35
Program Preparation
‱ Problem Identification stage.
a) Defining the problem.
b) Analyzing the problem.
‱ Planning stage.
a) Developing the algorithm.
b) Flow charting.
c) Writing Pseudo code.
Cont..
 Coding and Testing stage.
a) Writing the program.
b) Testing and Debugging the program.
c) Running the program.
‱ Implementing and Documenting stage.
a) Implementing the program.
b) Documenting the program.
Developing the Algorithm
 Algorithm is a step-by-step procedure developed to
solve a problem before writing an actual program.
 Algorithm is a complete procedure or plan that
describes the logic of a program.
Flow Charting
 The pictorial form is referred as a flow chart, which is a
pictorial representation of an algorithm.
 The written form of the algorithm (not in computer
language) is called pseudo code. Pseudo code
expresses the basic logic structure of an algorithm in a
systematic and clear way.
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:
‱ Input/output Symbol
start Stop
Cont..
 Processing symbol: A rectangular block is used to
represent processing symbol. It shows
all the calculations.
‱ Decision Symbol:
Decision making in C++
 Decision making is about deciding the order of execution
of statements based on certain conditions or repeat a group
of statements until certain specified conditions are met.
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 to be
tested. The different forms are,
 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 than y";
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 than y";
}
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 default statement
 Prototype :- switch < expression>
 Case <statement >
 Case <statement >
 Case <statement >
 Case <statement >
 default <statement >
OPERATORS USE IN C++
PROGRAMMING
 There are many operators used in c language
Arithmetic or Mathematical Operators
Relational Operators
Logical Operators
Go to statement
 A go to statement provides an unconditional jump from the goto
to a labeled statement in the same function.
 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 that is
preceded by an identifier followed by a colon (:).
Flow chart
Looping in C++
 Loops : :- repetition of instructions is called
loop there are following loop in c language .
How it works
 A sequence of statement is executed until a specified
condition is true. This sequence of statement to be
executed is kept inside the curly braces { } known as
loop body. After every execution of loop body,
condition is checked, and if it is found to be true the
loop body is executed again. When condition check
comes out to be false, the loop body will not be
executed.
There are three types of loop in
C++
1. while loop
2. for loop
3. do-while loop
While loop
 while loop can be address as an entry control loop. It
is completed in 3 steps.
Variable initialization.( e.g int x=0; )
condition( e.g while( x<=10) )
Variable increment or decrement ( x++ or x-- or x=x+2)
Syntax :
variable initialization ;
while (condition)
{
statements ;
variable increment or decrement ;
}
Flow chart
Example :
#include<iostream.h>
#include<conio.h>
Void main (void)
{
Int k;
Clrscr();
K=0;
While( k< 20)
{
Cout<<“ n “<<k;
K++; }
Getch(); }
For loop
 for loop is used to execute a set of statement repeatedly until a particular
condition is satisfied. we can say it an open ended loop. General format is,
for(initialization; condition ;increment/decrement)
{
statement-block;
}
e.g
for (i = 1; i <= n; ++i)
 In for loop we have exactly two semicolons, one after
initialization and second after condition. In this loop we can
have more than one initialization or increment/decrement,
separated using comma operator. for loop can have only
one condition.
Flow chart
Example :
#include <iostream>
using namespace std;
int main()
{
int i, n, factorial = 1;
cout<<"Enter a positive integer: ";
cin>>n;
for (i = 1; i <= n; ++i)
{
factorial *= i; // factorial = factorial * i;
}
cout<< "Factorial of "<<n<<" = "<<factorial; return 0;
}
do-while loop
 In some situations it is necessary to execute body of the loop
before testing the condition. Such situations can be handled
with the help of do-while loop. do statement evaluates the body
of the loop first and at the end, the condition is checked
using while statement. General format of do-while loop is,
Do
{
.statement is;
}
while(condition)
Flow chart
Example :
#include <iostream>
using namespace std;
int main() {
float number, sum = 0.0;
do {
cout<<"Enter a number: ";
cin>>number;
sum += number;
}
while(number != 0.0);
cout<<"Total sum = "<<sum; return 0;
}
C++ decision making
C++ decision making

Weitere Àhnliche Inhalte

Was ist angesagt?

08 c++ Operator Overloading.ppt
08 c++ Operator Overloading.ppt08 c++ Operator Overloading.ppt
08 c++ Operator Overloading.pptTareq Hasan
 
C++ Programming Language
C++ Programming Language C++ Programming Language
C++ Programming Language Mohamed Loey
 
Operators and expressions in C++
Operators and expressions in C++Operators and expressions in C++
Operators and expressions in C++Neeru Mittal
 
Exception handling c++
Exception handling c++Exception handling c++
Exception handling c++Jayant Dalvi
 
Pointers in c++
Pointers in c++Pointers in c++
Pointers in c++Vineeta Garg
 
Control statements in c
Control statements in cControl statements in c
Control statements in cSathish Narayanan
 
Type casting in java
Type casting in javaType casting in java
Type casting in javaFarooq Baloch
 
Conditional Statement in C Language
Conditional Statement in C LanguageConditional Statement in C Language
Conditional Statement in C LanguageShaina Arora
 
Inheritance in c++
Inheritance in c++Inheritance in c++
Inheritance in c++Vishal Patil
 
Virtual function in C++ Pure Virtual Function
Virtual function in C++ Pure Virtual Function Virtual function in C++ Pure Virtual Function
Virtual function in C++ Pure Virtual Function Kamlesh Makvana
 
Pointer in C++
Pointer in C++Pointer in C++
Pointer in C++Mauryasuraj98
 
Method overriding
Method overridingMethod overriding
Method overridingAzaz Maverick
 
If else statement in c++
If else statement in c++If else statement in c++
If else statement in c++Bishal Sharma
 

Was ist angesagt? (20)

Functions in C++
Functions in C++Functions in C++
Functions in C++
 
08 c++ Operator Overloading.ppt
08 c++ Operator Overloading.ppt08 c++ Operator Overloading.ppt
08 c++ Operator Overloading.ppt
 
C++ Programming Language
C++ Programming Language C++ Programming Language
C++ Programming Language
 
Operators and expressions in C++
Operators and expressions in C++Operators and expressions in C++
Operators and expressions in C++
 
Exception handling c++
Exception handling c++Exception handling c++
Exception handling c++
 
Pointers in c++
Pointers in c++Pointers in c++
Pointers in c++
 
Control statements in c
Control statements in cControl statements in c
Control statements in c
 
Type casting in java
Type casting in javaType casting in java
Type casting in java
 
Conditional Statement in C Language
Conditional Statement in C LanguageConditional Statement in C Language
Conditional Statement in C Language
 
Inheritance in c++
Inheritance in c++Inheritance in c++
Inheritance in c++
 
Introduction to C++
Introduction to C++Introduction to C++
Introduction to C++
 
Virtual function in C++ Pure Virtual Function
Virtual function in C++ Pure Virtual Function Virtual function in C++ Pure Virtual Function
Virtual function in C++ Pure Virtual Function
 
Data types in c++
Data types in c++Data types in c++
Data types in c++
 
Functions in c++
Functions in c++Functions in c++
Functions in c++
 
6. static keyword
6. static keyword6. static keyword
6. static keyword
 
Function overloading ppt
Function overloading pptFunction overloading ppt
Function overloading ppt
 
Functions in c
Functions in cFunctions in c
Functions in c
 
Pointer in C++
Pointer in C++Pointer in C++
Pointer in C++
 
Method overriding
Method overridingMethod overriding
Method overriding
 
If else statement in c++
If else statement in c++If else statement in c++
If else statement in c++
 

Ähnlich wie C++ decision making

C Programming Unit-2
C Programming Unit-2C Programming Unit-2
C Programming Unit-2Vikram Nandini
 
Programming in Arduino (Part 2)
Programming in Arduino  (Part 2)Programming in Arduino  (Part 2)
Programming in Arduino (Part 2)Niket Chandrawanshi
 
Object oriented programming system with C++
Object oriented programming system with C++Object oriented programming system with C++
Object oriented programming system with C++msharshitha03s
 
Control Structures in C
Control Structures in CControl Structures in C
Control Structures in Csana shaikh
 
C statements
C statementsC statements
C statementsAhsann111
 
[C++][a] tutorial 2
[C++][a] tutorial 2[C++][a] tutorial 2
[C++][a] tutorial 2yasir_cesc
 
Claguage 110226222227-phpapp02
Claguage 110226222227-phpapp02Claguage 110226222227-phpapp02
Claguage 110226222227-phpapp02CIMAP
 
Decision statements in c laguage
Decision statements in c laguageDecision statements in c laguage
Decision statements in c laguageTanmay Modi
 
Decision statements in c language
Decision statements in c languageDecision statements in c language
Decision statements in c languagetanmaymodi4
 
Flow of control C ++ By TANUJ
Flow of control C ++ By TANUJFlow of control C ++ By TANUJ
Flow of control C ++ By TANUJTANUJ ⠀
 
Loops in c language
Loops in c languageLoops in c language
Loops in c languagetanmaymodi4
 
Loops in c language
Loops in c languageLoops in c language
Loops in c languageTanmay Modi
 
Programming Fundamentals
Programming FundamentalsProgramming Fundamentals
Programming Fundamentalsumar78600
 
JPC#8 Introduction to Java Programming
JPC#8 Introduction to Java ProgrammingJPC#8 Introduction to Java Programming
JPC#8 Introduction to Java ProgrammingPathomchon Sriwilairit
 
COM1407: Program Control Structures – Repetition and Loops
COM1407: Program Control Structures – Repetition and Loops COM1407: Program Control Structures – Repetition and Loops
COM1407: Program Control Structures – Repetition and Loops Hemantha Kulathilake
 
C UNIT-2 PREPARED Y M V BRAHMANANDA REDDY
C UNIT-2 PREPARED Y M V BRAHMANANDA REDDYC UNIT-2 PREPARED Y M V BRAHMANANDA REDDY
C UNIT-2 PREPARED Y M V BRAHMANANDA REDDYRajeshkumar Reddy
 
Btech i pic u-3 handling input output and control statements
Btech i pic u-3 handling input output and control statementsBtech i pic u-3 handling input output and control statements
Btech i pic u-3 handling input output and control statementsRai University
 

Ähnlich wie C++ decision making (20)

C Programming Unit-2
C Programming Unit-2C Programming Unit-2
C Programming Unit-2
 
Programming in Arduino (Part 2)
Programming in Arduino  (Part 2)Programming in Arduino  (Part 2)
Programming in Arduino (Part 2)
 
Object oriented programming system with C++
Object oriented programming system with C++Object oriented programming system with C++
Object oriented programming system with C++
 
Control Structures in C
Control Structures in CControl Structures in C
Control Structures in C
 
C statements
C statementsC statements
C statements
 
[C++][a] tutorial 2
[C++][a] tutorial 2[C++][a] tutorial 2
[C++][a] tutorial 2
 
Flow of control ppt
Flow of control pptFlow of control ppt
Flow of control ppt
 
Claguage 110226222227-phpapp02
Claguage 110226222227-phpapp02Claguage 110226222227-phpapp02
Claguage 110226222227-phpapp02
 
Decision statements in c laguage
Decision statements in c laguageDecision statements in c laguage
Decision statements in c laguage
 
Decision statements in c language
Decision statements in c languageDecision statements in c language
Decision statements in c language
 
Flow of control C ++ By TANUJ
Flow of control C ++ By TANUJFlow of control C ++ By TANUJ
Flow of control C ++ By TANUJ
 
Loops in c language
Loops in c languageLoops in c language
Loops in c language
 
Loops in c language
Loops in c languageLoops in c language
Loops in c language
 
Programming Fundamentals
Programming FundamentalsProgramming Fundamentals
Programming Fundamentals
 
JPC#8 Introduction to Java Programming
JPC#8 Introduction to Java ProgrammingJPC#8 Introduction to Java Programming
JPC#8 Introduction to Java Programming
 
COM1407: Program Control Structures – Repetition and Loops
COM1407: Program Control Structures – Repetition and Loops COM1407: Program Control Structures – Repetition and Loops
COM1407: Program Control Structures – Repetition and Loops
 
Controls & Loops in C
Controls & Loops in C Controls & Loops in C
Controls & Loops in C
 
C UNIT-2 PREPARED Y M V BRAHMANANDA REDDY
C UNIT-2 PREPARED Y M V BRAHMANANDA REDDYC UNIT-2 PREPARED Y M V BRAHMANANDA REDDY
C UNIT-2 PREPARED Y M V BRAHMANANDA REDDY
 
Btech i pic u-3 handling input output and control statements
Btech i pic u-3 handling input output and control statementsBtech i pic u-3 handling input output and control statements
Btech i pic u-3 handling input output and control statements
 
Looping statements
Looping statementsLooping statements
Looping statements
 

KĂŒrzlich hochgeladen

%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...masabamasaba
 
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfonteinmasabamasaba
 
%in Soweto+277-882-255-28 abortion pills for sale in soweto
%in Soweto+277-882-255-28 abortion pills for sale in soweto%in Soweto+277-882-255-28 abortion pills for sale in soweto
%in Soweto+277-882-255-28 abortion pills for sale in sowetomasabamasaba
 
8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech studentsHimanshiGarg82
 
WSO2CON 2024 - Does Open Source Still Matter?
WSO2CON 2024 - Does Open Source Still Matter?WSO2CON 2024 - Does Open Source Still Matter?
WSO2CON 2024 - Does Open Source Still Matter?WSO2
 
WSO2CON2024 - It's time to go Platformless
WSO2CON2024 - It's time to go PlatformlessWSO2CON2024 - It's time to go Platformless
WSO2CON2024 - It's time to go PlatformlessWSO2
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...panagenda
 
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...WSO2
 
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...masabamasaba
 
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyviewmasabamasaba
 
%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg
%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg
%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburgmasabamasaba
 
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park %in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park masabamasaba
 
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park %in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park masabamasaba
 
%in Benoni+277-882-255-28 abortion pills for sale in Benoni
%in Benoni+277-882-255-28 abortion pills for sale in Benoni%in Benoni+277-882-255-28 abortion pills for sale in Benoni
%in Benoni+277-882-255-28 abortion pills for sale in Benonimasabamasaba
 
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...masabamasaba
 
VTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnVTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnAmarnathKambale
 
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...Jittipong Loespradit
 
Announcing Codolex 2.0 from GDK Software
Announcing Codolex 2.0 from GDK SoftwareAnnouncing Codolex 2.0 from GDK Software
Announcing Codolex 2.0 from GDK SoftwareJim McKeeth
 
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital TransformationWSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital TransformationWSO2
 

KĂŒrzlich hochgeladen (20)

Abortion Pills In Pretoria ](+27832195400*)[ đŸ„ Women's Abortion Clinic In Pre...
Abortion Pills In Pretoria ](+27832195400*)[ đŸ„ Women's Abortion Clinic In Pre...Abortion Pills In Pretoria ](+27832195400*)[ đŸ„ Women's Abortion Clinic In Pre...
Abortion Pills In Pretoria ](+27832195400*)[ đŸ„ Women's Abortion Clinic In Pre...
 
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
 
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
 
%in Soweto+277-882-255-28 abortion pills for sale in soweto
%in Soweto+277-882-255-28 abortion pills for sale in soweto%in Soweto+277-882-255-28 abortion pills for sale in soweto
%in Soweto+277-882-255-28 abortion pills for sale in soweto
 
8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students
 
WSO2CON 2024 - Does Open Source Still Matter?
WSO2CON 2024 - Does Open Source Still Matter?WSO2CON 2024 - Does Open Source Still Matter?
WSO2CON 2024 - Does Open Source Still Matter?
 
WSO2CON2024 - It's time to go Platformless
WSO2CON2024 - It's time to go PlatformlessWSO2CON2024 - It's time to go Platformless
WSO2CON2024 - It's time to go Platformless
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
 
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
 
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
 
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
 
%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg
%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg
%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg
 
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park %in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
 
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park %in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
 
%in Benoni+277-882-255-28 abortion pills for sale in Benoni
%in Benoni+277-882-255-28 abortion pills for sale in Benoni%in Benoni+277-882-255-28 abortion pills for sale in Benoni
%in Benoni+277-882-255-28 abortion pills for sale in Benoni
 
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
 
VTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnVTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learn
 
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
 
Announcing Codolex 2.0 from GDK Software
Announcing Codolex 2.0 from GDK SoftwareAnnouncing Codolex 2.0 from GDK Software
Announcing Codolex 2.0 from GDK Software
 
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital TransformationWSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
 

C++ decision making

  • 1.
  • 2.
  • 3.
  • 4. Program Preparation ‱ Problem Identification stage. a) Defining the problem. b) Analyzing the problem. ‱ Planning stage. a) Developing the algorithm. b) Flow charting. c) Writing Pseudo code.
  • 5. Cont..  Coding and Testing stage. a) Writing the program. b) Testing and Debugging the program. c) Running the program. ‱ Implementing and Documenting stage. a) Implementing the program. b) Documenting the program.
  • 6. Developing the Algorithm  Algorithm is a step-by-step procedure developed to solve a problem before writing an actual program.  Algorithm is a complete procedure or plan that describes the logic of a program.
  • 7. Flow Charting  The pictorial form is referred as a flow chart, which is a pictorial representation of an algorithm.  The written form of the algorithm (not in computer language) is called pseudo code. Pseudo code expresses the basic logic structure of an algorithm in a systematic and clear way.
  • 8. 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: ‱ Input/output Symbol start Stop
  • 9. Cont..  Processing symbol: A rectangular block is used to represent processing symbol. It shows all the calculations. ‱ Decision Symbol:
  • 10. Decision making in C++  Decision making is about deciding the order of execution of statements based on certain conditions or repeat a group of statements until certain specified conditions are met. C++ handles decision-making by supporting the following statements,  if statement  switch statement  conditional operator statement  goto statement
  • 11. Decision making with If statement  The if statement may be implemented in different forms depending on the complexity of conditions to be tested. The different forms are,  Simple if statement  If....else statement  Nested if....else statement  else if statement
  • 12. 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.
  • 13. Example : #include< iostream.h> int main( ) { int x,y; x=15; y=13; if (x > y ) { cout << "x is greater than y"; getch(); }
  • 14. 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.
  • 15. Example : void main( ) { int x,y; x=15; y=18; if (x > y ) { cout << "x is greater than y"; } else { cout << "y is greater than x"; } }
  • 16. 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.
  • 17. 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 default statement  Prototype :- switch < expression>  Case <statement >  Case <statement >  Case <statement >  Case <statement >  default <statement >
  • 18. OPERATORS USE IN C++ PROGRAMMING  There are many operators used in c language Arithmetic or Mathematical Operators Relational Operators Logical Operators
  • 19. Go to statement  A go to statement provides an unconditional jump from the goto to a labeled statement in the same function.  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 that is preceded by an identifier followed by a colon (:).
  • 21. Looping in C++  Loops : :- repetition of instructions is called loop there are following loop in c language .
  • 22. How it works  A sequence of statement is executed until a specified condition is true. This sequence of statement to be executed is kept inside the curly braces { } known as loop body. After every execution of loop body, condition is checked, and if it is found to be true the loop body is executed again. When condition check comes out to be false, the loop body will not be executed.
  • 23. There are three types of loop in C++ 1. while loop 2. for loop 3. do-while loop
  • 24. While loop  while loop can be address as an entry control loop. It is completed in 3 steps. Variable initialization.( e.g int x=0; ) condition( e.g while( x<=10) ) Variable increment or decrement ( x++ or x-- or x=x+2)
  • 25. Syntax : variable initialization ; while (condition) { statements ; variable increment or decrement ; }
  • 27. Example : #include<iostream.h> #include<conio.h> Void main (void) { Int k; Clrscr(); K=0; While( k< 20) { Cout<<“ n “<<k; K++; } Getch(); }
  • 28. For loop  for loop is used to execute a set of statement repeatedly until a particular condition is satisfied. we can say it an open ended loop. General format is, for(initialization; condition ;increment/decrement) { statement-block; } e.g for (i = 1; i <= n; ++i)  In for loop we have exactly two semicolons, one after initialization and second after condition. In this loop we can have more than one initialization or increment/decrement, separated using comma operator. for loop can have only one condition.
  • 30. Example : #include <iostream> using namespace std; int main() { int i, n, factorial = 1; cout<<"Enter a positive integer: "; cin>>n; for (i = 1; i <= n; ++i) { factorial *= i; // factorial = factorial * i; } cout<< "Factorial of "<<n<<" = "<<factorial; return 0; }
  • 31. do-while loop  In some situations it is necessary to execute body of the loop before testing the condition. Such situations can be handled with the help of do-while loop. do statement evaluates the body of the loop first and at the end, the condition is checked using while statement. General format of do-while loop is, Do { .statement is; } while(condition)
  • 33. Example : #include <iostream> using namespace std; int main() { float number, sum = 0.0; do { cout<<"Enter a number: "; cin>>number; sum += number; } while(number != 0.0); cout<<"Total sum = "<<sum; return 0; }

Hinweis der Redaktion

  1. The key to good programming is Planning.By spending more time in the planning phase,it is normally possible to save time in writing,testing and implementing a program.In many cases better planning can reduce total programming time and cost.
  2. Output : x is greater than y Output : x is greater than y Output : x is greater than y Output : x is greater than y
  3. Output: y is greater than x
  4. Output :Enter a positive integer: 5 Factorial of 5 = 120
  5. Output :Enter a number: 4.5 Enter a number: 2.34 Enter a number: 5.63 Enter a number: 6.34 Enter a number: 4.53 Enter a number: 5 Enter a number: 0 Total sum = 28.34