SlideShare una empresa de Scribd logo
1 de 41
prezentr.com!
Prepared By: Asst. Prof. Sejal Jadav
Unit-1
Principles of Object Oriented
Programming
Tokens, expressions & Control Statements
(14 MARKS)
B.C.A & B.Sc.(IT) – 3
CS-13 C++ and Object Oriented
Programming
prezentr.com!
Prepared By: Asst. Prof. Sejal Jadav
Control Structures
prezentr.com!
Prepared By: Asst. Prof. Sejal Jadav
Control Structures
prezentr.com!
Prepared By: Asst. Prof. Sejal Jadav
• In C++ programming, if statement is used
to test the condition. There are various
types of if statements in C++.
1. if statement
2. if-else statement
3. nested if statement
4. if-else-if ladder
prezentr.com!
Prepared By: Asst. Prof. Sejal Jadav
IF Statement
• If the Boolean expression evaluates
to true, then the block of code inside the if
statement will be executed.
• If Boolean expression evaluates to false,
then the first set of code after the end of
the if statement (after the closing curly
brace) will be executed.
prezentr.com!
Prepared By: Asst. Prof. Sejal Jadav
IF Statement
• The C++ if statement tests the condition. It
is executed if condition is true.
if(condition)
{
//code to be executed
}
prezentr.com!
Prepared By: Asst. Prof. Sejal Jadav
C++ If Example: 1_IFExample.cpp
prezentr.com!
Prepared By: Asst. Prof. Sejal Jadav
if...else statement
• An if statement can be followed by an
optional else statement, which executes
when the Boolean expression is false.
prezentr.com!
Prepared By: Asst. Prof. Sejal Jadav
Syntax
if(boolean_expression)
{
// statement(s) will execute if the boolean expression is
true
}else{
// statement(s) will execute if the boolean expression is
false
}
prezentr.com!
Prepared By: Asst. Prof. Sejal Jadav
• If the boolean expression evaluates to true,
then the if block of code will be executed,
otherwise else block of code will be
executed.
prezentr.com!
Prepared By: Asst. Prof. Sejal Jadav
Example: 2_IF_Else.cpp
prezentr.com!
Prepared By: Asst. Prof. Sejal Jadav
if...else if...else Statement
• An if statement can be followed by an
optional else if...else statement, which is
very useful to test various conditions using
single if...else if statement.
prezentr.com!
Prepared By: Asst. Prof. Sejal Jadav
Syntax and Example:3_if_elseif_else.cpp
if(boolean_expression 1)
{
// Executes when the boolean expression 1 is true
} else if( boolean_expression 2) {
// Executes when the boolean expression 2 is true
} else if( boolean_expression 3) {
// Executes when the boolean expression 3 is true
} else
{
// executes when the none of the above condition is true.
}
prezentr.com!
Prepared By: Asst. Prof. Sejal Jadav
nested if statements
• It is always legal to nest if-else statements,
which means you can use one if or else if
statement inside another if or else if
statement(s).
prezentr.com!
Prepared By: Asst. Prof. Sejal Jadav
Syntax
if( boolean_expression 1)
{
// Executes when the boolean expression 1 is true
if(boolean_expression 2)
{
// Executes when the boolean expression 2 is true
}
}
Let’s see example -> Example: Nested_if.cpp
prezentr.com!
Prepared By: Asst. Prof. Sejal Jadav
switch statement
• A switch statement allows a variable to be
tested for equality against a list of values.
Each value is called a case, and the variable
being switched on is checked for each case.
prezentr.com!
Prepared By: Asst. Prof. Sejal Jadav
Syntax
switch(expression)
{
case constant-expression :
statement(s);
break; //optional
case constant-expression :
statement(s);
break; //optional
// you can have any number of case statements.
default : //Optional
statement(s);
}
prezentr.com!
Prepared By: Asst. Prof. Sejal Jadav
Example: 5_Switch.cpp
prezentr.com!
Prepared By: Asst. Prof. Sejal Jadav
Looping Control
Structure
prezentr.com!
Prepared By: Asst. Prof. Sejal Jadav
• There may be a situation, when you need
to execute a block of code several number
of times. In general, statements are
executed sequentially: The first statement
in a function is executed first, followed by
the second, and so on.
• Programming languages provide various
control structures that allow for more
complicated execution paths.
prezentr.com!
Prepared By: Asst. Prof. Sejal Jadav
• 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 −
prezentr.com!
Prepared By: Asst. Prof. Sejal Jadav
• C++ programming language provides the
following type of loops to handle looping
requirements.
1. for,
2. while,
3. do… while
prezentr.com!
Prepared By: Asst. Prof. Sejal Jadav
For Loop
• A for loop is a repetition control structure
that allows you to efficiently write a loop
that needs to execute a specific number of
times.
prezentr.com!
Prepared By: Asst. Prof. Sejal Jadav
Syntax
The syntax of a for loop in C++ is −
for ( init; condition; increment )
{
statement(s);
}
prezentr.com!
Prepared By: Asst. Prof. Sejal Jadav
• Here is the flow of control in a for loop −
• The init step is executed first, and only
once. This step allows you to declare and
initialize any loop control variables. You
are not required to put a statement here, as
long as a semicolon appears.
prezentr.com!
Prepared By: Asst. Prof. Sejal Jadav
• Next, the condition is evaluated. If it is
true, the body of the loop is executed. If it is
false, the body of the loop does not execute
and flow of control jumps to the next
statement just after the for loop.
prezentr.com!
Prepared By: Asst. Prof. Sejal Jadav
• After the body of the for loop executes, the
flow of control jumps back up to
the increment statement.
prezentr.com!
Prepared By: Asst. Prof. Sejal Jadav
• The condition is now evaluated again. If it
is true, the loop executes and the process
repeats itself (body of loop, then increment
step, and then again condition). After the
condition becomes false, the for loop
terminates.
prezentr.com!
Prepared By: Asst. Prof. Sejal Jadav
Example: ForLoop.cpp
prezentr.com!
Prepared By: Asst. Prof. Sejal Jadav
while loop
• A while loop statement repeatedly
executes a target statement as long as a
given condition is true.
prezentr.com!
Prepared By: Asst. Prof. Sejal Jadav
Syntax
• The syntax of a while loop in C++ is -
while(condition)
{
statement(s);
}
prezentr.com!
Prepared By: Asst. Prof. Sejal Jadav
• Here, statement(s) may be a single
statement or a block of statements.
The condition may be any expression, and
true is any non-zero value. The loop
iterates while the condition is true.
• When the condition becomes false,
program control passes to the line
immediately following the loop.
prezentr.com!
Prepared By: Asst. Prof. Sejal Jadav
Example:9_while.cpp
Example:9_whileLoop.cpp
prezentr.com!
Prepared By: Asst. Prof. Sejal Jadav
• Here, key point of the while loop is that the
loop might not ever run. When the
condition is tested and the result is false,
the loop body will be skipped and the first
statement after the while loop will be
executed.
prezentr.com!
Prepared By: Asst. Prof. Sejal Jadav
do...while loop
• Unlike for and while loops, which test the
loop condition at the top of the loop,
the do...while loop checks its condition at the
bottom of the loop.
• A do...while loop is similar to a while loop,
except that a do...while loop is guaranteed to
execute at least one time.
prezentr.com!
Prepared By: Asst. Prof. Sejal Jadav
Syntax
do
{
statement(s);
}
while( condition );
prezentr.com!
Prepared By: Asst. Prof. Sejal Jadav
• Notice that the conditional expression
appears at the end of the loop, so the
statement(s) in the loop execute once
before the condition is tested.
• If the condition is true, the flow of control
jumps back up to do, and the statement(s)
in the loop execute again. This process
repeats until the given condition becomes
false.
prezentr.com!
Prepared By: Asst. Prof. Sejal Jadav
Example: 10_do_while.cpp
Example: dowhile.cpp
prezentr.com!
Prepared By: Asst. Prof. Sejal Jadav
Example: 6_infinite.cpp
#include <iostream>
using namespace std;
int main ()
{
for( ; ; )
{
printf("This loop will run forever.n");
}
return 0; }
prezentr.com!
Prepared By: Asst. Prof. Sejal Jadav
• A loop becomes infinite loop if a condition
never becomes false. The for loop is
traditionally used for this purpose. Since
none of the three expressions that form the
‘for’ loop are required, you can make an
endless loop by leaving the conditional
expression empty.
prezentr.com!
Prepared By: Asst. Prof. Sejal Jadav
• When the conditional expression is absent,
it is assumed to be true. You may have an
initialization and increment expression,
but C++ programmers more commonly use
the ‘for (;;)’ construct to signify an infinite
loop.
• NOTE − You can terminate an infinite loop
by pressing Ctrl + C keys.

