The document discusses conditional statements and logical expressions in C++. Some key points:
- Conditional statements like if, if-else, and switch allow a program to make decisions based on logical expressions that evaluate to true or false.
- Logical expressions use relational operators like <, >, == combined with variables, constants, and arithmetic expressions. Complex logical expressions can combine simple expressions using &&, ||, and ! operators.
- The if statement executes a block of code if the logical expression is true, and skips it if false. The if-else statement executes one of two blocks of code depending on if the expression is true or false.
- Flowcharts can visualize the flow of control
This document provides an overview of arithmetic, logical expressions, and conditional statements in C++. It discusses arithmetic operators for calculations, logical expressions using relational operators, and Boolean logic. Conditional constructs like if, if-else, and if-else-if statements are explained, along with examples of using them to make decisions based on expression evaluations. Operator precedence is also covered. The document aims to help readers learn about expressions and selection structures in C++.
This document discusses different types of operators used in programming languages. It describes arithmetic operators for mathematical operations, relational operators for comparisons, logical operators for logical expressions, and increment/decrement operators. Examples are provided for each type of operator to demonstrate their usage and effects. The key information covered includes the different operator symbols and their uses in expressions and assignments.
C operators allow building expressions and making decisions in code. The document discusses several categories of operators in C including arithmetic, assignment, relational, logical, bitwise, and others. It provides examples of using each type of operator and explains precedence rules and associativity. Key points covered include: how each operator works; common uses like conditional checks, assignments, and bit manipulation; and important considerations like order of operations and integer division behavior.
C operators allow building expressions and performing operations in C programs. The main types of operators in C are arithmetic, assignment, logical/relational, bitwise, and others like sizeof. Arithmetic operators perform math operations like addition and subtraction. Assignment operators assign values. Logical operators allow conditional logic. Relational operators compare values. Bitwise operators work at the bit level. Precedence rules determine the order calculations are performed. Operators are used with operands and follow consistent rules in C.
This document provides an overview of basic C# programming concepts. It covers topics such as program structure, data types, variables, operators, decision making statements, loops, classes and methods. Specifically, it discusses if/else statements, switch cases, ternary operators, for, while and do-while loops. It also provides examples of basic C# programs and explanations of concepts like classes, methods, constructors and namespaces.
Control structures in C++ Programming LanguageAhmad Idrees
This document discusses various control structures in C++ for selection and branching, including if/else statements, switch statements, logical operators, and the assert function. If/else statements allow for two-way selection based on a logical expression being true or false. Switch statements allow for multi-way branching depending on the value of an expression. Logical operators like && and || are used to combine logical expressions. The assert function halts a program if a specified condition is false, which is useful for debugging.
This document provides an overview of arithmetic, logical expressions, and conditional statements in C++. It discusses arithmetic operators for calculations, logical expressions using relational operators, and Boolean logic. Conditional constructs like if, if-else, and if-else-if statements are explained, along with examples of using them to make decisions based on expression evaluations. Operator precedence is also covered. The document aims to help readers learn about expressions and selection structures in C++.
This document discusses different types of operators used in programming languages. It describes arithmetic operators for mathematical operations, relational operators for comparisons, logical operators for logical expressions, and increment/decrement operators. Examples are provided for each type of operator to demonstrate their usage and effects. The key information covered includes the different operator symbols and their uses in expressions and assignments.
C operators allow building expressions and making decisions in code. The document discusses several categories of operators in C including arithmetic, assignment, relational, logical, bitwise, and others. It provides examples of using each type of operator and explains precedence rules and associativity. Key points covered include: how each operator works; common uses like conditional checks, assignments, and bit manipulation; and important considerations like order of operations and integer division behavior.
C operators allow building expressions and performing operations in C programs. The main types of operators in C are arithmetic, assignment, logical/relational, bitwise, and others like sizeof. Arithmetic operators perform math operations like addition and subtraction. Assignment operators assign values. Logical operators allow conditional logic. Relational operators compare values. Bitwise operators work at the bit level. Precedence rules determine the order calculations are performed. Operators are used with operands and follow consistent rules in C.
This document provides an overview of basic C# programming concepts. It covers topics such as program structure, data types, variables, operators, decision making statements, loops, classes and methods. Specifically, it discusses if/else statements, switch cases, ternary operators, for, while and do-while loops. It also provides examples of basic C# programs and explanations of concepts like classes, methods, constructors and namespaces.
Control structures in C++ Programming LanguageAhmad Idrees
This document discusses various control structures in C++ for selection and branching, including if/else statements, switch statements, logical operators, and the assert function. If/else statements allow for two-way selection based on a logical expression being true or false. Switch statements allow for multi-way branching depending on the value of an expression. Logical operators like && and || are used to combine logical expressions. The assert function halts a program if a specified condition is false, which is useful for debugging.
The document discusses various operators in C# programming including unary, binary, and ternary operators. It explains operators such as increment, decrement, bitwise inversion, logical, assignment, comparison, arithmetic, and more. Examples are provided to demonstrate how each operator works. The document also covers operator precedence and escape sequences.
The document discusses various operators in C# programming including unary, binary, and ternary operators. It explains operators such as increment, comparison, bitwise, logical, assignment, and escape sequence operators. It also covers Math class methods for common mathematical operations.
This document discusses flow of control in C programming. It covers selection structures like if/else statements that allow a program to make decisions based on boolean expressions. It also covers repetition structures like loops. The key control structures are sequences, selection, and repetition. Selection structures include if/else and switch statements. If/else allows two alternative paths, while switch supports multiple comparisons. Logical and relational operators are used to construct boolean expressions that if/else and switch evaluate. Proper indentation and braces are important for nested conditional statements.
Operator & control statements in C are used to perform operations and control program flow. Arithmetic operators (+, -, *, /, %) are used for mathematical calculations on integers and floating-point numbers. Relational operators (<, <=, >, >=, ==, !=) compare two operands. Logical operators (&&, ||, !) combine conditions. Control statements like if-else, switch, while, for, break, continue and goto alter program execution based on conditions.
This chapter discusses:
1. Program flow control and statements like conditionals and loops that alter normal linear execution.
2. Conditional statements like if/else that allow choosing which statement executes based on a boolean condition.
3. Repetition statements like while and for loops that repeatedly execute a statement as long as/for as long as a condition is true.
Chapter 3 introduces several Java program statements:
- Conditional statements like if-else allow programs to make decisions based on boolean expressions.
- Loops like while and for allow code to repeat based on conditions.
- Logical operators like && and || combine boolean expressions.
- Proper program design is important, involving requirements, design, implementation, and testing stages.
This document provides an overview of operators in C++ programming. It discusses assignment, arithmetic, relational, logical, and bitwise operators. It also covers increment/decrement, conditional, type casting, and sizeof operators. Examples are given for each operator. The document concludes with exercises asking the reader to write C++ programs using various operators.
18 css101j pps unit 2
Relational and logical Operators - Condition Operators, Operator Precedence - Expressions with pre / post increment operator - Expression with conditional and assignment operators - If statement in expression - L value and R value in expression -
Control Statements – if and else - else if and nested if, switch case - Iterations, Conditional and Unconditional branching
For loop - while loop - do while, goto, break, continue
Array Basic and Types - Array Initialization and Declaration - Initialization: one Dimensional Array - Accessing, Indexing one Dimensional Array Operations - One Dimensional Array operations - Array Programs – 1D
This document provides a review of constants, variables, expressions, logical expressions, conditional statements, and debugging techniques in C++. It defines constants and variables, discusses data types and expressions, introduces Boolean logic and truth tables, covers conditional constructs like if-else and switch statements, and explains debugging using breakpoints and program tracing.
The document discusses various control flow statements in C# including conditional statements like if-else and switch statements. It explains the syntax and usage of if-else, else if, logical and relational operators, switch statement, nested if statements, short-circuit evaluation, and the dangling else problem. It also introduces repetition statements like while to repeatedly execute a block of code as long as a condition is true.
Java defines several categories of operators: arithmetic, bitwise, relational, logical, and additional special operators. The increment and decrement operators ++ and -- increase or decrease a variable by 1. Relational operators determine the relationship between two operands and return a boolean. Control statements like if-else and switch allow a program to select or loop execution paths. Parentheses can be used to alter operator precedence or clarify complex expressions.
Esoft Metro Campus - Diploma in Web Engineering - (Module VI) Fundamentals of PHP
(Template - Virtusa Corporate)
Contents:
Introduction to PHP
What PHP Can Do?
PHP Environment Setup
What a PHP File is?
PHP Syntax
Comments in PHP
echo and print Statements
PHP Variables
PHP Data Types
Changing Type by settype()
Changing Type by Casting
PHP Constants
Arithmetic Operators
String Operators
Assignment Operators
Comparison Operators
Logical Operators
Operators Precedence
If Statement
If… Else Statement
If… Else if… Else Statement
Switch Statement
The ? Operator
While Loop
Do While Loop
For Loop
break Statement
continue Statement
Functions
User Defined Functions
Functions - Returning values
Default Argument Value
Arguments as Reference
Existence of Functions
Variable Local and Global Scope
The global Keyword
GLOBALS Array
Superglobals
Static Variables
The document discusses various elements of programming in C++ including literals, variables, types, expressions, statements, control flow constructs, functions, and libraries. It then focuses on different types of operators in C++ like arithmetic, relational, logical, and bitwise operators. It explains operator precedence and associativity rules for evaluating expressions. Special assignment operators, increment/decrement operators, and their differences are also covered.
The document discusses various C# operators including unary operators, binary operators, and ternary operators. It provides examples and explanations of increment/decrement, bitwise, logical, comparison, and assignment operators. It also covers operator precedence and uses the Math class for common mathematical functions.
This document summarizes Chapter 5 of the book "C Programming: A Modern Approach" regarding selection statements in C. It discusses logical expressions using relational and equality operators that return true or false values. It then covers the if statement for conditional execution, including else clauses, nested if statements, and conditional expressions. Finally, it discusses the switch statement as an alternative to nested if statements for selecting among multiple possible cases.
chap 2 : Operators and Assignments (scjp/ocjp)It Academy
The document provides an overview of operators in Java, including:
- Unary operators like increment, decrement, negation, boolean complement and cast
- Arithmetic operators like multiplication, division, modulo and their behavior during errors
- Relational operators like comparison and instanceof
- Equality operators like == and !=
- Logical operators like &&, || and conditional operator ?: and their short-circuit behavior
- Bitwise and boolean operators like &, |, ^, AND, OR
- Assignment operators like += and their evaluation order from right to left
This document discusses operators and expressions in C++. It begins by defining operators as symbols that represent operations and operands as the objects involved in those operations. It then covers various types of operators in C++ like arithmetic, relational, logical, and conditional operators. It provides examples of using each operator and notes order of precedence. The document also discusses expressions, noting they are combinations of operators, constants, and variables. It provides examples of integer, real, relational, and logical expressions. Finally, it discusses mathematical functions available in the C++ standard library header file math.h that can be used in arithmetic expressions.
This document provides an overview of the C programming language. It discusses the brief history of C, including its predecessors like CPL, BCPL, B, and ALGOL 68. It describes the different data types in C including literals, identifiers, keywords, expressions, and variables. Arithmetic, logical, and relational expressions are explained. Examples are provided to demonstrate how to convert mathematical formulas and English conditions to C expressions.
The document discusses comparison, logical, and bitwise operators in Python. It begins by defining comparison operators like >, <, ==, which return True or False based on relations between operands. Logical operators like and, or, not allow combining conditions and return True/False. Bitwise operators like &, |, ^ manipulate single bits and perform operations like conjunction, disjunction, exclusive or on a bit level. The document provides truth tables and examples to explain the usage and precedence of these different operator types in Python.
The document discusses various C operators and differences between some key concepts in programming. It covers arithmetic, conditional, increment/decrement operators and their usage. Special operators like sizeof and comma are described. Key differences explained include data vs information, compilers vs interpreters, system vs application software, algorithms vs flowcharts, arrays vs structures, and call by value vs call by reference. Examples are provided to illustrate the usage and differences of these concepts.
This document contains a class schedule for various degree programs at PMAS - University Institute of Information Technology. It lists the courses, instructors, class timings and locations for BSIT, BSSE, BSCS, MSCS/PhD programs on different weekdays from Monday to Thursday. Some common courses across programs include Object Oriented Programming, Software Engineering, Database Systems, Computer Networks, Technical & Business Writing etc. The schedule also mentions extra classes on System Programming and Psychology.
Women empowerment involves challenging gender-based discrimination and gaining power and influence. It is needed due to issues like educational problems, societal barriers, low confidence, lack of unity, and traditional barriers facing women. Women suffer much higher rates of harassment, discrimination, and exploitation than men. Women empowerment can be achieved through self-help groups, government schemes, microfinance, self-employment, and helping women become business leaders and gain education, food, and victory over injustice. The examples of empowered women include Mother Teresa, Aishwarya Rai, Kiran Bedi, and Lata Mangeshkar. Overall, women empowerment is a major issue in India that requires awareness, policy changes,
More Related Content
Similar to Ref Lec 4- Conditional Statement (1).pptx
The document discusses various operators in C# programming including unary, binary, and ternary operators. It explains operators such as increment, decrement, bitwise inversion, logical, assignment, comparison, arithmetic, and more. Examples are provided to demonstrate how each operator works. The document also covers operator precedence and escape sequences.
The document discusses various operators in C# programming including unary, binary, and ternary operators. It explains operators such as increment, comparison, bitwise, logical, assignment, and escape sequence operators. It also covers Math class methods for common mathematical operations.
This document discusses flow of control in C programming. It covers selection structures like if/else statements that allow a program to make decisions based on boolean expressions. It also covers repetition structures like loops. The key control structures are sequences, selection, and repetition. Selection structures include if/else and switch statements. If/else allows two alternative paths, while switch supports multiple comparisons. Logical and relational operators are used to construct boolean expressions that if/else and switch evaluate. Proper indentation and braces are important for nested conditional statements.
Operator & control statements in C are used to perform operations and control program flow. Arithmetic operators (+, -, *, /, %) are used for mathematical calculations on integers and floating-point numbers. Relational operators (<, <=, >, >=, ==, !=) compare two operands. Logical operators (&&, ||, !) combine conditions. Control statements like if-else, switch, while, for, break, continue and goto alter program execution based on conditions.
This chapter discusses:
1. Program flow control and statements like conditionals and loops that alter normal linear execution.
2. Conditional statements like if/else that allow choosing which statement executes based on a boolean condition.
3. Repetition statements like while and for loops that repeatedly execute a statement as long as/for as long as a condition is true.
Chapter 3 introduces several Java program statements:
- Conditional statements like if-else allow programs to make decisions based on boolean expressions.
- Loops like while and for allow code to repeat based on conditions.
- Logical operators like && and || combine boolean expressions.
- Proper program design is important, involving requirements, design, implementation, and testing stages.
This document provides an overview of operators in C++ programming. It discusses assignment, arithmetic, relational, logical, and bitwise operators. It also covers increment/decrement, conditional, type casting, and sizeof operators. Examples are given for each operator. The document concludes with exercises asking the reader to write C++ programs using various operators.
18 css101j pps unit 2
Relational and logical Operators - Condition Operators, Operator Precedence - Expressions with pre / post increment operator - Expression with conditional and assignment operators - If statement in expression - L value and R value in expression -
Control Statements – if and else - else if and nested if, switch case - Iterations, Conditional and Unconditional branching
For loop - while loop - do while, goto, break, continue
Array Basic and Types - Array Initialization and Declaration - Initialization: one Dimensional Array - Accessing, Indexing one Dimensional Array Operations - One Dimensional Array operations - Array Programs – 1D
This document provides a review of constants, variables, expressions, logical expressions, conditional statements, and debugging techniques in C++. It defines constants and variables, discusses data types and expressions, introduces Boolean logic and truth tables, covers conditional constructs like if-else and switch statements, and explains debugging using breakpoints and program tracing.
The document discusses various control flow statements in C# including conditional statements like if-else and switch statements. It explains the syntax and usage of if-else, else if, logical and relational operators, switch statement, nested if statements, short-circuit evaluation, and the dangling else problem. It also introduces repetition statements like while to repeatedly execute a block of code as long as a condition is true.
Java defines several categories of operators: arithmetic, bitwise, relational, logical, and additional special operators. The increment and decrement operators ++ and -- increase or decrease a variable by 1. Relational operators determine the relationship between two operands and return a boolean. Control statements like if-else and switch allow a program to select or loop execution paths. Parentheses can be used to alter operator precedence or clarify complex expressions.
Esoft Metro Campus - Diploma in Web Engineering - (Module VI) Fundamentals of PHP
(Template - Virtusa Corporate)
Contents:
Introduction to PHP
What PHP Can Do?
PHP Environment Setup
What a PHP File is?
PHP Syntax
Comments in PHP
echo and print Statements
PHP Variables
PHP Data Types
Changing Type by settype()
Changing Type by Casting
PHP Constants
Arithmetic Operators
String Operators
Assignment Operators
Comparison Operators
Logical Operators
Operators Precedence
If Statement
If… Else Statement
If… Else if… Else Statement
Switch Statement
The ? Operator
While Loop
Do While Loop
For Loop
break Statement
continue Statement
Functions
User Defined Functions
Functions - Returning values
Default Argument Value
Arguments as Reference
Existence of Functions
Variable Local and Global Scope
The global Keyword
GLOBALS Array
Superglobals
Static Variables
The document discusses various elements of programming in C++ including literals, variables, types, expressions, statements, control flow constructs, functions, and libraries. It then focuses on different types of operators in C++ like arithmetic, relational, logical, and bitwise operators. It explains operator precedence and associativity rules for evaluating expressions. Special assignment operators, increment/decrement operators, and their differences are also covered.
The document discusses various C# operators including unary operators, binary operators, and ternary operators. It provides examples and explanations of increment/decrement, bitwise, logical, comparison, and assignment operators. It also covers operator precedence and uses the Math class for common mathematical functions.
This document summarizes Chapter 5 of the book "C Programming: A Modern Approach" regarding selection statements in C. It discusses logical expressions using relational and equality operators that return true or false values. It then covers the if statement for conditional execution, including else clauses, nested if statements, and conditional expressions. Finally, it discusses the switch statement as an alternative to nested if statements for selecting among multiple possible cases.
chap 2 : Operators and Assignments (scjp/ocjp)It Academy
The document provides an overview of operators in Java, including:
- Unary operators like increment, decrement, negation, boolean complement and cast
- Arithmetic operators like multiplication, division, modulo and their behavior during errors
- Relational operators like comparison and instanceof
- Equality operators like == and !=
- Logical operators like &&, || and conditional operator ?: and their short-circuit behavior
- Bitwise and boolean operators like &, |, ^, AND, OR
- Assignment operators like += and their evaluation order from right to left
This document discusses operators and expressions in C++. It begins by defining operators as symbols that represent operations and operands as the objects involved in those operations. It then covers various types of operators in C++ like arithmetic, relational, logical, and conditional operators. It provides examples of using each operator and notes order of precedence. The document also discusses expressions, noting they are combinations of operators, constants, and variables. It provides examples of integer, real, relational, and logical expressions. Finally, it discusses mathematical functions available in the C++ standard library header file math.h that can be used in arithmetic expressions.
This document provides an overview of the C programming language. It discusses the brief history of C, including its predecessors like CPL, BCPL, B, and ALGOL 68. It describes the different data types in C including literals, identifiers, keywords, expressions, and variables. Arithmetic, logical, and relational expressions are explained. Examples are provided to demonstrate how to convert mathematical formulas and English conditions to C expressions.
The document discusses comparison, logical, and bitwise operators in Python. It begins by defining comparison operators like >, <, ==, which return True or False based on relations between operands. Logical operators like and, or, not allow combining conditions and return True/False. Bitwise operators like &, |, ^ manipulate single bits and perform operations like conjunction, disjunction, exclusive or on a bit level. The document provides truth tables and examples to explain the usage and precedence of these different operator types in Python.
The document discusses various C operators and differences between some key concepts in programming. It covers arithmetic, conditional, increment/decrement operators and their usage. Special operators like sizeof and comma are described. Key differences explained include data vs information, compilers vs interpreters, system vs application software, algorithms vs flowcharts, arrays vs structures, and call by value vs call by reference. Examples are provided to illustrate the usage and differences of these concepts.
Similar to Ref Lec 4- Conditional Statement (1).pptx (20)
This document contains a class schedule for various degree programs at PMAS - University Institute of Information Technology. It lists the courses, instructors, class timings and locations for BSIT, BSSE, BSCS, MSCS/PhD programs on different weekdays from Monday to Thursday. Some common courses across programs include Object Oriented Programming, Software Engineering, Database Systems, Computer Networks, Technical & Business Writing etc. The schedule also mentions extra classes on System Programming and Psychology.
Women empowerment involves challenging gender-based discrimination and gaining power and influence. It is needed due to issues like educational problems, societal barriers, low confidence, lack of unity, and traditional barriers facing women. Women suffer much higher rates of harassment, discrimination, and exploitation than men. Women empowerment can be achieved through self-help groups, government schemes, microfinance, self-employment, and helping women become business leaders and gain education, food, and victory over injustice. The examples of empowered women include Mother Teresa, Aishwarya Rai, Kiran Bedi, and Lata Mangeshkar. Overall, women empowerment is a major issue in India that requires awareness, policy changes,
This document summarizes research on the relationship between religion, fertility rates, and population growth. It finds that in Muslim-majority countries, higher national religiosity is associated with lower fertility rates, unlike in other developing nations. Religious groups within Muslim countries tend to have higher fertility. However, the effect is modest, and religious population growth is a long-term process unlike in Israel. Younger, more educated Muslims are less religious, though the effect of education on Islamism is complex. Urbanization may increase Islamic beliefs. Overall, Muslim societies are expected to follow a distinct trajectory of modernization rather than secularization. Future research on religious population projections is proposed.
This document discusses self-confidence and provides tips to build it. It defines self-confidence as having knowledge in your abilities and being able to perform well. There are three types of self-confidence: low, optimal, and over. Low self-confidence means fearing failure while optimal means inspiring others. Steps to build self-confidence include self-acceptance, believing in yourself, focusing on strengths, and spending time with confident people. Famous figures like Abdul Kalam and Einstein achieved success despite initial doubts, showing the power of self-confidence.
Self-confidence is a feeling of trust in one's own abilities and judgment. It is a key to unlocking unlimited potential. There are three types of self-confidence: low self-confidence which is governed by what others think; optimal self-confidence which allows one to make decisions with absolute confidence; and over-confidence which overestimates one's abilities. Developing self-confidence provides advantages like greater self-worth, enjoyment in life, freedom from self-doubt and anxiety, more motivation and success. Ways to develop self-confidence include identifying and changing negative thoughts, taking risks, eliminating reminders of negativity, identifying talents, and accepting compliments.
This document provides information about supporting transgender resilience. It discusses topics like visibility, liberation, discrimination, violence faced by the transgender community, and the importance of resilience and healing. The goal is to educate about transgender issues and empower transgender people to tell their stories.
This presentation was provided by Rebecca Benner, Ph.D., of the American Society of Anesthesiologists, for the second session of NISO's 2024 Training Series "DEIA in the Scholarly Landscape." Session Two: 'Expanding Pathways to Publishing Careers,' was held June 13, 2024.
Walmart Business+ and Spark Good for Nonprofits.pdfTechSoup
"Learn about all the ways Walmart supports nonprofit organizations.
You will hear from Liz Willett, the Head of Nonprofits, and hear about what Walmart is doing to help nonprofits, including Walmart Business and Spark Good. Walmart Business+ is a new offer for nonprofits that offers discounts and also streamlines nonprofits order and expense tracking, saving time and money.
The webinar may also give some examples on how nonprofits can best leverage Walmart Business+.
The event will cover the following::
Walmart Business + (https://business.walmart.com/plus) is a new shopping experience for nonprofits, schools, and local business customers that connects an exclusive online shopping experience to stores. Benefits include free delivery and shipping, a 'Spend Analytics” feature, special discounts, deals and tax-exempt shopping.
Special TechSoup offer for a free 180 days membership, and up to $150 in discounts on eligible orders.
Spark Good (walmart.com/sparkgood) is a charitable platform that enables nonprofits to receive donations directly from customers and associates.
Answers about how you can do more with Walmart!"
Philippine Edukasyong Pantahanan at Pangkabuhayan (EPP) CurriculumMJDuyan
(𝐓𝐋𝐄 𝟏𝟎𝟎) (𝐋𝐞𝐬𝐬𝐨𝐧 𝟏)-𝐏𝐫𝐞𝐥𝐢𝐦𝐬
𝐃𝐢𝐬𝐜𝐮𝐬𝐬 𝐭𝐡𝐞 𝐄𝐏𝐏 𝐂𝐮𝐫𝐫𝐢𝐜𝐮𝐥𝐮𝐦 𝐢𝐧 𝐭𝐡𝐞 𝐏𝐡𝐢𝐥𝐢𝐩𝐩𝐢𝐧𝐞𝐬:
- Understand the goals and objectives of the Edukasyong Pantahanan at Pangkabuhayan (EPP) curriculum, recognizing its importance in fostering practical life skills and values among students. Students will also be able to identify the key components and subjects covered, such as agriculture, home economics, industrial arts, and information and communication technology.
𝐄𝐱𝐩𝐥𝐚𝐢𝐧 𝐭𝐡𝐞 𝐍𝐚𝐭𝐮𝐫𝐞 𝐚𝐧𝐝 𝐒𝐜𝐨𝐩𝐞 𝐨𝐟 𝐚𝐧 𝐄𝐧𝐭𝐫𝐞𝐩𝐫𝐞𝐧𝐞𝐮𝐫:
-Define entrepreneurship, distinguishing it from general business activities by emphasizing its focus on innovation, risk-taking, and value creation. Students will describe the characteristics and traits of successful entrepreneurs, including their roles and responsibilities, and discuss the broader economic and social impacts of entrepreneurial activities on both local and global scales.
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...PECB
Denis is a dynamic and results-driven Chief Information Officer (CIO) with a distinguished career spanning information systems analysis and technical project management. With a proven track record of spearheading the design and delivery of cutting-edge Information Management solutions, he has consistently elevated business operations, streamlined reporting functions, and maximized process efficiency.
Certified as an ISO/IEC 27001: Information Security Management Systems (ISMS) Lead Implementer, Data Protection Officer, and Cyber Risks Analyst, Denis brings a heightened focus on data security, privacy, and cyber resilience to every endeavor.
His expertise extends across a diverse spectrum of reporting, database, and web development applications, underpinned by an exceptional grasp of data storage and virtualization technologies. His proficiency in application testing, database administration, and data cleansing ensures seamless execution of complex projects.
What sets Denis apart is his comprehensive understanding of Business and Systems Analysis technologies, honed through involvement in all phases of the Software Development Lifecycle (SDLC). From meticulous requirements gathering to precise analysis, innovative design, rigorous development, thorough testing, and successful implementation, he has consistently delivered exceptional results.
Throughout his career, he has taken on multifaceted roles, from leading technical project management teams to owning solutions that drive operational excellence. His conscientious and proactive approach is unwavering, whether he is working independently or collaboratively within a team. His ability to connect with colleagues on a personal level underscores his commitment to fostering a harmonious and productive workplace environment.
Date: May 29, 2024
Tags: Information Security, ISO/IEC 27001, ISO/IEC 42001, Artificial Intelligence, GDPR
-------------------------------------------------------------------------------
Find out more about ISO training and certification services
Training: ISO/IEC 27001 Information Security Management System - EN | PECB
ISO/IEC 42001 Artificial Intelligence Management System - EN | PECB
General Data Protection Regulation (GDPR) - Training Courses - EN | PECB
Webinars: https://pecb.com/webinars
Article: https://pecb.com/article
-------------------------------------------------------------------------------
For more information about PECB:
Website: https://pecb.com/
LinkedIn: https://www.linkedin.com/company/pecb/
Facebook: https://www.facebook.com/PECBInternational/
Slideshare: http://www.slideshare.net/PECBCERTIFICATION
LAND USE LAND COVER AND NDVI OF MIRZAPUR DISTRICT, UPRAHUL
This Dissertation explores the particular circumstances of Mirzapur, a region located in the
core of India. Mirzapur, with its varied terrains and abundant biodiversity, offers an optimal
environment for investigating the changes in vegetation cover dynamics. Our study utilizes
advanced technologies such as GIS (Geographic Information Systems) and Remote sensing to
analyze the transformations that have taken place over the course of a decade.
The complex relationship between human activities and the environment has been the focus
of extensive research and worry. As the global community grapples with swift urbanization,
population expansion, and economic progress, the effects on natural ecosystems are becoming
more evident. A crucial element of this impact is the alteration of vegetation cover, which plays a
significant role in maintaining the ecological equilibrium of our planet.Land serves as the foundation for all human activities and provides the necessary materials for
these activities. As the most crucial natural resource, its utilization by humans results in different
'Land uses,' which are determined by both human activities and the physical characteristics of the
land.
The utilization of land is impacted by human needs and environmental factors. In countries
like India, rapid population growth and the emphasis on extensive resource exploitation can lead
to significant land degradation, adversely affecting the region's land cover.
Therefore, human intervention has significantly influenced land use patterns over many
centuries, evolving its structure over time and space. In the present era, these changes have
accelerated due to factors such as agriculture and urbanization. Information regarding land use and
cover is essential for various planning and management tasks related to the Earth's surface,
providing crucial environmental data for scientific, resource management, policy purposes, and
diverse human activities.
Accurate understanding of land use and cover is imperative for the development planning
of any area. Consequently, a wide range of professionals, including earth system scientists, land
and water managers, and urban planners, are interested in obtaining data on land use and cover
changes, conversion trends, and other related patterns. The spatial dimensions of land use and
cover support policymakers and scientists in making well-informed decisions, as alterations in
these patterns indicate shifts in economic and social conditions. Monitoring such changes with the
help of Advanced technologies like Remote Sensing and Geographic Information Systems is
crucial for coordinated efforts across different administrative levels. Advanced technologies like
Remote Sensing and Geographic Information Systems
9
Changes in vegetation cover refer to variations in the distribution, composition, and overall
structure of plant communities across different temporal and spatial scales. These changes can
occur natural.
This presentation was provided by Racquel Jemison, Ph.D., Christina MacLaughlin, Ph.D., and Paulomi Majumder. Ph.D., all of the American Chemical Society, for the second session of NISO's 2024 Training Series "DEIA in the Scholarly Landscape." Session Two: 'Expanding Pathways to Publishing Careers,' was held June 13, 2024.
How to Setup Warehouse & Location in Odoo 17 InventoryCeline George
In this slide, we'll explore how to set up warehouses and locations in Odoo 17 Inventory. This will help us manage our stock effectively, track inventory levels, and streamline warehouse operations.
2. 2
INTRODUCTION
Before writing a program
Have a thorough understanding of problem
Carefully plan your approach for solving it
While writing a program
Know what “building blocks” are available
Use good programming principles
3. 3
ALGORITHMS
Computing problems
Solved by executing a series of actions in a specific order
Algorithm is a procedure determining
Actions to be executed
Order to be executed
Example: recipe
Program control
Specifies the order in which statements are executed
4. 4
PSEUDOCODE
Pseudocode
Artificial, informal language used to develop algorithms
Similar to everyday English
Not executed on computers
Used to think out program before coding
Easy to convert into C++ program
Only executable statements
No need to declare variables
5. 5
CONTROL STRUCTURES
Flowchart
Graphical representation of an algorithm
Special-purpose symbols connected by arrows (flowlines)
Rectangle symbol (action symbol)
Any type of action
Oval symbol
Beginning or end of a program, or a section of code
(circles)
Single-entry/single-exit control structures
Connect exit point of one to entry point of the next
Control structure stacking
8. 8
CONTROL STRUCTURES
Sequential execution
Statements executed in order
Transfer of control
Next statement executed not next one in sequence
3 control structures (Bohm and Jacopini)
Sequence structure
Programs executed sequentially by default
Selection structures
if, if/else, switch
Repetition structures
while, do/while, for
9. FLOW OF CONTROL
Unless specified otherwise, the order of statement execution
through a function is linear: one statement after another in
sequence
Some programming statements allow us to:
decide whether or not to execute a particular statement
execute a statement over and over, repetitively
These decisions are based on boolean expressions (or
conditions) that evaluate to true or false
The order of statement execution is called the flow of control
10. OVERVIEW
Many times we want programs to make decisions
What drink should we dispense from the vending machine?
Should we let the user withdraw money from this account?
We make this choice by looking at values of variables
When variables meet one condition we do one thing
When variables do not meet condition we do something else
To make decisions in a program we need conditional
statements that let us take different paths through code
10
11. OVERVIEW
A conditional statement lets us choose which statement
will be executed next
Therefore they are sometimes called selection
statements
Conditional statements give us the power to make basic
decisions
12. OVERVIEW
In C++ there are three types of conditional statements:
The if statement
The if-else statement
The switch statement
Lesson objectives:
Learn how logical expressions are written
Learn the syntax and semantics of conditional statements
Study example programs showing their use
Complete lab tasks on conditional statements
Complete programming assignments using conditional
statements
12
14. LOGICAL
EXPRESSIONS
All conditional statements in C++ make use of logical
expressions that are true/false statements about data
Simple logical expressions are of the form:
(data operator data)
Data terms in logical expressions can be variables,
constants or arithmetic expressions
C++ evaluates logical expressions from left to right to see
if they are true/false
14
15. LOGICAL
EXPRESSIONS
The C++ relational operators are:
< less than
> greater than
<= less than or equal
>= greater than or equal
== equal to
!= not equal to
15
16. LOGICAL
EXPRESSIONS
Some examples:
(17 < 42) is true
(42 > 17) is true
(17 == 42) is false
(42 != 17) is true
((17 + 10) > (42 – 2)) is false
((17 * 3) <= (17 + 17 + 17) is true
16
17. LOGICAL
EXPRESSIONS
When integer variables a = 17 and b = 42
(a < b) is true
(a >= b) is false
(a == 17) is true
(a != b) is true
((a + 17) == b) is false
((42 – a) < b) is true
17
18. LOGICAL
EXPRESSIONS
Warning: Do not use a single = for checking equality
This will attempt to do assignment instead
The logical expression will not check for equality
Warning: Do not use =<, =>, =! to compare data values
These are invalid operators
You will get a compiler error
18
19. COMPLEX LOGICAL
EXPRESSIONS
Simple logical expressions have limited power
To solve this problem, we can combine simple logical
expressions to get complex logical expressions
This is useful for more realistic data comparison tasks
The basic syntax is: (expression operator expression)
Expression can be a simple or complex logical expression
The C++ logical operators are:
&& and
|| or
! not
19
20. COMPLEX LOGICAL
EXPRESSIONS
Truth tables are often be used to enumerate all possible
values of a complex logical expression
We make columns for all logical expressions
Each row illustrates one set of input values
The number of rows is always a power of 2
20
A B A && B A || B
TRUE TRUE TRUE TRUE
TRUE FALSE FALSE TRUE
FALSE TRUE FALSE TRUE
FALSE FALSE FALSE FALSE
21. COMPLEX LOGICAL
EXPRESSIONS
C++ evaluates complex logical expressions from left to right
(exp1 && exp2) will be true if both exp are true
(exp1 && exp2 && exp3) will be true if all exp are true
(exp1 || exp2 || exp3) will be true if any exp is true
C++ has a feature called “conditional evaluation” that will
stop the evaluation early in some cases
(exp1 && exp2) will be false if exp1 is false
(exp1 || exp2) will be true if exp1 is true
In both cases, we do not need to evaluate exp2
21
22. COMPLEX LOGICAL
EXPRESSIONS
Complex logical expressions
((17 < 42) && (42 < 17)) is false, because second half is false
((17 <= 42) || (42 <= 17)) is true, because first half is true
When float variables x = 3.14 and y = 7.89
((x < 4) && (y < 8)) is true, because both halves are true
((x > 3) && (y > 8)) is false, because second half is false
((x < 4) || (y > 8)) is true, because first half is true
((x < 3) || (y < 8)) is true, because second half is true
((x > 4) || (y > 8)) is false, because both halves are false
22
23. THE NOT OPERATOR
The not operator ‘!’ in in C++ reverses the value of any
logical expression
Logically “not true” is same as “false”
Logically “not false” is same as “true”
The C++ syntax for the not operator is: ! expression
This is a “unary” operator since there is just one
expression to the right of the not operator
23
24. THE NOT OPERATOR
Examples with integer variables a = 7 and b = 3
(a > b) is true ! (a > b) is false
(a <= b) is false ! (a <= b) is true
(a == b) is false ! (a == b) is true
(a != b) is true ! (a != b) is false
24
25. THE NOT OPERATOR
We can often “move the not operation inside” a simple
logical expression
To do this simplification, we need to remove the ! operator
and reverse the logic of the relational operator
!(a < b) same as (a >= b)
!(a <= b) same as (a > b)
!(a > b) same as (a <= b)
!(a >= b) same as (a < b)
!(a == b) same as (a != b)
!(a != b) same as (a == b)
25
26. THE NOT OPERATOR
We can extend truth tables to illustrate the not operator
Add new columns showing !A and !B and their use in
complex logical expressions
26
A B !A !B A && B A || B !A && !B !A || !B
TRUE TRUE FALSE FALSE TRUE TRUE FALSE FALSE
TRUE FALSE FALSE TRUE FALSE TRUE FALSE TRUE
FALSE TRUE TRUE FALSE FALSE TRUE FALSE TRUE
FALSE FALSE TRUE TRUE FALSE FALSE TRUE TRUE
Notice anything
interesting here?
27. THE NOT OPERATOR
We can extend truth tables to illustrate the not operator
Add new columns showing !A and !B and their use in
complex logical expressions
27
A B !A !B A && B A || B !A && !B !A || !B
TRUE TRUE FALSE FALSE TRUE TRUE FALSE FALSE
TRUE FALSE FALSE TRUE FALSE TRUE FALSE TRUE
FALSE TRUE TRUE FALSE FALSE TRUE FALSE TRUE
FALSE FALSE TRUE TRUE FALSE FALSE TRUE TRUE
The same pattern
occurs here too
28. THE NOT OPERATOR
From the truth table we can see that:
!(A || B) is the same as !A && ! B
!(A && B) is the same as !A || ! B
This rule is known as “De Morgan’s Law”
It allows us to simplify a complex logical expression by
“moving the not operation to expression operands”
28
29. THE NOT OPERATOR
To apply De Morgan’s Law, we must change the logical
operator and the expressions
The && operator changes into ||
The || operator changes into &&
The ! is applied to both expressions
Remember, two not operators side by side cancel each
other out so they can both be removed
29
30. THE NOT OPERATOR
When exp1 and exp2 are simple logical expressions
!(exp1 && exp2) same as (!exp1 || !exp2)
!(exp1 || exp2) same as (!exp1 && !exp2)
!(!exp1 || !exp2) same as (!!exp1 && !!exp2) or (exp1 && exp2)
!(!exp1 && !exp2) same as (!!exp1 || !!exp2) or (exp1 || exp2)
Hence, there are many different ways to represent the same
logical expression
30
31. THE NOT OPERATOR
Examples with float variables x = 4.3 and y = 9.2
((x < 5) && (y < 10)) is true
!((x < 5) && (y < 10)) is false
( !(x < 5) || !(y < 10)) is false
((x >= 5) || (y >= 10)) is false
!((x >= 5) || (y >= 10)) is true
( !(x >= 5) && !(y >= 10)) is true
((x < 5) && (y < 10)) is true
31
32. SUMMARY
In this section, we have focused on how logical
expressions can be written in C++
We have seen how relational operators (<, <=, >, >=, ==,
and !=) can be used to create simple logical expressions
We have seen how logical operators (&& and !!) can be
used to make more complex logical expressions
Finally, we have seen how the not operator (!) can be used
to reverse the true/false value of logical expressions
32
34. THE IF STATEMENT
Sometimes we want to selectively execute a block of code
The C++ syntax of the if statement is:
if ( logical expression )
{
//Block of code if expression is true
statement1;
statement2;
}
When expression is true, the block of code is executed
When expression is false, the block of code is skipped
34
35. THE IF STATEMENT
Allows statements to be conditionally executed or skipped
over
Models the way we mentally evaluate situations:
"If it is raining, take an umbrella."
"If it is cold outside, wear a coat."
35
38. THE IF STATEMENT
The if statement has the following syntax:
if ( condition )
statement;
if is a C
reserved word
The condition must be a
boolean expression. It must
evaluate to either true or false.
If the condition is true, the statement is executed.
If it is false, the statement is skipped.
39. THE IF STATEMENT
Programming style suggestions:
The block of code should be indented 3-4 spaces to aid
program readability
If the block of code is only one line long the { } brackets can
be omitted
Never put a semi-colon directly after the Boolean
expression in an if statement
The empty statement between ) and ; will be selectively
executed based on the logical expression value
The block of code directly below if statement will always be
executed, which is probably not what you intended
39
40. THE IF STATEMENT
We can visualize the program’s if statement decision
process using a “flow chart” diagram
40
Logical
expression
Block of code
true
false
41. THE IF STATEMENT
If the logical expression is true, we take one path through
the diagram (executing the block of code)
41
Logical
expression
Block of code
true
false
42. THE IF STATEMENT
If the logical expression is false, we take a different path
through the diagram (skipping over the block of code)
42
Logical
expression
Block of code
true
false
43. THE IF STATEMENT
// Simple if statement
int a, b;
cin >> a >> b;
if (a < b)
cout << “A is smaller than Bn”;
43
44. THE IF STATEMENT
// One line block of code
int a, b;
cin >> a >> b;
if (a == b)
cout << “A is equal to Bn”;
44
45. THE IF STATEMENT
// Block of code that never executes
if (1 == 2)
cout << “This code will never executen”;
45
46. THE IF STATEMENT
// Block of code that always executes
if (true)
cout << “This code will always executen”;
46
47. 47
IF SELECTION
STRUCTURE
Flowchart of pseudocode statement
true
false
grade >= 60 print “Passed”
A decision can be made on
any expression.
zero - false
nonzero - true
Example:
3, - 4 is true
Translation into C++
If student’s grade is greater than or equal to 60
Print “Passed”
if ( grade >= 60 )
cout << "Passed";
48. WHAT IS THE OUTPUT?
int m = 5;
int n = 10;
if (m < n)
++m;
++n;
cout << " m = " << m << " n = " << n << endl;
49. WHAT IS THE OUTPUT?
int m = 10;
int n = 5;
if (m < n)
++m;
++n;
cout << " m = " << m << " n = " << n << endl;
50. THE IF-ELSE
STATEMENT
Sometimes we need to handle two alternatives in our code
The C++ syntax of the if-else statement is:
if ( logical expression )
{
// Block of code to execute if expression is true
}
else
{
// Block of code to execute if expression is false
}
50
51. THE IF-ELSE
STATEMENT
An else clause can be added to an if statement to make an if-
else statement
if ( condition )
statement1;
else
statement2;
• If the condition is true, statement1 is executed;
if the condition is false, statement2 is executed
• One or the other will be executed, but not both
52. THE IF-ELSE
STATEMENT
Programming style suggestions:
Type the “if line” and the “else line” and the { } brackets so
they are vertically aligned with each other
Do not put a semi-colon after the “if line” or the “else line” or
you will get very strange run time errors
The two blocks of code should be indented 3-4 spaces to aid
program readability
If either block of code is only one line long the { } brackets can
be omitted
52
53. THE IF-ELSE
STATEMENT
We can visualize the program’s if-else statement decision
process using a “flow chart” diagram
53
Logical
expression
Block of code
executed if true
true
false
Block of code
executed if false
54. THE IF-ELSE
STATEMENT
If the logical expression is true, we take one path through
the diagram (executing one block of code)
54
Logical
expression
Block of code
executed if true
true
false
Block of code
executed if false
55. THE IF-ELSE
STATEMENT
If the logical expression is false, we take one path through
the diagram (executing the other block of code)
55
Logical
expression
Block of code
executed if true
true
false
Block of code
executed if false
56. THE IF-ELSE
STATEMENT
// Simple if-else example
if ((a > 0) && (b > 0))
{
c = a / b;
a = a - c;
}
else
{
c = a * b;
a = b + c;
}
56
57. THE IF-ELSE
STATEMENT
// Ugly if-else example
if (a < b) {
c = a * 3;
a = b - c; } else
a = c + 5;
This code is nice and short but it is hard to read
57
58. THE IF-ELSE
STATEMENT
// Pretty if-else example
if (a < b)
{
c = a * 3;
a = b - c;
}
else
a = c + 5;
This code takes more lines but it is easier to read
58
59. TESTING A SERIES OF
CONDITIONS
Use if … else … if sequences to test a series of
conditions:
If your score is over 90 your letter grade is A else if your
score is over 80 your letter grade is B else your letter grade
is C.
59
60. GRADE CALCULATION
EXAMPLE
How can we convert test scores to letter grades?
We are given numerical values between 0..100
We want to output A,B,C,D,F letter grades
We will want series of if-else statements
If test score between 90..100 output A
Else if score between 80..89 output B
Else if score between 70..79 output C
Else if score between 60..69 output D
Else if score between 0..59 output F
60
61. GRADE CALCULATION
EXAMPLE
// Program to convert test scores into letter grades
#include <iostream>
using namespace std;
int main()
{
// Local variable declarations
// Read test score
// Calculate grade
// Print output
return 0;
}
61
The first step is to
write comments in
the main program to
explain our approach
62. GRADE CALCULATION
EXAMPLE
// Program to convert test scores into letter grades
#include <iostream>
using namespace std;
int main()
{
// Local variable declarations
float Score = 0;
char Grade = '?' ;
// Read test score
cout << “Enter test score: “;
cin >> Score;
…
62
We add code to the
main program to get
the input test score
63. GRADE CALCULATION
EXAMPLE
…
// Local variable declarations
float Score = 0;
char Grade = '?' ;
// Read test score
cout << “Enter test score: “;
cin >> Score;
// Calculate grade
if (Score >= 90)
Grade = 'A';
// Print output
cout << “Grade: ” << Grade;
…
63
We add more code
calculate one letter
grade and print output
64. GRADE CALCULATION
EXAMPLE
…
// Calculate grade
if (Score >= 90)
Grade = 'A';
else if (Score >= 80)
Grade = 'B';
else if (Score >= 70)
Grade = 'C';
else if (Score >= 60)
Grade = 'D';
else
Grade = 'F';
…
64
We add more code to
calculate the remaining
letter grades
Do you think there will be any issues if we use if instead of else if
????
65. GRADE CALCULATION
EXAMPLE
How should we test the grade calculation program?
Start with values we know are in the middle of the
A,B,C,D,F letter ranges (e.g. 95,85,75,65,55)
Then test values “on the border” of the letter grade ranges
to make sure we have our “>=“ and “>” conditions right
(e.g. 79,80,81)
Then test values that are outside the 0..100 range to see
what happens – is this what we want?
Finally, see what happens if the user enters something
other than an integer value (e.g. 3.14159, “hello”)
65
66. RANGE CHECKING
Used to test to see if a value falls inside a range:
if (grade >= 0 && grade <= 100)
cout << "Valid grade";
Can also test to see if value falls outside of range:
if (grade <= 0 || grade >= 100)
cout << "Invalid grade";
Cannot use mathematical notation:
if (0 <= grade <= 100) //doesn’t work!
66
67. COMPARING
CHARACTERS
Characters are compared using their ASCII values
'A' < 'B'
The ASCII value of 'A' (65) is less than the ASCII value of
'B'(66)
'1' < '2'
The ASCII value of '1' (49) is less than the ASCI value of '2'
(50)
Lowercase letters have higher ASCII codes than uppercase
letters, so 'a' > 'Z'
67
68. SUMMARY
In this section we have studied the syntax and use of the
C++ if statement and the if-else statement
We have also seen how flow chart diagrams can be used
to visualize different execution paths in a program
Finally, we showed how if statements can be used to
implement a simple grade calculation program
68
70. NESTED IF
STATEMENTS
We can have two or more if statements inside each other to
check multiple conditions
These are called nested if statements
Nested if statements can be used to test more than one
condition
Use indentation to reflect nesting and aid readability
Typically indent 3-4 spaces or one tab
Need to take care when matching up { } brackets
This way you can decipher the nesting of conditions
70
71. NESTED IF
STATEMENTS
if ( logical expression1 )
{
if ( logical expression2 )
{
// Statements to execute if expressions1 and expression2 are true
}
else
{
// Statements to execute if expression1 true and expression2 false
}
}
else
{
// Statements to execute if expression1 false
}
71
73. NESTED IF CODE
// Determine loan qualification
if (employed == ‘y’)
{
if (recentGrad == ‘y’)
{
cout << “You qualify!”
}
}
Note: this could be done with one if and two conditions.
73
74. NESTED IF
STATEMENTS
// Simple nested if example
cin >> a >> b;
if (a < b)
{
cout << “A is smaller than Bn”;
if ((a > 0) && (b > 0))
cout << “A and B are both positiven”;
else
cout << “A or B or both are negativen”;
}
74
75. NESTED IF
STATEMENTS
// Ugly nested if example
if (a > 0) {
if (b < 0) {
a = 3 * b;
c = a + b; } }
else {
a = 2 * a;
c = b / a; }
It is hard to see what condition the else code goes with
75
76. NESTED IF
STATEMENTS
// Pretty nested if example
if (a > 0)
{
if (b < 0)
{
a = 3 * b;
c = a + b;
}
}
else
{
a = 2 * a;
c = b / a;
}
76
77. BOOLEAN VARIABLES
In C++ we can store true/false values in Boolean variables
The constants “true” and “false” can be used to initialize
these variables
bool Done = true;
bool Quit = false;
Boolean expressions can also be used to initialize these
variables
bool Positive = (a >= 0);
bool Negative = (b < 0);
77
78. BOOLEAN VARIABLES
Boolean variables and true/false constants can also be
used in logical expressions
(Done == true) is true
(Quit != true) is true
(Done == Quit) is false
(true == Positive) is true
((a < b) == false) is false
(Negative) is false
78
79. BOOLEAN VARIABLES
Internally C++ stores Boolean variables as integers
0 is normally used for false
1 is normally used for true
Any value != 1 is also considered true
It is considered “bad programming style” to use integers
instead of true/false
bool Good = 0;
bool Bad = 1;
bool Ugly = a;
79
80. BOOLEAN VARIABLES
Integers are used when writing Boolean values
cout << Good will print 0
cout << Bad will print 1
cout << Ugly will also print 1
Integers are also used when reading Boolean values
cin >> Good;
Entering 0 sets Good variable to false
Entering any value >= 1 sets Good variable to true
Entering value < 0 also sets Good variable to true
80
81. PRIME NUMBER
EXAMPLE
How can we test a number to see if it is prime?
We are given numerical values between 1..100
We need to see if it has any factors besides 1 and itself
We need some nested if statements
Test if input number is between 1..100
If so, then test if 2,3,5,7 are factors of input number
Then print out “prime” or “not prime”
81
82. PRIME NUMBER
EXAMPLE
// Check for prime numbers using a factoring approach
#include <iostream>
using namespace std;
int main()
{
// Local variable declarations
// Read input parameters
// Check input is valid
// Check if number is prime
// Print output
return 0;
}
82
For the first version
of program we just
write comments in
the main program to
explain our approach
83. PRIME NUMBER
EXAMPLE
// Check for prime numbers using a factoring approach
#include <iostream>
using namespace std;
int main()
{
// Local variable declarations
int Number = 0;
bool Prime = true;
// Read input parameters
cout << “Enter a number [1..100]:”;
cin >> Number;
83
For the second
version of program
we initialize variables
and read the input
value from user
84. PRIME NUMBER
EXAMPLE
…
cout << “Enter a number [1..100]:”;
cin >> Number;
// Check input is valid
if ((Number < 1) || (Number > 100))
cout << “Error: Number is out of rangen”;
else
{
// Check if number is prime
// Print output
}
84
For the next version
of the program we
add code to verify the
range of input value
85. PRIME NUMBER
EXAMPLE
// Check if number is prime
if (Number == 1)
Prime = false;
if ((Number > 2) && (Number % 2 == 0))
Prime = false;
if ((Number > 3) && (Number % 3 == 0)) Prime = false;
if ((Number > 5) && (Number % 5 == 0)) Prime = false;
if ((Number > 7) && (Number % 7 == 0)) Prime = false;
// Print output
if (Prime)
cout << “Number “ << Number << “ IS primen”;
else
cout << “Number “ << Number << “ is NOT primen”;
85
In the final
version we finish
the prime number
calculation and
print the output
86. PRIME NUMBER
EXAMPLE
How should we test the prime number program?
Test the range checking code by entering values “on the
border” of the input range (e.g. 0,1,2 and 99,100,101)
Test program with several values we know are prime
Test program with several values we know are not prime
To be really compulsive we could test all values between
1..100 and compare to known prime numbers
What is wrong with this program?
It only works for inputs between 1..100
It will not “scale up” easily if we extend this input range
86
87. SUMMARY
In this section we showed how if statements and if-else
statements can be nested inside each other to create more
complex paths through a program
We also showed how proper indenting is important to read
and understand programs with nested if statements
We have seen how Boolean variables can be used to store
true/false values in a program
Finally, we used an incremental approach to create a
program for checking the factors of input numbers to see
if they are prime or not
87
88. EXAMPLE: WAGES.CPP
Write a C++ program that calculates weekly wages for hourly
employees.
Regular hours 0 - 40 are paid at $10/hours.
Overtime (> 40 hours per week) is paid at 150%
90. SWITCH STATEMENTS
The switch statement is convenient for handling multiple
branches based on the the value of one decision variable
The program looks at the value of the decision variable
The program jumps directly to the matching case label
The statements following the case label are executed
Special features of the switch statement:
The “break” command at the end of a block of statements
will make the program jump to the end of the switch
The program executes the statements after the “default”
label if no other cases match the decision variable
90
91. SWITCH STATEMENTS
switch ( decision variable )
{
case value1 :
// Statements to execute if variable equals value1
break;
case value2:
// Statements to execute if variable equals value2
break;
...
default:
// Statements to execute if variable not equal to any value
}
91
92. SWITCH STATEMENTS
int Number = 0;
cin >> Number;
switch (Number)
{
case 0:
cout << “This is nothing << endl;
break;
case 7:
cout << “My favorite number” << endl;
break;
92
93. SWITCH STATEMENTS
case 21:
cout << “Lets go for a drink” << endl;
break;
case 42:
cout << “The answer to the ultimate question” << endl;
break;
default:
cout << “This number is boring” << endl;
}
93
94. SWITCH STATEMENTS
The main advantage of switch statement over a sequence
of if-else statements is that it is much faster
Jumping to blocks of code is based on a lookup table
instead of a sequence of variable comparisons
The main disadvantage of switch statements is that the
decision variable must be an integer (or a character)
We can not use a switch with a float or string decision
variable or with complex logical expressions
94
95. MENU EXAMPLE
How can we create a user interface for banking?
Assume user selects commands from a menu
We need to see read and process user commands
We can use a switch statements to handle menu
Ask user for numerical code for user command
Jump to the code to process that banking operation
Repeat until the user quits the application
95
96. MENU EXAMPLE
// Simulate bank deposits and withdrawals
#include <iostream>
using namespace std;
int main()
{
// Local variable declarations
// Print command prompt
// Read user input
// Handle banking command
return 0;
}
96
For the first version
of program we just
write comments in
the main program to
explain our approach
97. MENU EXAMPLE
…
// Local variable declarations
int Command = 0;
// Print command prompt
cout << “Enter command number:n”;
// Read user input
cin >> Command;
…
97
For the next version
of program we add
the code to read the
user command
98. MENU EXAMPLE
// Handle banking command
switch (Command)
{
case 0: // Quit code
break;
case 1: // Deposit code
break;
case 2: // Withdraw code
break;
case 3: // Print balance code
break;
}
98
Then we add the
skeleton of the switch
statement to handle
the user command
99. MENU EXAMPLE
// Simulate bank deposits and withdrawals
#include <iostream>
using namespace std;
int main()
{
// Local variable declarations
int Command = 0;
int Money = 0;
int Balance = 100;
// Print command prompt
cout << “Enter command number:n”
<< “ 0 - quitn”
<< “ 1 - deposit moneyn”
<< “ 2 - withdraw moneyn”
<< “ 3 - print balancen”;
99
In the final version
add bank account
variables and add
code to perform
banking operations
100. MENU EXAMPLE
// Read and handle banking commands
cin >> Command;
switch (Command)
{
case 0: // Quit code
cout << “See you later!” << endl;
break;
case 1: // Deposit code
cout << “Enter deposit amount: “;
cin >> Money;
Balance = Balance + Money;
break;
100
102. MENU EXAMPLE
How should we test this program?
Test the code by entering all valid menu commands
What happens if we enter an invalid menu command?
What happens if we enter an invalid deposit or withdraw
amount (e.g. negative input values)?
What is wrong with this program?
We might end up with a negative account balance
There is only one bank account and zero security
102
103. SOFTWARE
ENGINEERING TIPS
There are many ways to write conditional code
Your task is to find the simplest correct code for the task
Make your code easy to read and understand
Indent your program to reflect the nesting of blocks of code
Develop your program incrementally
Compile and run your code frequently
Anticipate potential user input errors
Check for normal and abnormal input values
103
104. SOFTWARE
ENGINEERING TIPS
Common programming mistakes
Missing or unmatched ( ) brackets in logical expressions
Missing or unmatched { } brackets in conditional statement
Missing break statement at bottom of switch cases
Never use & instead of && in logical expressions
Never use | instead of || in logical expressions
Never use = instead of == in logical expressions
Never use “;” directly after logical expression
104
105. SUMMARY
In this section we have studied the syntax and use of the
C++ switch statement
We also showed an example where a switch statement
was used to create a menu-based banking program
Finally, have discussed several software engineering tips
for creating and debugging conditional programs
105
Editor's Notes
A prime number (or a prime) is a natural number greater than 1 that is not a product of two smaller natural numbers. A natural number greater than 1 that is not prime is called a composite number. For example, 5 is prime because the only ways of writing it as a product, 1 × 5 or 5 × 1, involve 5 itself. However, 4 is composite because it is a product (2 × 2) in which both numbers are smaller than 4. Primes are central in number theory because of the fundamental theorem of arithmetic: every natural number greater than 1 is either a prime itself or can be factorized as a product of primes that is unique up to their order.