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