Más contenido relacionado

La actualidad más candente

Python Testing Fundamentals
Python Testing FundamentalsPython Testing Fundamentals
Python Testing Fundamentalscbcunc
 
testing for people who hate testing
testing for people who hate testingtesting for people who hate testing
testing for people who hate testingBram Vogelaar
 
Static typing and proof in ATS language
Static typing and proof in ATS languageStatic typing and proof in ATS language
Static typing and proof in ATS languageKiwamu Okabe
 
ATS/LF for Coq users
ATS/LF for Coq usersATS/LF for Coq users
ATS/LF for Coq usersKiwamu Okabe
 
Embedded application designed by ATS language
Embedded application designed by ATS languageEmbedded application designed by ATS language
Embedded application designed by ATS languageKiwamu Okabe
 
Hands-on VeriFast with STM32 microcontroller
Hands-on VeriFast with STM32 microcontrollerHands-on VeriFast with STM32 microcontroller
Hands-on VeriFast with STM32 microcontrollerKiwamu Okabe
 
Start! ATS programming
Start! ATS programmingStart! ATS programming
Start! ATS programmingKiwamu Okabe
 
Metasepi team meeting #14: ATS programming on MCU
Metasepi team meeting #14: ATS programming on MCUMetasepi team meeting #14: ATS programming on MCU
Metasepi team meeting #14: ATS programming on MCUKiwamu Okabe
 
Unit testing legacy code
Unit testing legacy codeUnit testing legacy code
Unit testing legacy codeLars Thorup
 
Metasepi team meeting #16: Safety on ATS language + MCU
Metasepi team meeting #16: Safety on ATS language + MCUMetasepi team meeting #16: Safety on ATS language + MCU
Metasepi team meeting #16: Safety on ATS language + MCUKiwamu Okabe
 
10control statement in c#
10control statement in c#10control statement in c#
10control statement in c#Sireesh K
 
Google mock for dummies
Google mock for dummiesGoogle mock for dummies
Google mock for dummiesHarry Potter
 
Refactoring legacy code driven by tests - ENG
Refactoring legacy code driven by tests - ENGRefactoring legacy code driven by tests - ENG
Refactoring legacy code driven by tests - ENGLuca Minudel
 
Living With Legacy Code
Living With Legacy CodeLiving With Legacy Code
Living With Legacy CodeRowan Merewood
 
Please Behave Yourself: BDD and automating Eclipse RCP applications using JBe...
Please Behave Yourself: BDD and automating Eclipse RCP applications using JBe...Please Behave Yourself: BDD and automating Eclipse RCP applications using JBe...
Please Behave Yourself: BDD and automating Eclipse RCP applications using JBe...Eclipse Day India
 
