The document discusses selection statements in C++ programming. It covers one-way selection using if statements, two-way selection using if-else statements, and multiple selections using else-if statements and switch statements. Examples are provided to demonstrate calculating employee salary and determining whether a number is even, odd, positive or negative. Exercises are included to write programs to find the largest of three numbers, assign grades based on marks, and calculate BMI. Nested if-else statements and when to use different selection statements are also explained.
Fundamentals of Computer Programming Summary of Flow ControlsChereLemma2
The document discusses fundamentals of computer programming using C++, including program flow controls like selection and loop statements. It defines flow control and different types of selection statements like if, if-else, and switch statements. Loop statements like while, for, and do-while are also covered. The objectives are to use these flow controls to design programs that can evaluate conditions and execute code repeatedly. Recommended reading materials on these topics from various books and online sources are also provided.
The document discusses program statements in Java. It covers:
- The four basic activities of program development: establishing requirements, creating a design, implementing code, and testing.
- Conditional statements like if, if-else, and switch that allow modifying the flow of control through a method.
- Logical operators like && and || that can be used to form complex boolean expressions for conditionals.
This document discusses decision making and conditional logic in Microsoft Visual Basic programs. It explains how comparisons return true or false values and how conditional operators are used to make comparisons. If statements allow code to execute conditionally based on a true or false evaluation. If-else statements provide a two-path decision structure. Flowcharts help visualize program logic and decision points. Checkboxes store true/false values to represent yes/no selections. Logical operators combine comparisons and logical operators are evaluated in a specific order.
The document outlines the sessions and topics covered in a Beginning Access VBA course. Session 1 covers event driven programming in Access, while Session 2 focuses on VBA language constructs and programming techniques like making decisions using IF/ELSE and SELECT CASE statements, repetitions using FOR/NEXT and DO/LOOP, calling functions and procedures, using message boxes, and debugging techniques. Specific techniques demonstrated include IF statements, SELECT CASE, FOR/NEXT loops, DO/LOOP, calling and returning functions, and using message boxes with buttons and icons.
Chapter 4 flow control structures and arrayssshhzap
The document discusses various flow control structures in programming like algorithms, flowcharts, and different types of loops and conditional statements in Java like if-else statements, switch statements, for loops and while loops. It provides examples of each structure and explains their usage and syntax.
Visual Basic provides various control structures like selection statements (if/else), looping statements (for, while), and arrays to control program flow and work with multiple data elements. Selection statements allow programs to make decisions and perform different actions based on certain conditions. Looping statements let programs repeat blocks of code until a condition is met. Arrays allow programs to work with multiple values as a single variable. Functions and procedures let programmers organize code into reusable blocks to make programs clearer and easier to debug.
The document provides an introduction to control structures and programming concepts in Visual Basic, including decision making statements, looping statements, arrays, functions, procedures, and control arrays. It discusses various conditional structures like if-then and select-case statements. It also covers different types of loops like for-next loops and do-while loops. The use of arrays, both fixed-size and dynamic, in VB programming is explained. Finally, it discusses various built-in functions and different types of procedures in Visual Basic.
Fundamentals of Programming Lecture #1.pptxEyasu46
This document provides an overview of programming and problem solving concepts. It discusses that a problem is a situation that needs resolution, while a solution removes the problematic situation. Problem solving is the process of deriving a solution. Programming involves creating computer solutions to problems through algorithms expressed as programs. Key steps for problem solving are understanding the problem, planning an algorithm/solution, implementing it as a program, testing the program, documenting it, and maintaining it for changes. Pseudocode and flowcharts are common ways to describe algorithms before implementing them as programs.
This document provides an overview of key concepts in C++ programming including #include directives, inputs/outputs, variables, data types, selection, iteration, data structures, and functions. It explains each concept in 3 sentences or less and provides links to example programs. The tutorial covers the basics of coding in C++ like variable declaration, assignment, logical/arithmetic operators, and using functions with parameters and return values. It emphasizes setting up a development environment and includes examples to demonstrate each programming concept discussed.
The document discusses control structures in C programming. It defines control structures as determining the order of statement execution and categorizes them as sequential, conditional, or iterative. Conditional statements include if-else statements, switch statements, and ternary operators for decision making. Iterative statements include for, while, and do-while loops for repetitive execution. The document provides syntax examples and flowcharts for each control structure. It also discusses jumping statements like goto, break, and continue that alter normal program flow.
This document provides an overview of control structures in Visual Basic. It describes the three types of control structures: sequence, selection, and iteration. Sequence refers to the default sequential execution of statements. Selection structures like If/Then/Else and Select Case allow branching program execution based on conditions. Iteration structures like For/Next loops and Do/Loop statements allow repeating a block of code until a condition is met. The document provides details and syntax examples for If/Then/Else, Select Case, For/Next loops, and Do/Loop in Visual Basic.
Notes how to work with variables, constants and do calculationsWilliam Olivier
1. The document discusses different ways of storing and working with data in a Visual C++ application, including variables, constants, arrays, and structures.
2. It explains the differences between local and global scope for variables and constants, and shows examples of declaring identifiers in each scope.
3. The document also demonstrates how to convert between data types like string and double when retrieving user input and performing calculations.
Introduction to computer programming (C)-CSC1205_Lec5_Flow controlENGWAU TONNY
The document discusses different types of flow control in programming including sequential, selection, and repetition structures. It provides examples of if/else statements, nested ifs, if-else ladders, and the conditional operator. It also covers switch-case statements as an alternative for complex decisions. Finally, it poses challenges for readers to code decision-making structures using if/else and switch-case statements.
This document discusses various program flow control statements in Java, including selection statements (if, if-else, switch), iteration statements (for, while, do-while), and jump statements (return, break, continue). It provides examples and comparisons of these statements. The document is intended as teaching material, as it includes sections on classwork, homework, and was created by an instructor.
This document discusses the key phases of the Software Development Method (SDM) framework: specification of needs, problem analysis, design and algorithmic representation, implementation, testing and verification, and documentation. It provides details on each phase, including defining the problem and needed solution, identifying inputs/outputs, designing algorithms using pseudocode and flowcharts, implementing the program, testing it, and documenting the process. Pseudocode and flowcharts are presented as ways to formally represent algorithms using basic structures like sequence, selection, and repetition. The document emphasizes that documentation should be an ongoing process throughout the entire software development lifecycle.
C++ provides various programming constructs including variables, operators, conditionals, and functions. The document outlines the basic program structure in C++ and describes several key elements. It explains that a C++ program contains a main function and optionally additional functions, and source code can be split across multiple files. It then discusses operators like arithmetic, logical, and assignment operators and how they are evaluated based on precedence. Several conditional statements like if-else, for, while, do-while, switch, break and continue are also covered along with examples. Finally, it briefly introduces variable types in C++.
GUI Programming in JAVA (Using Netbeans) - A ReviewFernando Torres
The powerpoint provides the user with a review of various concepts of GUI programming in JAVA. It covers various concepts like :
1. What is IDE ?
2. Various Methods and Properties of Components
3. Variable declaration
4. Data types
Etc
The document discusses various software testing techniques including:
- Unit testing techniques like white box testing, gray box testing, and equivalence partitioning
- Integration testing techniques like boundary value analysis and error guessing
- The iterative process of test-driven development where tests are written before implementing features
It provides an example of using these techniques to test a TrafficSignal class through a series of test methods.
This document provides an overview of scope management and work breakdown structures (WBS). It begins with key concepts such as product scope, project scope, and the processes of scope management. It then discusses planning scope management and collecting requirements. Considerable detail is provided on defining the project scope, including developing a project scope statement, identifying what is in/out of scope, and documenting assumptions and constraints. The document focuses on WBS, explaining what it is, its benefits, elements and how to create one using different approaches and formats. An example of a WBS for developing a personal portfolio website is also included.
More Related Content
Similar to Fundamentals of Computer Programming - Flow of Control I (20)
Fundamentals of Programming Lecture #1.pptxEyasu46
This document provides an overview of programming and problem solving concepts. It discusses that a problem is a situation that needs resolution, while a solution removes the problematic situation. Problem solving is the process of deriving a solution. Programming involves creating computer solutions to problems through algorithms expressed as programs. Key steps for problem solving are understanding the problem, planning an algorithm/solution, implementing it as a program, testing the program, documenting it, and maintaining it for changes. Pseudocode and flowcharts are common ways to describe algorithms before implementing them as programs.
This document provides an overview of key concepts in C++ programming including #include directives, inputs/outputs, variables, data types, selection, iteration, data structures, and functions. It explains each concept in 3 sentences or less and provides links to example programs. The tutorial covers the basics of coding in C++ like variable declaration, assignment, logical/arithmetic operators, and using functions with parameters and return values. It emphasizes setting up a development environment and includes examples to demonstrate each programming concept discussed.
The document discusses control structures in C programming. It defines control structures as determining the order of statement execution and categorizes them as sequential, conditional, or iterative. Conditional statements include if-else statements, switch statements, and ternary operators for decision making. Iterative statements include for, while, and do-while loops for repetitive execution. The document provides syntax examples and flowcharts for each control structure. It also discusses jumping statements like goto, break, and continue that alter normal program flow.
This document provides an overview of control structures in Visual Basic. It describes the three types of control structures: sequence, selection, and iteration. Sequence refers to the default sequential execution of statements. Selection structures like If/Then/Else and Select Case allow branching program execution based on conditions. Iteration structures like For/Next loops and Do/Loop statements allow repeating a block of code until a condition is met. The document provides details and syntax examples for If/Then/Else, Select Case, For/Next loops, and Do/Loop in Visual Basic.
Notes how to work with variables, constants and do calculationsWilliam Olivier
1. The document discusses different ways of storing and working with data in a Visual C++ application, including variables, constants, arrays, and structures.
2. It explains the differences between local and global scope for variables and constants, and shows examples of declaring identifiers in each scope.
3. The document also demonstrates how to convert between data types like string and double when retrieving user input and performing calculations.
Introduction to computer programming (C)-CSC1205_Lec5_Flow controlENGWAU TONNY
The document discusses different types of flow control in programming including sequential, selection, and repetition structures. It provides examples of if/else statements, nested ifs, if-else ladders, and the conditional operator. It also covers switch-case statements as an alternative for complex decisions. Finally, it poses challenges for readers to code decision-making structures using if/else and switch-case statements.
This document discusses various program flow control statements in Java, including selection statements (if, if-else, switch), iteration statements (for, while, do-while), and jump statements (return, break, continue). It provides examples and comparisons of these statements. The document is intended as teaching material, as it includes sections on classwork, homework, and was created by an instructor.
This document discusses the key phases of the Software Development Method (SDM) framework: specification of needs, problem analysis, design and algorithmic representation, implementation, testing and verification, and documentation. It provides details on each phase, including defining the problem and needed solution, identifying inputs/outputs, designing algorithms using pseudocode and flowcharts, implementing the program, testing it, and documenting the process. Pseudocode and flowcharts are presented as ways to formally represent algorithms using basic structures like sequence, selection, and repetition. The document emphasizes that documentation should be an ongoing process throughout the entire software development lifecycle.
C++ provides various programming constructs including variables, operators, conditionals, and functions. The document outlines the basic program structure in C++ and describes several key elements. It explains that a C++ program contains a main function and optionally additional functions, and source code can be split across multiple files. It then discusses operators like arithmetic, logical, and assignment operators and how they are evaluated based on precedence. Several conditional statements like if-else, for, while, do-while, switch, break and continue are also covered along with examples. Finally, it briefly introduces variable types in C++.
GUI Programming in JAVA (Using Netbeans) - A ReviewFernando Torres
The powerpoint provides the user with a review of various concepts of GUI programming in JAVA. It covers various concepts like :
1. What is IDE ?
2. Various Methods and Properties of Components
3. Variable declaration
4. Data types
Etc
The document discusses various software testing techniques including:
- Unit testing techniques like white box testing, gray box testing, and equivalence partitioning
- Integration testing techniques like boundary value analysis and error guessing
- The iterative process of test-driven development where tests are written before implementing features
It provides an example of using these techniques to test a TrafficSignal class through a series of test methods.
This document provides an overview of scope management and work breakdown structures (WBS). It begins with key concepts such as product scope, project scope, and the processes of scope management. It then discusses planning scope management and collecting requirements. Considerable detail is provided on defining the project scope, including developing a project scope statement, identifying what is in/out of scope, and documenting assumptions and constraints. The document focuses on WBS, explaining what it is, its benefits, elements and how to create one using different approaches and formats. An example of a WBS for developing a personal portfolio website is also included.
Ch-3(b) - Variables and Data types in C++.pptxChereLemma2
The document provides an overview of fundamentals of computer programming using C++. It discusses topics like variables and data types, variable declaration and initialization, constants and literals, library functions, and preprocessors. The document contains lecture notes, objectives, examples, exercises and solutions to demonstrate concepts like defining variables, differentiating between data types, using constants, escape sequences, and including library header files.
Chapter 6 - Modular Programming- in C++.pptxChereLemma2
Here is a function that meets the requirements:
int getProduct(int num1, double num2) {
return num1 * num2;
}
This function:
- Is named getProduct
- Has two parameters: num1 which is an int, and num2 which is a double
- Returns the product of num1 and num2 by multiplying them together and returning the result
- Complies with the data types and operation specified in the requirements
User Defined Datatypes in C++ (Union, enum, class)ChereLemma2
This document discusses various user-defined data types in C++ including structures, unions, enumerations, and classes. It provides examples and explanations of how to define and use each data type. Structures allow grouping of different data types while unions share the same memory space for mutually exclusive members. Enumerations define a set of named integer constants. Typedef creates synonyms for existing types. Classes represent user-defined data types that model real-world entities through attributes and behaviors.
File Management and manipulation in C++ ProgrammingChereLemma2
The document discusses file handling in C++. It covers the basics of file management including the different types of files, file streams, and the file manipulation process. The key steps in the file manipulation process are: 1) declaring a file stream object; 2) opening a file using the file stream object; 3) checking if the file opened successfully; and 4) performing read and write operations on the file. The document provides examples of writing to and reading from files in C++.
Basic Concepts of Programming - Practical ExercisesChereLemma2
This document provides an overview of a fundamentals of computer programming course using C++. It outlines exercises on algorithm design, program writing, and problem solving. The objectives are to solve small problems using techniques like flowcharts and pseudocode, write and run simple programs, and explain program translation and execution. Example exercises include calculating BMI from user input height and weight, finding miles driven from fuel tank size and mileage, and converting letters between uppercase and lowercase. Reading materials suggested include programming books and eBook chapters on problem solving with C++.
Fundamentals of Computer Programming in C++ Key ConceptsChereLemma2
This document provides a summary of key concepts from a computer programming fundamentals textbook. It outlines 9 chapters that cover basic programming concepts like variables, data types, operators, and control flow structures. Specific topics discussed include algorithms, programming languages, problem solving skills, C++ program structure, arrays, strings, pointers, functions, structures, file handling, and templates/vectors. The overall document serves as a table of contents to introduce readers to core programming topics covered in the textbook.
Students will research and orally present a Colombian company using a visual tool, in order to develop their communication skills and intercultural understanding through the exploration of identity, innovation, and local culture, in connection with the IB global themes.
Odoo 18 Point of Sale PWA - Odoo SlidesCeline George
Progressive Web Apps (PWA) are web applications that deliver an app-like experience using modern web technologies, offering features like offline functionality, installability, and responsiveness across devices.
How to Setup Lunch in Odoo 18 - Odoo guidesCeline George
In Odoo 18, the Lunch application allows users a convenient way to order food and pay for their meal directly from the database. Lunch in Odoo 18 is a handy application designed to streamline and manage employee lunch orders within a company.
Principal Satbir Singh writes “Kaba and Kitab i.e. Building Harmandir Sahib and Compilation of Granth Sahib gave Sikhs a central place of worship and a Holy book is the single most important reason for Sikhism to flourish as a new religion which gave them a identity which was separate from Hindu’s and Muslim’s.
How to create and manage blogs in odoo 18Celine George
A blog serves as a space for sharing articles and information.
In Odoo 18, users can easily create and publish blogs through
the blog menu. This guide offers step-by-step instructions on
setting up and managing a blog on an Odoo 18 website.
Updated About Me. Used for former college assignments.
Make sure to catch our weekly updates. Updates are done Thursday to Fridays or its a holiday/event weekend.
Thanks again, Readers, Guest Students, and Loyalz/teams.
This profile is older. I started at the beginning of my HQ journey online. It was recommended by AI. AI was very selective but fits my ecourse style. I am media flexible depending on the course platform. More information below.
AI Overview:
“LDMMIA Reiki Yoga refers to a specific program of free online workshops focused on integrating Reiki energy healing techniques with yoga practices. These workshops are led by Leslie M. Moore, also known as LDMMIA, and are designed for all levels, from beginners to those seeking to review their practice. The sessions explore various themes like "Matrix," "Alice in Wonderland," and "Goddess," focusing on self-discovery, inner healing, and shifting personal realities.”
ISO 27001 Lead Auditor Exam Practice Questions and Answers-.pdfinfosec train
🧠 𝐏𝐫𝐞𝐩𝐚𝐫𝐢𝐧𝐠 𝐟𝐨𝐫 𝐭𝐡𝐞 𝐈𝐒𝐎 𝟐𝟕𝟎𝟎𝟏 𝐋𝐞𝐚𝐝 𝐀𝐮𝐝𝐢𝐭𝐨𝐫 𝐄𝐱𝐚𝐦? 𝐃𝐨𝐧’𝐭 𝐉𝐮𝐬𝐭 𝐒𝐭𝐮𝐝𝐲—𝐏𝐫𝐚𝐜𝐭𝐢𝐜𝐞 𝐰𝐢𝐭𝐡 𝐏𝐮𝐫𝐩𝐨𝐬𝐞!
We’ve compiled a 𝐜𝐨𝐦𝐩𝐫𝐞𝐡𝐞𝐧𝐬𝐢𝐯𝐞 𝐰𝐡𝐢𝐭𝐞 𝐩𝐚𝐩𝐞𝐫 featuring 𝐫𝐞𝐚𝐥𝐢𝐬𝐭𝐢𝐜, 𝐬𝐜𝐞𝐧𝐚𝐫𝐢𝐨-𝐛𝐚𝐬𝐞𝐝 𝐩𝐫𝐚𝐜𝐭𝐢𝐜𝐞 𝐪𝐮𝐞𝐬𝐭𝐢𝐨𝐧𝐬 𝐚𝐧𝐝 𝐚𝐧𝐬𝐰𝐞𝐫𝐬 designed specifically for those targeting the 𝐈𝐒𝐎/𝐈𝐄𝐂 𝟐𝟕𝟎𝟎𝟏 𝐋𝐞𝐚𝐝 𝐀𝐮𝐝𝐢𝐭𝐨𝐫 𝐜𝐞𝐫𝐭𝐢𝐟𝐢𝐜𝐚𝐭𝐢𝐨𝐧.
🔍 𝐈𝐧𝐬𝐢𝐝𝐞 𝐲𝐨𝐮'𝐥𝐥 𝐟𝐢𝐧𝐝:
✅ Exam-style questions mapped to ISO 27001:2022
✅ Detailed explanations (not just the right answer—but why it’s right)
✅ Mnemonics, control references (like A.8.8, A.5.12, A.8.24), and study tips
✅ Key audit scenarios: nonconformities, SoA vs scope, AART treatment options, CIA triad, and more
𝐖𝐡𝐞𝐭𝐡𝐞𝐫 𝐲𝐨𝐮'𝐫𝐞:
🔹 Starting your ISO journey
🔹 Preparing for your Lead Auditor exam
🔹 Or mentoring others in information security audits...
This guide can seriously boost your confidence and performance.
Active Surveillance For Localized Prostate Cancer A New Paradigm For Clinical...wygalkelceqg
Active Surveillance For Localized Prostate Cancer A New Paradigm For Clinical Management 2nd Ed Klotz
Active Surveillance For Localized Prostate Cancer A New Paradigm For Clinical Management 2nd Ed Klotz
Active Surveillance For Localized Prostate Cancer A New Paradigm For Clinical Management 2nd Ed Klotz
How to Manage Orders in Odoo 18 Lunch - Odoo SlidesCeline George
The Lunch module in Odoo 18 helps users place their food orders, making meal management seamless and efficient. It allows employees to browse available options, place orders, and track their meals effortlessly.
Here is the current update:
CURRENT CASE COUNT: 897
- Texas: 742 (+14) (55% of cases are in Gaines County). Includes additional numbers from El Paso.
- New Mexico: 79 (+1) (83% of cases are from Lea County)
- Oklahoma: 17
- Kansas: 59 (+3) (38.89% of the cases are from Gray County)
HOSPITALIZATIONS: 103
- Texas: 94 – This accounts for 13% of all cases in Texas.
- New Mexico: 7 – This accounts for 9.47% of all cases in New Mexico.
- Kansas: 3 – This accounts for 5.08% of all cases in Kansas.
DEATHS: 3
- Texas: 2 – This is 0.28% of all cases in Texas.
- New Mexico: 1 – This is 1.35% of all cases in New Mexico.
US NATIONAL CASE COUNT: 1,132 (confirmed and suspected)
INTERNATIONAL SPREAD
Mexico: 1,856(+103), 4 fatalities
- Chihuahua, Mexico: 1,740 (+83) cases, 3 fatalities, 4 currently hospitalized.
Canada: 2,791 (+273)
- Ontario, Canada: 1,938 (+143) cases. 158 (+29) hospitalizations
- Alberta, Canada: 679 (+119) cases. 4 currently hospitalized
Order: Odonata Isoptera and Thysanoptera.pptxArshad Shaikh
*Odonata*: Odonata is an order of insects that includes dragonflies and damselflies. Characterized by their large, compound eyes and agile flight, they are predators that feed on other insects, playing a crucial role in maintaining ecological balance.
*Isoptera*: Isoptera is an order of social insects commonly known as termites. These eusocial creatures live in colonies with complex social hierarchies and are known for their ability to decompose wood and other cellulose-based materials, playing a significant role in ecosystem nutrient cycling.
*Thysanoptera*: Thysanoptera, or thrips, are tiny insects with fringed wings. Many species are pests that feed on plant sap, transmitting plant viruses and causing damage to crops and ornamental plants. Despite their small size, they have significant impacts on agriculture and horticulture.
Paper 110A | Shadows and Light: Exploring Expressionism in ‘The Cabinet of Dr...Rajdeep Bavaliya
Dive into the haunting worlds of German Expressionism as we unravel how shadows and light elevate ‘The Cabinet of Dr. Caligari’ and ‘Nosferatu: A Symphony of Horror’ into timeless masterpieces. Discover the psychological power of chiaroscuro, distorted sets, and evocative silhouettes that shaped modern horror. Whether you’re a film buff or a budding cinephile, this journey through post‑WWI trauma and surreal visuals will leave you seeing movies in a whole new light. Hit play, share your favorite shock‑and‑awe moment in the comments, and don’t forget to follow for more deep‑dives into cinema’s most influential movements!
M.A. Sem - 2 | Presentation
Presentation Season - 2
Paper - 110A: History of English Literature – From 1900 to 2000
Submitted Date: April 1, 2025
Paper Name: History of English Literature – From 1900 to 2000
Topic: Shadows and Light: Exploring Expressionism in ‘The Cabinet of Dr. Caligari’ and ‘Nosferatu: A Symphony of Horror’
[Please copy the link and paste it into any web browser to access the content.]
Video Link: https://youtu.be/pWjHqo6clT4
For a more in-depth discussion of this presentation, please visit the full blog post at the following link:
Please visit this blog to explore additional presentations from this season:
Hashtags:
#GermanExpressionism #SilentHorror #Caligari #Nosferatu #Chiaroscuro #VisualStorytelling #FilmHistory #HorrorCinema #CinematicArt #ExpressionistAesthetics
Keyword Tags:
Expressionism, The Cabinet of Dr. Caligari, Nosferatu, silent film horror, film noir origins, German Expressionist cinema, chiaroscuro techniques, cinematic shadows, psychological horror, visual aesthetics
Jack Lutkus is an education champion, community-minded innovator, and cultural enthusiast. A social work graduate student at Aurora University, he also holds a BA from the University of Iowa.
2. Jan 2023
PROGRAM FLOW CONTROLS
(Selection Statements)
Outline
▪ Introduction to flow control
▪ Branching flow controls
✓ One-way selection
✓ Two-way selection
✓ Multiple selections
✓ switch statement
CHAPTER FOUR
3. Jan 2023
Objectives
At the end of this section, you able to
▪ Identify and use selection flow controls
▪ Form and evaluate Boolean expressions
▪ Examine the relational and logical operators
▪ Write a program using selection statements
5. Jan 2023
What is flow control?
▪ It refers to the order in which a program statements (instructions) are
executed (performs actions).
▪ The term reflects the fact that the currently executing statement has
control of the CPU and is handed over (flow) to another statement when
its execution is completed.
6. Jan 2023
Cont’d
The natural flow control of program
▪ Typically, the flow control in a program is
sequential, which is the most common and
straightforward.
▪ However, usually a program execution is not
limited to a sequential
7. Jan 2023
Cont’d
Can the programmer
alter the normal
order of program
execution?
▪ Yes, programmers can control the order of
instruction execution
▪ Accordingly, most programming language
including C++ provides control structures that
serve to specify what has to be done by our
program, when and under which circumstances.
8. Jan 2023
The Basic Program Flow Controls
▪ Generally there are three basic program flow controls
Execution of instructions
sequentially one after
another
allow alternative actions
based upon conditions that
are evaluated at run time
allows to execute a
statement or group of
statements multiple times
9. Jan 2023
Logical/Boolean expressions
What are Logical/Boolean expressions?
▪ Refers to the expressions that are evaluated as true/false
▪ Formed using the logical or/and relational operators
(refer to Operator and expression topic for the details)
▪ Logical/Boolean expressions are a fundamental part of control statements
Example of
a Boolean
expression
10. Jan 2023
Summary
In this section, we briefly discussed;
➢ Program flow control concept
➢ Revision on relational and logical operators
➢ Formation and evaluation of Logical/Boolean expressions
12. Jan 2023
Types of Selection Statements
▪ Selection statements include
✓ One-way selection ----> if statement
✓ Two-way selection statements
➢ if...else statement
➢ Conditional operator
➢ nested if --- else statement
✓ Multiple selection statements
➢ else if…else statement
➢ Switch statement
13. Jan 2023
I) if Statement (single-selection)
▪ Syntax
if (expression) {
statement (s);
}
next statement(s);
14. Jan 2023
Cont’d
When to use it?
▪ When there is a one-time condition check in the program and the
program continues with the normal execution either the condition is
satisfied or not.
Example:
▪ Computing salary bonus for an employee given extra hours worked.
▪ Set the nth bit of a long integer num to 1
15. Jan 2023
Exercise 4.1
Problem description
Write a C++ program to calculate the Net-Pay of an employee as follow after deduction
of pension (7%) and tax. The program should read the gross salary, worked hours, and
income tax rate. If the employee worked hours exceed 40 hrs., the program prompts
the user to enter an over-time bonus rate/hour and find the bonus payment by
multiplying the extra hours worked with the provided bonus rate.
net Salary = (gross Salary – pension – income tax) + Overtime payment
Purpose: To demonstrate the use case of the if statement.
16. Jan 2023
Solution
(Problem Analysis)
Input
- employee gross salary,
- worked-hours,
- income tax rate,
- the bonus rate
Output
- Employee Net salary
Process/Operation
➢ Variable declarations
➢ Initialization: overtime payment to zero
➢ Constant definition: pension
➢ Print input prompt message
➢ Read corresponding input data
➢ Checking if the hours worked > 40 or not
➢ Calculate net salary by computing the following
✓ Pension (gross salary * 7%)
✓ Income tax (gross salary * income tax rate).
✓ Over-time payment (worked hours – 40 * bonus rate), if any
➢ Print output prompt message and the Net salary
17. Jan 2023
Solution
(Design the Program)
1. Variable declaration and initialization
➢ float gross_Salary, taxRate, bonusRate, overTime = 0.0;
➢ int hrsWorked
2. Constant definition
➢ const float penstionRate = 0.07;
3. Reading input data
➢ cout<<“Eneter gross salary, tax rate, hrs worked separated by space: “;
➢ cin>>gross_Salary>>taxRate>>bonusRate
18. Jan 2023
Solution
(Design the Program)
You can compile it
and make one
statement
4. Compute net Salary
➢ if (hrsWorked > 40) ➔ overtime = bonusRate * (hrsworked - 40 )
➢ gross_Salary += Overtime;
➢ float incomeTax = gross_Salary * taxRate;
➢ float penstion = gross_Salary * pensionRate;
➢ netSalary = gross_Salary – incomeTax – pesntion
5. Print result (net Salary)
➢ cout<< “The net Salary of the Employee is: “<<netSalary<<endl;
20. Jan 2023
I) if else Statement (two-selection)
▪ Syntax if (expression){
statement1 / block1
}else{
statement2 / block2;
}
next statement(s);
21. Jan 2023
Cont’d
Another Syntax ----- > without the block { }
➢ Can be used when there is only one statement
➢ Not suggested (it causes dangling Else
Problem)
if (condition)
<statement_true>;
else
<statement_false>;
if (condition)
<statement_true>;
When it can be used?
➢ It can be used when there are two different operations to be performed based on the pre-
defined condition.
22. Jan 2023
III) Conditional/Ternary operator
▪ It is an alternative selection
statement for the if …. else
statement
▪ Syntax
Condition ? Expr 1 : Expr 2;
24. Jan 2023
Exercise 4.2
Problem description
Write a C++ program to check whether a given integer number is (a) even/odd or
(b) positive or negative using the two-way selection statements;
➢ if ... else statement
➢ Conditional operator
Purpose: To demonstrate the use case of the two selection statements
Outcome: You able to identify and differentiate the various selection statements
25. Jan 2023
Solution
LET’S DO TOGETHER
➢ Perform an Analysis of the problem
➢ Design the program on paper
➢ Write the program.
26. Jan 2023
V) if .. else if Statement
Syntax
if (expression1){
statement1 / block1
}
else if (expression2){
statement2 / block2;
}
. . . . .
else {
statement-N / block-N;
}
next statement(s);
This selection statement allows
for conditional execution based
on more than two alternatives
27. Jan 2023
▪ if the condition (Boolean expression) is TRUE
(evaluated to 1), then statement1 or block1
that follows the selection is executed and
then the next statement(s) get executed.
▪ Otherwise block2 of each else if part is
evaluated and the statement2 or block2 of
the selection that returns TRUE is executed
and the execution continues with the next
statement in the program.
▪ If there is no condition evaluated to TRUE,
the else part will be executed.
Description
Cont’d
28. Jan 2023
Exercise 4.3
Problem description
1. Write a program to find the largest number of three numbers using if...else
statement
2. Write a program that reads a valid student mark score and prints the
corresponding GRADE scale as follows. [Hint: solve it using both nested if …. else and
if … else if statements)
3. Make a program that calculates and display the Body Mass Index (BMI) of a
person along with it’s status (normal, under-weight or over-weight.
29. Jan 2023
Cont. . . .
Purpose:
➢ To demonstrate the use case of the multiple selection statements
➢ To differentiate the use case of the nested two-way selection and multiple
selection statements
Outcome:
➢ You able to design and write a program with multiple execution alternatives
and determine the difference between the various selection statements.
30. Jan 2023
Solution
LET’S DO TOGETHER
➢ Perform an Analysis of the problem
➢ Design the program on paper
➢ Write the program.
31. Jan 2023
Summary
In this section, we briefly discussed and demonstrated;
➢ If statement
➢ If …. else statement
➢ If … else if statement
33. Jan 2023
Iv) Nested if … else statement
▪ Sometimes there is a situation
when one condition is based on the
other previous one.
▪ Nested statement refers to using
within another selection statement
▪ Match each else with the last
unmatched if
34. Jan 2023
Cont. . .
Example:
▪ A program used to determine if a given
symbol is a digit or upper case letter or
lower case letter.
35. Jan 2023
Exercise 4.4
Problem description
Write a C++ program that read a student mark score and print a message
“Congratulation!” for a score >= 50 otherwise “Failed, try harder!” using the two-way
selection statements;
➢ if ... else statement
➢ Conditional operator
➢ Nested if … else statement
Purpose: To demonstrate the use case of the two selection statements
Outcome: You able to identify and differentiate the various selection statements
36. Jan 2023
Summary
In this section, we briefly demonstrated;
➢ Nested if else if statement
➢ Solved practical exercise
38. Jan 2023
VI) Switch Statement Syntax
Switch statement is similar to if … else if
combination, it enables you to test several
cases generated by a given expression
40. Jan 2023
Cont. . .
➢ First the switch expression is evaluated once
➢ The value of the expression is compared with the values of each case
➢ If there is a match, the statements following the matched case (associated block )
will be executed until a break statement is reached.
➢ When a break statement is reached, the switch terminates, and the flow of
control jumps to the next line following the switch statement.
➢ A switch statement can have an optional default case (equivalent to else), which
usually appears at the end of the switch.
➢ The default case holds tasks to be executed when none of the cases is true.
How it works
41. Jan 2023
Cont. . .
➢ The expression must be evaluated to literal value (integral or character or Boolean
or enum) and can only be used to compare an expression against constants
➢ Each case is followed by the value to be compared to and a colon.
➢ The expression of each case statement in the block must be unique and cannot be
either a variable or range.
➢ If no break appears, the flow of control will fall through to subsequent cases until a
break is reached.
➢ It is not necessary to include block - braces {} surrounding the statements of the cases
➢ Even if it is usually necessary to include a break statement at the end of each case,
there are situations in which it makes sense to have a case without a break.
Important Note
42. Jan 2023
Exercise 4.5
Problem description
Write a basic calculator program that reads an operator and numbers from the
user and prints the result. [Hint: switch-case statement)
Purpose:
✓ To demonstrate the use case of the
switch-case statements
Outcome:
✓ You able to write a menu-based
program using switch-case statements
Solution [LET’S DO TOGETHER]
➢ Perform an Analysis of the problem
➢ Design the program on paper
➢ Write the program.
44. Jan 2023
Dangling else problem
Output
✓ It displays the “4 is an odd
number” message
Case study
➢ What does it display for x=4?
45. Jan 2023
Cont. . .
Problem
✓ 4 is a positive even numbers
✓ Reason is that else belongs to the most recent if
✓ The indentation says the reverse, else belongs to second (inner) if
Solution:
✓ using brace {}
46. Jan 2023
Short-circuit Evaluation
✓ Short-circuit evaluation refers to the order of Boolean expression evaluation in the
selection statement
✓ During the selection evaluation, the first (leftmost) Boolean sub-expression is
evaluated.
✓ If its value is enough to judge the value of the entire expression, then stop there.
Otherwise, continue evaluation towards the right.
✓ Example: if (count != 0 && scores/count < 60) cout<<"low average";
▪ In this example, if the value of count is zero, then first sub-expression becomes
false and the second one is not evaluated.
▪ In this way, we avoid “division by zero” error (that would cause to stop the
execution of the program)
✓ Alternative method without using short-circuit evaluation is using nested statement
47. Jan 2023
Summary
In this section, we briefly discussed and demonstrated;
➢ Switch statement
➢ Switch statement Vs. If else if statement
➢ Dangling else problem
➢ Short-circuit Evaluation
49. Jan 2023
Reading Resources/Materials
eBooks
▪ Chapter 5 & 6: Diane Zak; An Introduction to Programming with C++ [8th Edition],
2016 Cengage Learning
▪ Chapter 4: Gary J. Bronson; C++ For Engineers and Scientists [3rd edition],
Course Technology, Cengage Learning, 2010
▪ Chapter 2 (section 2.4): Walter Savitch; Problem Solving With C++ [10th edition],
University of California, San Diego, 2018
▪ Chapter 4: P. Deitel , H. Deitel; C++ how to program, [10th, Global Edition] (2017)
50. Jan 2023
Reading Resources/Materials
eBooks – looping statements
▪ Chapter 7 & 8: Diane Zak; An Introduction to Programming with C++ [8th Edition],
2016 Cengage Learning
▪ Chapter 5: Gary J. Bronson; C++ For Engineers and Scientists [3rd edition],
Course Technology, Cengage Learning, 2010
▪ Chapter 2 (section 2.4): Walter Savitch; Problem Solving With C++ [10th edition],
University of California, San Diego, 2018
▪ Chapter 4 & 5: P. Deitel , H. Deitel; C++ how to program, [10th, Global Ed.] (2017)