Sanjivani Rural Education Society’s
Sanjivani College of Engineering, Kopargaon-423 603
(An Autonomous Institute, Affiliated to Savitribai Phule Pune University, Pune)
NAAC ‘A’Grade Accredited, ISO 9001:2015 Certified
Department of Computer Engineering
(NBA Accredited)
Subject- Object Oriented Programming (CO212)
Unit 1 – Fundamentals of OOP
Topic – 1.6 Control Structures in C++
Prof. V.N.Nirgude
Assistant Professor
E-mail :
nirgudevikascomp@sanjivani.org.in
Contact No: 9975240215
Control Structures in C++
⚫Controlstructuresareused toaffect howstatementsareexecuted.
⚫Sequence structure (Straight
line)
⚫Selection structure(Branching)
⚫Loop structure (Iteration)
DEPARTMENT OF COMPUTER ENGINEERING ,SCOE,KOPARGAON 2
Sequence Structure
⚫Statementsareexecuted oneafterthe
other.
⚫This is C++'sdefaultbehavior!
DEPARTMENT OF COMPUTER ENGINEERING ,SCOE,KOPARGAON 3
Selection Structure
• It is used tochooseamong alternative actions.
• Making decisions
•If
•if/else
•switch
DEPARTMENT OF COMPUTER ENGINEERING ,SCOE,KOPARGAON 4
If selection structure
⚫Used todosomething if somecondition is
“true”.
DEPARTMENT OF COMPUTER ENGINEERING ,SCOE,KOPARGAON 5
If/else selection structure
⚫Used todoone thing if somecondition is “true” and something
else if the condition is“false”.
DEPARTMENT OF COMPUTER ENGINEERING ,SCOE,KOPARGAON 6
Switch Selection structure
⚫This is a multiple-Branching Statement where based on a condition the
control is transferred tooneof the many possiblepoints.
cout<<“Operatornot matched..”;
}
DEPARTMENT OF COMPUTER ENGINEERING ,SCOE,KOPARGAON 7
Loop structure
⚫Used to repeat a setof
instructions.
⚫Looping
•Do-While loop
•While loop
•Forloop
DEPARTMENT OF COMPUTER ENGINEERING ,SCOE,KOPARGAON 8
Do-While Loop structure
⚫The do-while is an exit-controlled loop. Based on a condition the control
istransferred back toaparticular point in theprogram.
Output:
0
1
2
3
4
5
DEPARTMENT OF COMPUTER ENGINEERING ,SCOE,KOPARGAON 9
While Loop structure
⚫Thewhile loop isan entry-controlled loop
.
Output:
0
1
2
3
4
5
DEPARTMENT OF COMPUTER ENGINEERING ,SCOE,KOPARGAON 10
For Loop structure
⚫forisan entry-controlled loopand isused whenan action is to be repeated
for a numberof times.
Output:
1
2
3
4
5
DEPARTMENT OF COMPUTER ENGINEERING ,SCOE,KOPARGAON 11
Task to be perform using appropriate control structure
DEPARTMENT OF COMPUTER ENGINEERING ,SCOE,KOPARGAON 12
• Write a program to check number is prime or not.
• Write a program to check number is amstrong number or not.
• Write a program to find palidrome number
• Write a program to print following output:
1
1 2
1 2 3
1 2 3 4
1 2 3 4 5
Thank you..
DEPARTMENT OF COMPUTER ENGINEERING ,SCOE,KOPARGAON 13

1.6 Control Structures in C++ .......pdf

  • 1.
    Sanjivani Rural EducationSociety’s Sanjivani College of Engineering, Kopargaon-423 603 (An Autonomous Institute, Affiliated to Savitribai Phule Pune University, Pune) NAAC ‘A’Grade Accredited, ISO 9001:2015 Certified Department of Computer Engineering (NBA Accredited) Subject- Object Oriented Programming (CO212) Unit 1 – Fundamentals of OOP Topic – 1.6 Control Structures in C++ Prof. V.N.Nirgude Assistant Professor E-mail : nirgudevikascomp@sanjivani.org.in Contact No: 9975240215
  • 2.
    Control Structures inC++ ⚫Controlstructuresareused toaffect howstatementsareexecuted. ⚫Sequence structure (Straight line) ⚫Selection structure(Branching) ⚫Loop structure (Iteration) DEPARTMENT OF COMPUTER ENGINEERING ,SCOE,KOPARGAON 2
  • 3.
    Sequence Structure ⚫Statementsareexecuted oneafterthe other. ⚫Thisis C++'sdefaultbehavior! DEPARTMENT OF COMPUTER ENGINEERING ,SCOE,KOPARGAON 3
  • 4.
    Selection Structure • Itis used tochooseamong alternative actions. • Making decisions •If •if/else •switch DEPARTMENT OF COMPUTER ENGINEERING ,SCOE,KOPARGAON 4
  • 5.
    If selection structure ⚫Usedtodosomething if somecondition is “true”. DEPARTMENT OF COMPUTER ENGINEERING ,SCOE,KOPARGAON 5
  • 6.
    If/else selection structure ⚫Usedtodoone thing if somecondition is “true” and something else if the condition is“false”. DEPARTMENT OF COMPUTER ENGINEERING ,SCOE,KOPARGAON 6
  • 7.
    Switch Selection structure ⚫Thisis a multiple-Branching Statement where based on a condition the control is transferred tooneof the many possiblepoints. cout<<“Operatornot matched..”; } DEPARTMENT OF COMPUTER ENGINEERING ,SCOE,KOPARGAON 7
  • 8.
    Loop structure ⚫Used torepeat a setof instructions. ⚫Looping •Do-While loop •While loop •Forloop DEPARTMENT OF COMPUTER ENGINEERING ,SCOE,KOPARGAON 8
  • 9.
    Do-While Loop structure ⚫Thedo-while is an exit-controlled loop. Based on a condition the control istransferred back toaparticular point in theprogram. Output: 0 1 2 3 4 5 DEPARTMENT OF COMPUTER ENGINEERING ,SCOE,KOPARGAON 9
  • 10.
    While Loop structure ⚫Thewhileloop isan entry-controlled loop . Output: 0 1 2 3 4 5 DEPARTMENT OF COMPUTER ENGINEERING ,SCOE,KOPARGAON 10
  • 11.
    For Loop structure ⚫forisanentry-controlled loopand isused whenan action is to be repeated for a numberof times. Output: 1 2 3 4 5 DEPARTMENT OF COMPUTER ENGINEERING ,SCOE,KOPARGAON 11
  • 12.
    Task to beperform using appropriate control structure DEPARTMENT OF COMPUTER ENGINEERING ,SCOE,KOPARGAON 12 • Write a program to check number is prime or not. • Write a program to check number is amstrong number or not. • Write a program to find palidrome number • Write a program to print following output: 1 1 2 1 2 3 1 2 3 4 1 2 3 4 5
  • 13.
    Thank you.. DEPARTMENT OFCOMPUTER ENGINEERING ,SCOE,KOPARGAON 13