Metasepi team meeting #20: Start! ATS programming on MCU
Metasepi team meeting #20: Start! ATS programming on MCUMetasepi team meeting #20: Start! ATS programming on MCU
Metasepi team meeting #20: Start! ATS programming on MCUKiwamu Okabe
 
The Art of Unit Testing - Towards a Testable Design
The Art of Unit Testing - Towards a Testable DesignThe Art of Unit Testing - Towards a Testable Design
The Art of Unit Testing - Towards a Testable DesignVictor Rentea
 
Testing Legacy Rails Apps
Testing Legacy Rails AppsTesting Legacy Rails Apps
Testing Legacy Rails AppsRabble .
 
Functional IoT: Programming Language and OS
Functional IoT: Programming Language and OSFunctional IoT: Programming Language and OS
Functional IoT: Programming Language and OSKiwamu Okabe
 

La actualidad más candente (19)

Python Testing Fundamentals
Python Testing FundamentalsPython Testing Fundamentals
Python Testing Fundamentals
 
testing for people who hate testing
testing for people who hate testingtesting for people who hate testing
testing for people who hate testing
 
Static typing and proof in ATS language
Static typing and proof in ATS languageStatic typing and proof in ATS language
Static typing and proof in ATS language
 
ATS/LF for Coq users
ATS/LF for Coq usersATS/LF for Coq users
ATS/LF for Coq users
 
Embedded application designed by ATS language
Embedded application designed by ATS languageEmbedded application designed by ATS language
Embedded application designed by ATS language
 
Hands-on VeriFast with STM32 microcontroller
Hands-on VeriFast with STM32 microcontrollerHands-on VeriFast with STM32 microcontroller
Hands-on VeriFast with STM32 microcontroller
 
Start! ATS programming
Start! ATS programmingStart! ATS programming
Start! ATS programming
 
Metasepi team meeting #14: ATS programming on MCU
Metasepi team meeting #14: ATS programming on MCUMetasepi team meeting #14: ATS programming on MCU
Metasepi team meeting #14: ATS programming on MCU
 
Unit testing legacy code
Unit testing legacy codeUnit testing legacy code
Unit testing legacy code
 
Metasepi team meeting #16: Safety on ATS language + MCU
Metasepi team meeting #16: Safety on ATS language + MCUMetasepi team meeting #16: Safety on ATS language + MCU
Metasepi team meeting #16: Safety on ATS language + MCU
 
10control statement in c#
10control statement in c#10control statement in c#
10control statement in c#
 
Google mock for dummies
Google mock for dummiesGoogle mock for dummies
Google mock for dummies
 
Refactoring legacy code driven by tests - ENG
Refactoring legacy code driven by tests - ENGRefactoring legacy code driven by tests - ENG
Refactoring legacy code driven by tests - ENG
 
Living With Legacy Code
Living With Legacy CodeLiving With Legacy Code
Living With Legacy Code
 
Please Behave Yourself: BDD and automating Eclipse RCP applications using JBe...
Please Behave Yourself: BDD and automating Eclipse RCP applications using JBe...Please Behave Yourself: BDD and automating Eclipse RCP applications using JBe...
Please Behave Yourself: BDD and automating Eclipse RCP applications using JBe...
 
Metasepi team meeting #20: Start! ATS programming on MCU
Metasepi team meeting #20: Start! ATS programming on MCUMetasepi team meeting #20: Start! ATS programming on MCU
Metasepi team meeting #20: Start! ATS programming on MCU
 
The Art of Unit Testing - Towards a Testable Design
The Art of Unit Testing - Towards a Testable DesignThe Art of Unit Testing - Towards a Testable Design
The Art of Unit Testing - Towards a Testable Design
 
Testing Legacy Rails Apps
Testing Legacy Rails AppsTesting Legacy Rails Apps
Testing Legacy Rails Apps
 
Functional IoT: Programming Language and OS
Functional IoT: Programming Language and OSFunctional IoT: Programming Language and OS
Functional IoT: Programming Language and OS
 

Similar a C++ unit-1-part-15

Similar a C++ unit-1-part-15 (20)

C++ unit-1-part-14
C++ unit-1-part-14C++ unit-1-part-14
C++ unit-1-part-14
 
Learn C# Programming - Decision Making & Loops
Learn C# Programming - Decision Making & LoopsLearn C# Programming - Decision Making & Loops
Learn C# Programming - Decision Making & Loops
 
Unit II.pptx
Unit II.pptxUnit II.pptx
Unit II.pptx
 
Decision Making & Loops
Decision Making & LoopsDecision Making & Loops
Decision Making & Loops
 
DECISION MAKING.pptx
DECISION MAKING.pptxDECISION MAKING.pptx
DECISION MAKING.pptx
 
Loops in c
Loops in cLoops in c
Loops in c
 
Chapter 2 : Programming with Java Statements
Chapter 2 : Programming with Java StatementsChapter 2 : Programming with Java Statements
Chapter 2 : Programming with Java Statements
 
Programming in Arduino (Part 2)
Programming in Arduino  (Part 2)Programming in Arduino  (Part 2)
Programming in Arduino (Part 2)
 
05 Conditional statements
05 Conditional statements05 Conditional statements
05 Conditional statements
 
Loop structures
Loop structuresLoop structures
Loop structures
 
Final requirement
Final requirementFinal requirement
Final requirement
 
Control statements anil
Control statements anilControl statements anil
Control statements anil
 
Control structure
Control structureControl structure
Control structure
 
