SlideShare a Scribd company logo
1 of 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

More Related Content

What's hot (20)

Loop(for, while, do while) condition Presentation
Loop(for, while, do while) condition PresentationLoop(for, while, do while) condition Presentation
Loop(for, while, do while) condition Presentation
 
Input and output in C++
Input and output in C++Input and output in C++
Input and output in C++
 
Typecasting in c
Typecasting in cTypecasting in c
Typecasting in c
 
Introduction to c programming
Introduction to c programmingIntroduction to c programming
Introduction to c programming
 
Control Structures
Control StructuresControl Structures
Control Structures
 
Control structure C++
Control structure C++Control structure C++
Control structure C++
 
String functions in C
String functions in CString functions in C
String functions in C
 
Python Flow Control
Python Flow ControlPython Flow Control
Python Flow Control
 
Increment and Decrement operators in C++
Increment and Decrement operators in C++Increment and Decrement operators in C++
Increment and Decrement operators in C++
 
Operators and expressions in C++
Operators and expressions in C++Operators and expressions in C++
Operators and expressions in C++
 
Loops in C
Loops in CLoops in C
Loops in C
 
Files in c++
Files in c++Files in c++
Files in c++
 
Loops in C Programming Language
Loops in C Programming LanguageLoops in C Programming Language
Loops in C Programming Language
 
Pseudocode
PseudocodePseudocode
Pseudocode
 
Java conditional statements
Java conditional statementsJava conditional statements
Java conditional statements
 
Exception Handling in object oriented programming using C++
Exception Handling in object oriented programming using C++Exception Handling in object oriented programming using C++
Exception Handling in object oriented programming using C++
 
Loops in c programming
Loops in c programmingLoops in c programming
Loops in c programming
 
Exception handling c++
Exception handling c++Exception handling c++
Exception handling c++
 
Functions in c++
Functions in c++Functions in c++
Functions in c++
 
Loops in c
Loops in cLoops in c
Loops in c
 

Similar to C++ decision making

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 language
Decision statements in c languageDecision statements in c language
Decision statements in c languagetanmaymodi4
 
Decision statements in c laguage
Decision statements in c laguageDecision statements in c laguage
Decision statements in c laguageTanmay Modi
 
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
 

Similar to 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 language
Decision statements in c languageDecision statements in c language
Decision statements in c language
 
Decision statements in c laguage
Decision statements in c laguageDecision statements in c laguage
Decision statements in c laguage
 
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
 

Recently uploaded

React Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaReact Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaHanief Utama
 
Salesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantSalesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantAxelRicardoTrocheRiq
 
Professional Resume Template for Software Developers
Professional Resume Template for Software DevelopersProfessional Resume Template for Software Developers
Professional Resume Template for Software DevelopersVinodh Ram
 
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样umasea
 
Folding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesFolding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesPhilip Schwarz
 
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...gurkirankumar98700
 
Intelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalmIntelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalmSujith Sukumaran
 
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...soniya singh
 
EY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityEY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityNeo4j
 
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...Christina Lin
 
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio, Inc.
 
Cloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackCloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackVICTOR MAESTRE RAMIREZ
 
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEBATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEOrtus Solutions, Corp
 
chapter--4-software-project-planning.ppt
chapter--4-software-project-planning.pptchapter--4-software-project-planning.ppt
chapter--4-software-project-planning.pptkotipi9215
 
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte GermanySuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte GermanyChristoph Pohl
 
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024StefanoLambiase
 
What are the key points to focus on before starting to learn ETL Development....
What are the key points to focus on before starting to learn ETL Development....What are the key points to focus on before starting to learn ETL Development....
What are the key points to focus on before starting to learn ETL Development....kzayra69
 
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...OnePlan Solutions
 
Implementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureImplementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureDinusha Kumarasiri
 
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideBuilding Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideChristina Lin
 

Recently uploaded (20)

React Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaReact Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief Utama
 
Salesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantSalesforce Certified Field Service Consultant
Salesforce Certified Field Service Consultant
 
Professional Resume Template for Software Developers
Professional Resume Template for Software DevelopersProfessional Resume Template for Software Developers
Professional Resume Template for Software Developers
 
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
 
Folding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesFolding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a series
 
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
 
Intelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalmIntelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalm
 
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
 
EY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityEY_Graph Database Powered Sustainability
EY_Graph Database Powered Sustainability
 
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
 
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
 
Cloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackCloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStack
 
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEBATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
 
chapter--4-software-project-planning.ppt
chapter--4-software-project-planning.pptchapter--4-software-project-planning.ppt
chapter--4-software-project-planning.ppt
 
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte GermanySuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
 
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
 
What are the key points to focus on before starting to learn ETL Development....
What are the key points to focus on before starting to learn ETL Development....What are the key points to focus on before starting to learn ETL Development....
What are the key points to focus on before starting to learn ETL Development....
 
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
 
Implementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureImplementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with Azure
 
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideBuilding Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
 

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; }

Editor's Notes

  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