Introduction To Programming with Python Lecture 2
Introduction To Programming with Python Lecture 2Introduction To Programming with Python Lecture 2
Introduction To Programming with Python Lecture 2
 
Java chapter 3
Java chapter 3Java chapter 3
Java chapter 3
 
M C6java6
M C6java6M C6java6
M C6java6
 
Programming Fundamentals in C++ structures
Programming Fundamentals in  C++ structuresProgramming Fundamentals in  C++ structures
Programming Fundamentals in C++ structures
 
Lecture 10
Lecture 10Lecture 10
Lecture 10
 
control statements
control statementscontrol statements
control statements
 
05. Control Structures.ppt
05. Control Structures.ppt05. Control Structures.ppt
05. Control Structures.ppt
 

Más de Jadavsejal

Programming with Java Concept: Java TimeZone Class
Programming with Java Concept: Java TimeZone ClassProgramming with Java Concept: Java TimeZone Class
Programming with Java Concept: Java TimeZone ClassJadavsejal
 
Programming Java Concept of Event Handling
Programming Java Concept of Event HandlingProgramming Java Concept of Event Handling
Programming Java Concept of Event HandlingJadavsejal
 
Programming Java GUI using SWING, Event Handling
Programming Java GUI using SWING, Event HandlingProgramming Java GUI using SWING, Event Handling
Programming Java GUI using SWING, Event HandlingJadavsejal
 
concept of applet and concept of Layout Managers
concept of applet and concept of Layout Managersconcept of applet and concept of Layout Managers
concept of applet and concept of Layout ManagersJadavsejal
 
C++ unit-2-part-3
C++ unit-2-part-3C++ unit-2-part-3
C++ unit-2-part-3Jadavsejal
 
C++ unit-2-part-2
C++ unit-2-part-2C++ unit-2-part-2
C++ unit-2-part-2Jadavsejal
 
C++ unit-2-part-1
C++ unit-2-part-1C++ unit-2-part-1
C++ unit-2-part-1Jadavsejal
 
C++ unit-1-part-13
C++ unit-1-part-13C++ unit-1-part-13
C++ unit-1-part-13Jadavsejal
 
C++ unit-1-part-12
C++ unit-1-part-12C++ unit-1-part-12
C++ unit-1-part-12Jadavsejal
 
C++ unit-1-part-11
C++ unit-1-part-11C++ unit-1-part-11
C++ unit-1-part-11Jadavsejal
 
C++ unit-1-part-10
C++ unit-1-part-10C++ unit-1-part-10
C++ unit-1-part-10Jadavsejal
 
C++ unit-1-part-9
C++ unit-1-part-9C++ unit-1-part-9
C++ unit-1-part-9Jadavsejal
 
C++ unit-1-part-8
C++ unit-1-part-8C++ unit-1-part-8
C++ unit-1-part-8Jadavsejal
 
C++ unit-1-part-7
C++ unit-1-part-7C++ unit-1-part-7
C++ unit-1-part-7Jadavsejal
 
C++ unit-1-part-6
C++ unit-1-part-6C++ unit-1-part-6
C++ unit-1-part-6Jadavsejal
 
C++ unit-1-part-5
C++ unit-1-part-5C++ unit-1-part-5
C++ unit-1-part-5Jadavsejal
 
C++ unit-1-part-4
C++ unit-1-part-4C++ unit-1-part-4
C++ unit-1-part-4Jadavsejal
 
C++ unit-1-part-2
C++ unit-1-part-2C++ unit-1-part-2
C++ unit-1-part-2Jadavsejal
 
C++ unit-1-part-3
C++ unit-1-part-3C++ unit-1-part-3
C++ unit-1-part-3Jadavsejal
 
C++-Unit-1-Part-1
C++-Unit-1-Part-1C++-Unit-1-Part-1
C++-Unit-1-Part-1Jadavsejal
 

Más de Jadavsejal (20)

Programming with Java Concept: Java TimeZone Class
Programming with Java Concept: Java TimeZone ClassProgramming with Java Concept: Java TimeZone Class
Programming with Java Concept: Java TimeZone Class
 
Programming Java Concept of Event Handling
Programming Java Concept of Event HandlingProgramming Java Concept of Event Handling
Programming Java Concept of Event Handling
 
Programming Java GUI using SWING, Event Handling
Programming Java GUI using SWING, Event HandlingProgramming Java GUI using SWING, Event Handling
Programming Java GUI using SWING, Event Handling
 
concept of applet and concept of Layout Managers
concept of applet and concept of Layout Managersconcept of applet and concept of Layout Managers
concept of applet and concept of Layout Managers
 
C++ unit-2-part-3
C++ unit-2-part-3C++ unit-2-part-3
C++ unit-2-part-3
 
C++ unit-2-part-2
C++ unit-2-part-2C++ unit-2-part-2
C++ unit-2-part-2
 
C++ unit-2-part-1
C++ unit-2-part-1C++ unit-2-part-1
C++ unit-2-part-1
 
C++ unit-1-part-13
C++ unit-1-part-13C++ unit-1-part-13
C++ unit-1-part-13
 
C++ unit-1-part-12
C++ unit-1-part-12C++ unit-1-part-12
C++ unit-1-part-12
 
C++ unit-1-part-11
C++ unit-1-part-11C++ unit-1-part-11
C++ unit-1-part-11
 
C++ unit-1-part-10
C++ unit-1-part-10C++ unit-1-part-10
C++ unit-1-part-10
 
C++ unit-1-part-9
C++ unit-1-part-9C++ unit-1-part-9
C++ unit-1-part-9
 
C++ unit-1-part-8
C++ unit-1-part-8C++ unit-1-part-8
C++ unit-1-part-8
 
C++ unit-1-part-7
C++ unit-1-part-7C++ unit-1-part-7
C++ unit-1-part-7
 
C++ unit-1-part-6
C++ unit-1-part-6C++ unit-1-part-6
C++ unit-1-part-6
 
C++ unit-1-part-5
C++ unit-1-part-5C++ unit-1-part-5
C++ unit-1-part-5
 
C++ unit-1-part-4
C++ unit-1-part-4C++ unit-1-part-4
C++ unit-1-part-4
 
C++ unit-1-part-2
C++ unit-1-part-2C++ unit-1-part-2
C++ unit-1-part-2
 
C++ unit-1-part-3
C++ unit-1-part-3C++ unit-1-part-3
C++ unit-1-part-3
 
C++-Unit-1-Part-1
C++-Unit-1-Part-1C++-Unit-1-Part-1
C++-Unit-1-Part-1
 

Último

Freegle User Survey as visual display - BH
Freegle User Survey as visual display - BHFreegle User Survey as visual display - BH
Freegle User Survey as visual display - BHbill846304
 
Call Girl Nagpur Roshni Call 7001035870 Meet With Nagpur Escorts
Call Girl Nagpur Roshni Call 7001035870 Meet With Nagpur EscortsCall Girl Nagpur Roshni Call 7001035870 Meet With Nagpur Escorts
Call Girl Nagpur Roshni Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur High Profile
 
webinaire-green-mirror-episode-2-Smart contracts and virtual purchase agreeme...
webinaire-green-mirror-episode-2-Smart contracts and virtual purchase agreeme...webinaire-green-mirror-episode-2-Smart contracts and virtual purchase agreeme...
webinaire-green-mirror-episode-2-Smart contracts and virtual purchase agreeme...Cluster TWEED
 
Russian Call Girls Nashik Anjali 7001305949 Independent Escort Service Nashik
Russian Call Girls Nashik Anjali 7001305949 Independent Escort Service NashikRussian Call Girls Nashik Anjali 7001305949 Independent Escort Service Nashik
Russian Call Girls Nashik Anjali 7001305949 Independent Escort Service Nashikranjana rawat
 
Call Girls Budhwar Peth Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Budhwar Peth Call Me 7737669865 Budget Friendly No Advance BookingCall Girls Budhwar Peth Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Budhwar Peth Call Me 7737669865 Budget Friendly No Advance Bookingroncy bisnoi
 
Call Girls In Okhla DELHI ~9654467111~ Short 1500 Night 6000
Call Girls In Okhla DELHI ~9654467111~ Short 1500 Night 6000Call Girls In Okhla DELHI ~9654467111~ Short 1500 Night 6000
Call Girls In Okhla DELHI ~9654467111~ Short 1500 Night 6000Sapana Sha
 
DENR EPR Law Compliance Updates April 2024
DENR EPR Law Compliance Updates April 2024DENR EPR Law Compliance Updates April 2024
DENR EPR Law Compliance Updates April 2024itadmin50
 
(ANAYA) Call Girls Hadapsar ( 7001035870 ) HI-Fi Pune Escorts Service
(ANAYA) Call Girls Hadapsar ( 7001035870 ) HI-Fi Pune Escorts Service(ANAYA) Call Girls Hadapsar ( 7001035870 ) HI-Fi Pune Escorts Service
(ANAYA) Call Girls Hadapsar ( 7001035870 ) HI-Fi Pune Escorts Serviceranjana rawat
 
VVIP Pune Call Girls Moshi WhatSapp Number 8005736733 With Elite Staff And Re...
VVIP Pune Call Girls Moshi WhatSapp Number 8005736733 With Elite Staff And Re...VVIP Pune Call Girls Moshi WhatSapp Number 8005736733 With Elite Staff And Re...
VVIP Pune Call Girls Moshi WhatSapp Number 8005736733 With Elite Staff And Re...SUHANI PANDEY
 
(DIYA) Call Girls Sinhagad Road ( 7001035870 ) HI-Fi Pune Escorts Service
(DIYA) Call Girls Sinhagad Road ( 7001035870 ) HI-Fi Pune Escorts Service(DIYA) Call Girls Sinhagad Road ( 7001035870 ) HI-Fi Pune Escorts Service
(DIYA) Call Girls Sinhagad Road ( 7001035870 ) HI-Fi Pune Escorts Serviceranjana rawat
 
(ZARA) Call Girls Talegaon Dabhade ( 7001035870 ) HI-Fi Pune Escorts Service
(ZARA) Call Girls Talegaon Dabhade ( 7001035870 ) HI-Fi Pune Escorts Service(ZARA) Call Girls Talegaon Dabhade ( 7001035870 ) HI-Fi Pune Escorts Service
(ZARA) Call Girls Talegaon Dabhade ( 7001035870 ) HI-Fi Pune Escorts Serviceranjana rawat
 
BOOK Call Girls in (Dwarka) CALL | 8377087607 Delhi Escorts Services
BOOK Call Girls in (Dwarka) CALL | 8377087607 Delhi Escorts ServicesBOOK Call Girls in (Dwarka) CALL | 8377087607 Delhi Escorts Services
BOOK Call Girls in (Dwarka) CALL | 8377087607 Delhi Escorts Servicesdollysharma2066
 
Call Girls In Faridabad(Ballabgarh) Book ☎ 8168257667, @4999
Call Girls In Faridabad(Ballabgarh) Book ☎ 8168257667, @4999Call Girls In Faridabad(Ballabgarh) Book ☎ 8168257667, @4999
Call Girls In Faridabad(Ballabgarh) Book ☎ 8168257667, @4999Tina Ji
 
Verified Trusted Kalyani Nagar Call Girls 8005736733 𝐈𝐍𝐃𝐄𝐏𝐄𝐍𝐃𝐄𝐍𝐓 Call 𝐆𝐈𝐑𝐋 𝐕...
Verified Trusted Kalyani Nagar Call Girls  8005736733 𝐈𝐍𝐃𝐄𝐏𝐄𝐍𝐃𝐄𝐍𝐓 Call 𝐆𝐈𝐑𝐋 𝐕...Verified Trusted Kalyani Nagar Call Girls  8005736733 𝐈𝐍𝐃𝐄𝐏𝐄𝐍𝐃𝐄𝐍𝐓 Call 𝐆𝐈𝐑𝐋 𝐕...
Verified Trusted Kalyani Nagar Call Girls 8005736733 𝐈𝐍𝐃𝐄𝐏𝐄𝐍𝐃𝐄𝐍𝐓 Call 𝐆𝐈𝐑𝐋 𝐕...tanu pandey
 
CSR_Tested activities in the classroom -EN
CSR_Tested activities in the classroom -ENCSR_Tested activities in the classroom -EN
CSR_Tested activities in the classroom -ENGeorgeDiamandis11
 

Último (20)

(NEHA) Call Girls Navi Mumbai Call Now 8250077686 Navi Mumbai Escorts 24x7
(NEHA) Call Girls Navi Mumbai Call Now 8250077686 Navi Mumbai Escorts 24x7(NEHA) Call Girls Navi Mumbai Call Now 8250077686 Navi Mumbai Escorts 24x7
(NEHA) Call Girls Navi Mumbai Call Now 8250077686 Navi Mumbai Escorts 24x7
 
Freegle User Survey as visual display - BH
Freegle User Survey as visual display - BHFreegle User Survey as visual display - BH
Freegle User Survey as visual display - BH
 
Green Banking
Green Banking Green Banking
Green Banking
 
Call Girl Nagpur Roshni Call 7001035870 Meet With Nagpur Escorts
Call Girl Nagpur Roshni Call 7001035870 Meet With Nagpur EscortsCall Girl Nagpur Roshni Call 7001035870 Meet With Nagpur Escorts
Call Girl Nagpur Roshni Call 7001035870 Meet With Nagpur Escorts
 
webinaire-green-mirror-episode-2-Smart contracts and virtual purchase agreeme...
webinaire-green-mirror-episode-2-Smart contracts and virtual purchase agreeme...webinaire-green-mirror-episode-2-Smart contracts and virtual purchase agreeme...
webinaire-green-mirror-episode-2-Smart contracts and virtual purchase agreeme...
 
Russian Call Girls Nashik Anjali 7001305949 Independent Escort Service Nashik
Russian Call Girls Nashik Anjali 7001305949 Independent Escort Service NashikRussian Call Girls Nashik Anjali 7001305949 Independent Escort Service Nashik
Russian Call Girls Nashik Anjali 7001305949 Independent Escort Service Nashik
 
Sustainable Packaging
Sustainable PackagingSustainable Packaging
Sustainable Packaging
 
Call Girls Budhwar Peth Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Budhwar Peth Call Me 7737669865 Budget Friendly No Advance BookingCall Girls Budhwar Peth Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Budhwar Peth Call Me 7737669865 Budget Friendly No Advance Booking
 
Call Girls In Okhla DELHI ~9654467111~ Short 1500 Night 6000
Call Girls In Okhla DELHI ~9654467111~ Short 1500 Night 6000Call Girls In Okhla DELHI ~9654467111~ Short 1500 Night 6000
Call Girls In Okhla DELHI ~9654467111~ Short 1500 Night 6000
 
DENR EPR Law Compliance Updates April 2024
DENR EPR Law Compliance Updates April 2024DENR EPR Law Compliance Updates April 2024
DENR EPR Law Compliance Updates April 2024
 
Call Girls In Dhaula Kuan꧁❤ 🔝 9953056974🔝❤꧂ Escort ServiCe
Call Girls In Dhaula Kuan꧁❤ 🔝 9953056974🔝❤꧂ Escort ServiCeCall Girls In Dhaula Kuan꧁❤ 🔝 9953056974🔝❤꧂ Escort ServiCe
Call Girls In Dhaula Kuan꧁❤ 🔝 9953056974🔝❤꧂ Escort ServiCe
 
(ANAYA) Call Girls Hadapsar ( 7001035870 ) HI-Fi Pune Escorts Service
(ANAYA) Call Girls Hadapsar ( 7001035870 ) HI-Fi Pune Escorts Service(ANAYA) Call Girls Hadapsar ( 7001035870 ) HI-Fi Pune Escorts Service
(ANAYA) Call Girls Hadapsar ( 7001035870 ) HI-Fi Pune Escorts Service
 
young Whatsapp Call Girls in Delhi Cantt🔝 9953056974 🔝 escort service
young Whatsapp Call Girls in Delhi Cantt🔝 9953056974 🔝 escort serviceyoung Whatsapp Call Girls in Delhi Cantt🔝 9953056974 🔝 escort service
young Whatsapp Call Girls in Delhi Cantt🔝 9953056974 🔝 escort service
 
VVIP Pune Call Girls Moshi WhatSapp Number 8005736733 With Elite Staff And Re...
VVIP Pune Call Girls Moshi WhatSapp Number 8005736733 With Elite Staff And Re...VVIP Pune Call Girls Moshi WhatSapp Number 8005736733 With Elite Staff And Re...
VVIP Pune Call Girls Moshi WhatSapp Number 8005736733 With Elite Staff And Re...
 
(DIYA) Call Girls Sinhagad Road ( 7001035870 ) HI-Fi Pune Escorts Service
(DIYA) Call Girls Sinhagad Road ( 7001035870 ) HI-Fi Pune Escorts Service(DIYA) Call Girls Sinhagad Road ( 7001035870 ) HI-Fi Pune Escorts Service
(DIYA) Call Girls Sinhagad Road ( 7001035870 ) HI-Fi Pune Escorts Service
 
(ZARA) Call Girls Talegaon Dabhade ( 7001035870 ) HI-Fi Pune Escorts Service
(ZARA) Call Girls Talegaon Dabhade ( 7001035870 ) HI-Fi Pune Escorts Service(ZARA) Call Girls Talegaon Dabhade ( 7001035870 ) HI-Fi Pune Escorts Service
(ZARA) Call Girls Talegaon Dabhade ( 7001035870 ) HI-Fi Pune Escorts Service
 
BOOK Call Girls in (Dwarka) CALL | 8377087607 Delhi Escorts Services
BOOK Call Girls in (Dwarka) CALL | 8377087607 Delhi Escorts ServicesBOOK Call Girls in (Dwarka) CALL | 8377087607 Delhi Escorts Services
BOOK Call Girls in (Dwarka) CALL | 8377087607 Delhi Escorts Services
 
Call Girls In Faridabad(Ballabgarh) Book ☎ 8168257667, @4999
Call Girls In Faridabad(Ballabgarh) Book ☎ 8168257667, @4999Call Girls In Faridabad(Ballabgarh) Book ☎ 8168257667, @4999
Call Girls In Faridabad(Ballabgarh) Book ☎ 8168257667, @4999
 
Verified Trusted Kalyani Nagar Call Girls 8005736733 𝐈𝐍𝐃𝐄𝐏𝐄𝐍𝐃𝐄𝐍𝐓 Call 𝐆𝐈𝐑𝐋 𝐕...
Verified Trusted Kalyani Nagar Call Girls  8005736733 𝐈𝐍𝐃𝐄𝐏𝐄𝐍𝐃𝐄𝐍𝐓 Call 𝐆𝐈𝐑𝐋 𝐕...Verified Trusted Kalyani Nagar Call Girls  8005736733 𝐈𝐍𝐃𝐄𝐏𝐄𝐍𝐃𝐄𝐍𝐓 Call 𝐆𝐈𝐑𝐋 𝐕...
Verified Trusted Kalyani Nagar Call Girls 8005736733 𝐈𝐍𝐃𝐄𝐏𝐄𝐍𝐃𝐄𝐍𝐓 Call 𝐆𝐈𝐑𝐋 𝐕...
 
CSR_Tested activities in the classroom -EN
CSR_Tested activities in the classroom -ENCSR_Tested activities in the classroom -EN
CSR_Tested activities in the classroom -EN
 

C++ unit-1-part-15

  • 1. prezentr.com! Prepared By: Asst. Prof. Sejal Jadav Unit-1 Principles of Object Oriented Programming Tokens, expressions & Control Statements (14 MARKS) B.C.A & B.Sc.(IT) – 3 CS-13 C++ and Object Oriented Programming
  • 2. prezentr.com! Prepared By: Asst. Prof. Sejal Jadav Control Structures
  • 3. prezentr.com! Prepared By: Asst. Prof. Sejal Jadav Control Structures
  • 4. prezentr.com! Prepared By: Asst. Prof. Sejal Jadav • In C++ programming, if statement is used to test the condition. There are various types of if statements in C++. 1. if statement 2. if-else statement 3. nested if statement 4. if-else-if ladder
  • 5. prezentr.com! Prepared By: Asst. Prof. Sejal Jadav IF Statement • If the Boolean expression evaluates to true, then the block of code inside the if statement will be executed. • If Boolean expression evaluates to false, then the first set of code after the end of the if statement (after the closing curly brace) will be executed.
  • 6. prezentr.com! Prepared By: Asst. Prof. Sejal Jadav IF Statement • The C++ if statement tests the condition. It is executed if condition is true. if(condition) { //code to be executed }
  • 7. prezentr.com! Prepared By: Asst. Prof. Sejal Jadav C++ If Example: 1_IFExample.cpp
  • 8. prezentr.com! Prepared By: Asst. Prof. Sejal Jadav if...else statement • An if statement can be followed by an optional else statement, which executes when the Boolean expression is false.
  • 9. prezentr.com! Prepared By: Asst. Prof. Sejal Jadav Syntax if(boolean_expression) { // statement(s) will execute if the boolean expression is true }else{ // statement(s) will execute if the boolean expression is false }
  • 10. prezentr.com! Prepared By: Asst. Prof. Sejal Jadav • If the boolean expression evaluates to true, then the if block of code will be executed, otherwise else block of code will be executed.
  • 11. prezentr.com! Prepared By: Asst. Prof. Sejal Jadav Example: 2_IF_Else.cpp
  • 12. prezentr.com! Prepared By: Asst. Prof. Sejal Jadav if...else if...else Statement • An if statement can be followed by an optional else if...else statement, which is very useful to test various conditions using single if...else if statement.
  • 13. prezentr.com! Prepared By: Asst. Prof. Sejal Jadav Syntax and Example:3_if_elseif_else.cpp if(boolean_expression 1) { // Executes when the boolean expression 1 is true } else if( boolean_expression 2) { // Executes when the boolean expression 2 is true } else if( boolean_expression 3) { // Executes when the boolean expression 3 is true } else { // executes when the none of the above condition is true. }
  • 14. prezentr.com! Prepared By: Asst. Prof. Sejal Jadav nested if statements • It is always legal to nest if-else statements, which means you can use one if or else if statement inside another if or else if statement(s).
  • 15. prezentr.com! Prepared By: Asst. Prof. Sejal Jadav Syntax if( boolean_expression 1) { // Executes when the boolean expression 1 is true if(boolean_expression 2) { // Executes when the boolean expression 2 is true } } Let’s see example -> Example: Nested_if.cpp
  • 16. prezentr.com! Prepared By: Asst. Prof. Sejal Jadav switch statement • A switch statement allows a variable to be tested for equality against a list of values. Each value is called a case, and the variable being switched on is checked for each case.
  • 17. prezentr.com! Prepared By: Asst. Prof. Sejal Jadav Syntax switch(expression) { case constant-expression : statement(s); break; //optional case constant-expression : statement(s); break; //optional // you can have any number of case statements. default : //Optional statement(s); }
  • 18. prezentr.com! Prepared By: Asst. Prof. Sejal Jadav Example: 5_Switch.cpp
  • 19. prezentr.com! Prepared By: Asst. Prof. Sejal Jadav Looping Control Structure
  • 20. prezentr.com! Prepared By: Asst. Prof. Sejal Jadav • There may be a situation, when you need to execute a block of code several number of times. In general, statements are executed sequentially: The first statement in a function is executed first, followed by the second, and so on. • Programming languages provide various control structures that allow for more complicated execution paths.
  • 21. prezentr.com! Prepared By: Asst. Prof. Sejal Jadav • 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 −
  • 22. prezentr.com! Prepared By: Asst. Prof. Sejal Jadav • C++ programming language provides the following type of loops to handle looping requirements. 1. for, 2. while, 3. do… while
  • 23. prezentr.com! Prepared By: Asst. Prof. Sejal Jadav For Loop • A for loop is a repetition control structure that allows you to efficiently write a loop that needs to execute a specific number of times.
  • 24. prezentr.com! Prepared By: Asst. Prof. Sejal Jadav Syntax The syntax of a for loop in C++ is − for ( init; condition; increment ) { statement(s); }
  • 25. prezentr.com! Prepared By: Asst. Prof. Sejal Jadav • Here is the flow of control in a for loop − • The init step is executed first, and only once. This step allows you to declare and initialize any loop control variables. You are not required to put a statement here, as long as a semicolon appears.
  • 26. prezentr.com! Prepared By: Asst. Prof. Sejal Jadav • Next, the condition is evaluated. If it is true, the body of the loop is executed. If it is false, the body of the loop does not execute and flow of control jumps to the next statement just after the for loop.
  • 27. prezentr.com! Prepared By: Asst. Prof. Sejal Jadav • After the body of the for loop executes, the flow of control jumps back up to the increment statement.
  • 28. prezentr.com! Prepared By: Asst. Prof. Sejal Jadav • The condition is now evaluated again. If it is true, the loop executes and the process repeats itself (body of loop, then increment step, and then again condition). After the condition becomes false, the for loop terminates.
  • 29. prezentr.com! Prepared By: Asst. Prof. Sejal Jadav Example: ForLoop.cpp
  • 30. prezentr.com! Prepared By: Asst. Prof. Sejal Jadav while loop • A while loop statement repeatedly executes a target statement as long as a given condition is true.
  • 31. prezentr.com! Prepared By: Asst. Prof. Sejal Jadav Syntax • The syntax of a while loop in C++ is - while(condition) { statement(s); }
  • 32. prezentr.com! Prepared By: Asst. Prof. Sejal Jadav • Here, statement(s) may be a single statement or a block of statements. The condition may be any expression, and true is any non-zero value. The loop iterates while the condition is true. • When the condition becomes false, program control passes to the line immediately following the loop.
  • 33. prezentr.com! Prepared By: Asst. Prof. Sejal Jadav Example:9_while.cpp Example:9_whileLoop.cpp
  • 34. prezentr.com! Prepared By: Asst. Prof. Sejal Jadav • Here, key point of the while loop is that the loop might not ever run. When the condition is tested and the result is false, the loop body will be skipped and the first statement after the while loop will be executed.
  • 35. prezentr.com! Prepared By: Asst. Prof. Sejal Jadav do...while loop • Unlike for and while loops, which test the loop condition at the top of the loop, the do...while loop checks its condition at the bottom of the loop. • A do...while loop is similar to a while loop, except that a do...while loop is guaranteed to execute at least one time.
  • 36. prezentr.com! Prepared By: Asst. Prof. Sejal Jadav Syntax do { statement(s); } while( condition );
  • 37. prezentr.com! Prepared By: Asst. Prof. Sejal Jadav • Notice that the conditional expression appears at the end of the loop, so the statement(s) in the loop execute once before the condition is tested. • If the condition is true, the flow of control jumps back up to do, and the statement(s) in the loop execute again. This process repeats until the given condition becomes false.
  • 38. prezentr.com! Prepared By: Asst. Prof. Sejal Jadav Example: 10_do_while.cpp Example: dowhile.cpp
  • 39. prezentr.com! Prepared By: Asst. Prof. Sejal Jadav Example: 6_infinite.cpp #include <iostream> using namespace std; int main () { for( ; ; ) { printf("This loop will run forever.n"); } return 0; }
  • 40. prezentr.com! Prepared By: Asst. Prof. Sejal Jadav • A loop becomes infinite loop if a condition never becomes false. The for loop is traditionally used for this purpose. Since none of the three expressions that form the ‘for’ loop are required, you can make an endless loop by leaving the conditional expression empty.
  • 41. prezentr.com! Prepared By: Asst. Prof. Sejal Jadav • When the conditional expression is absent, it is assumed to be true. You may have an initialization and increment expression, but C++ programmers more commonly use the ‘for (;;)’ construct to signify an infinite loop. • NOTE − You can terminate an infinite loop by pressing Ctrl + C keys.