Skill Area 306: Develop and Implement Computer Program

Similar documents
Microsoft Visual Basic 2005: Reloaded

SKILL AREA 306: DEVELOP AND IMPLEMENT COMPUTER PROGRAMS

Introduction to Visual Basic and Visual C++ Arithmetic Expression. Arithmetic Expression. Using Arithmetic Expression. Lesson 4.

Programming Logic and Design Sixth Edition

An overview about DroidBasic For Android

Microsoft Visual Basic 2015: Reloaded


Chapter 4: Making Decisions

Chapter 4: Making Decisions

An Introduction to Programming with C++ Sixth Edition. Chapter 7 The Repetition Structure

Chapter 4: Making Decisions. Copyright 2012 Pearson Education, Inc. Sunday, September 7, 14

Microsoft Visual Basic 2005: Reloaded

GO - OPERATORS. This tutorial will explain the arithmetic, relational, logical, bitwise, assignment and other operators one by one.

Control Structures. Lecture 4 COP 3014 Fall September 18, 2017

Loops! Loops! Loops! Lecture 5 COP 3014 Fall September 25, 2017

Overview About KBasic

LECTURE 04 MAKING DECISIONS

Unit 3. Operators. School of Science and Technology INTRODUCTION

Conditions, logical expressions, and selection. Introduction to control structures

Introduction to Programming

Lecture 5 Tao Wang 1

Flow Control. So Far: Writing simple statements that get executed one after another.

Individual research task. You should all have completed the research task set last week. Please make sure you hand it in today.

CT 229 Java Syntax Continued

Chapter 2 Working with Data Types and Operators

Structured Program Development

Program Development. Chapter 3: Program Statements. Program Statements. Requirements. Java Software Solutions for AP* Computer Science A 2nd Edition

Chapter 3: Program Statements

Overview: Programming Concepts. Programming Concepts. Names, Values, And Variables

Overview: Programming Concepts. Programming Concepts. Chapter 18: Get With the Program: Fundamental Concepts Expressed in JavaScript

Introduction to Programming Using Java (98-388)

In Delphi script, when values are assigned to variables, the colon-equal operator is used; :=

Objectives. Chapter 4: Control Structures I (Selection) Objectives (cont d.) Control Structures. Control Structures (cont d.) Relational Operators

C-LANGUAGE CURRICULAM

Chapter 4 The If Then Statement

CS 115 Lecture 8. Selection: the if statement. Neil Moore

Computers Programming Course 6. Iulian Năstac

Chapter 4: Control Structures I (Selection) Objectives. Objectives (cont d.) Control Structures. Control Structures (cont d.

Pseudo Code and Flow Charts. Chapter 1 Lesson 2

SFPL Reference Manual

CSCI 136 Data Structures & Advanced Programming. Fall 2018 Instructors Bill Lenhart & Bill Jannen

Boolean Logic & Branching Lab Conditional Tests

CP FAQS Q-1) Define flowchart and explain Various symbols of flowchart Q-2) Explain basic structure of c language Documentation section :

TCL - STRINGS. Boolean value can be represented as 1, yes or true for true and 0, no, or false for false.


Program Elements -- Introduction

CSE 115. Introduction to Computer Science I

LECTURE 5 Control Structures Part 2

Logical Operators and switch

CS313D: ADVANCED PROGRAMMING LANGUAGE

Programming Language 2 (PL2)

Chapter 17. Fundamental Concepts Expressed in JavaScript

WEEK 4 OPERATORS, EXPRESSIONS AND STATEMENTS

More Things We Can Do With It! Overview. Circle Calculations. πr 2. π = More operators and expression types More statements

SMS 3515: Scientific Computing. Sem /2015

COP 2000 Introduction to Computer Programming Mid-Term Exam Review

Petros: A Multi-purpose Text File Manipulation Language

COMPUTING Syllabus Version 1.0

Add Subtract Multiply Divide

BIL101E: Introduction to Computers and Information systems Lecture 8

Introduction to Decision Structures. Boolean & If Statements. Different Types of Decisions. Boolean Logic. Relational Operators


5/3/2006. Today! HelloWorld in BlueJ. HelloWorld in BlueJ, Cont. HelloWorld in BlueJ, Cont. HelloWorld in BlueJ, Cont. HelloWorld in BlueJ, Cont.

SSEA Computer Science: Track A. Dr. Cynthia Lee Lecturer in Computer Science Stanford

Le L c e t c ur u e e 2 To T p o i p c i s c t o o b e b e co c v o e v r e ed e Variables Operators

Chapter 3 Syntax, Errors, and Debugging. Fundamentals of Java

Logic Design: Part 2


Looping. Arizona State University 1

Introduction. C provides two styles of flow control:

PLD Semester Exam Study Guide Dec. 2018

Chapter 3: Operators, Expressions and Type Conversion

Computational Expression

FRAC: Language Reference Manual

Introduction to Conditionals

LCSL Reference Manual

SNS COLLEGE OF ENGINEERING,

This tutorial will teach you about operators. Operators are symbols that are used to represent an actions used in programming.

Basics of Java Programming variables, assignment, and input

CHAPTER 1 Introduction to Computers and Programming CHAPTER 2 Introduction to C++ ( Hexadecimal 0xF4 and Octal literals 031) cout Object

Standard. Number of Correlations

Introduction to C++ Lecture Set 2. Introduction to C++ Week 2 Dr Alex Martin 2013 Slide 1

Java provides a rich set of operators to manipulate variables. We can divide all the Java operators into the following groups:

Cellular Automata Language (CAL) Language Reference Manual

Operators & Expressions

Problem Solving FLOWCHART. by Noor Azida Binti Sahabudin Faculty of Computer Systems & Software Engineering

Lecture 5: Making Decisions

Week 1 Introduction to Computer and Algorithm (Part1) UniMAP Sem II 11/12 DKT121: Basic Computer Programming 1

CSC 121 Spring 2017 Howard Rosenthal

Mirage. Language Reference Manual. Image drawn using Mirage 1.1. Columbia University COMS W4115 Programming Languages and Translators Fall 2006

Information Science 1

C++ Programming: From Problem Analysis to Program Design, Fourth Edition. Chapter 4: Control Structures I (Selection)

Prof. Navrati Saxena TA: Rochak Sachan

Chapter 2.4: Common facilities of procedural languages

CS 106A, Lecture 5 Booleans and Control Flow

Chapter 4: Basic C Operators

Note: unless otherwise stated, the questions are with reference to the C Programming Language. You may use extra sheets if need be.

9/10/10. Arithmetic Operators. Today. Assigning floats to ints. Arithmetic Operators & Expressions. What do you think is the output?

CSc 372. Comparative Programming Languages. 4 : Haskell Basics. Department of Computer Science University of Arizona

Making Decisions and Working with Strings

Transcription:

Add your company slogan Skill Area 306: Develop and Implement Computer Program Computer Programming (YPG) LOGO

Skill Area 306.2: Produce Structured Program 306.2.1 Write Algorithm 306.2.2 Apply appropriate program design tools 306.2.3 Apply logical and operational operators 306.2.4 Apply control structures 306.2.5 Write program 306.2.6 Tests and debug program

The Selection Structure Selection structure (or decision structure): Used to select a path to take based on the outcome of a decision or comparison Condition: The decision to be made Results in a Boolean (True or False) answer Four forms of selection structure: If If/Else If/ElseIf/Else Case

The Selection Structure (continued) Figure 306.2-1: Selection structures you might use today

Writing Pseudocode for the If and If/Else Selection Structures If selection structure: contains one set of instructions to process when the condition is true If/Else selection structure: Contains two sets of instructions One set is processed when the condition is true The other set is processed when the condition is false True path: path to follow when condition is true False path: path to follow when condition is false

Figure 306.2-2: Examples of the If and If/Else selection structures written in pseudocode

Flowcharting the If and If/Else Selection Structures Flowchart uses standardized symbols to show the steps a computer must take Selection/repetition symbol: Diamond shape Represents both selection and repetition structures One flowline entering and two flowlines leaving

Figure 306.2-3: Examples of the If and If/Else selection structures in flowchart form

Coding the If and If/Else Selection Structures If Then Else statement: used to code the If and If/Else selection structures Else clause: an optional part of the If statement Condition must be a Boolean expression Must evaluate to either True or False Statement block: set of statements terminated by an Else or End If If Then Else statement can contain variables, literal constants, named constants, properties, methods, arithmetic operators, comparison operators, and logical operators

Coding the If and If/Else Selection Structures (continued) Figure 306.2-4: How to use the If/Then/Else statement to code the If/Then/Else selection structure

Figure 306.3-4: How to use the If/Then/Else statement to code the If/Then/Else selection structure (continued)

Comparison Operators Comparison operators (or relational operators): Used as part of the condition in an If statement Most commonly used comparison operators: Equal to: = Greater than: > Greater than or equal to: >= Less than: < Less than or equal to: <= Not equal to: <>

Figure 306.2-5: How to use the most commonly used comparison operators

Comparison Operators (continued) Comparison operators: Have no order of precedence Are evaluated from left to right in an expression Are evaluated after any arithmetic operators in the expression All expressions containing comparison operators evaluate to True or False only

Comparison Operators (continued) Figure 306.2-6: Evaluation steps for an expression containing arithmetic and comparison operators

Using Comparison Operators Swapping Numeric Values Pseudocode for a procedure that displays highest and lowest of two numbers Figure 306.2-7: Sample run of the Number Swap application

Using Comparison Operators Swapping Numeric Values (continued) Figure 306.2-8: Pseudocode showing the If selection structure

Figure 306.2-9: Flowchart showing the If selection structure

Using Comparison Operators Swapping Numeric Values (continued) Figure 306.2-10: The If selection structure shown in the displaybutton s Click event procedure

Using Comparison Operators Swapping Numeric Values (continued) Block scope: the scope of a variable created within a statement block A block-scope variable can only be used within the statement block in which it was declared Concatenation operator (&): connects or links two strings together ControlChars.NewLine constant: Advances the insertion point to the next line

Using Comparison Operators Swapping Numeric Values (continued) Figure 306.2-11: Illustration of the swapping concept

Using Comparison Operators Swapping Numeric Values (continued) Figure 306.2-12: How to concatenate strings

Using Comparison Operators Example 2 Pseudocode for a procedure to allow the user to display the sum or difference of two numbers: Figure 306.2-13: Sample run of the Addition and Subtraction Calculator application

Using Comparison Operators Example 2 (continued) Figure 306.2-14: Pseudocode showing the If/Else selection structure

Figure 306.2-15: Flowchart showing the If/Else selection structure

Using Comparison Operators Example 2 (continued) Figure 306.2-16: The If/Else selection structure shown in the calcbutton s Click event procedure

Using Comparison Operators Example 2 (continued) MaxLength property: text box property that specifies the maximum number of characters that can be entered CharacterCasing property: text box property that indicates if text should remain as typed or be converted to upper- or lowercase

Using the ToUpper and ToLower Methods String comparisons in Visual Basic are case-sensitive ToUpper method: converts a string to uppercase ToLower method: converts a string to lowercase ToUpper and ToLower can be used to permanently or temporarily convert a variable s contents

Figure 306.2-17a: How to use the ToUpper and ToLower methods

Using the ToUpper and ToLower Methods (continued) Figure 306.2-17b: How to use the ToUpper and ToLower methods (continued)

Using the ToUpper and ToLower Methods (continued) Figure 306.2-18: Code showing the ToUpper method in the assignment statement

Using the ToUpper and ToLower Methods (continued) Figure 306.2-19: Code showing the ToUpper method in the If Then Else statement s condition

Logical Operators Logical operators (or Boolean operators): Used to combine two or more conditions into one compound condition Compound condition: a combination of conditions using logical operator(s)

Logical Operators (continued) Figure 306.2-20: How to use the logical operators

Figure 306.2-20: How to use the logical operators (continued)

Logical Operators (continued) Truth tables: used to evaluate logical operators in an expression Short-circuit evaluation: an evaluation in which the second condition may not be evaluated And and Or operations always evaluate both conditions AndAlso and OrElse operations do not evaluate the second condition if the first condition is false

Logical Operators (continued) Figure 4-21: Truth tables

Using the Truth Tables Use And or AndAlso when both conditions must be true to give a true result Use Or or OrElse when one or both conditions must be true to give a true result Use XOr when exactly one condition must be true to give a true result Logical operators are evaluated after arithmetic or comparison operators in an expression

Using the Truth Tables (continued) Figure 306.2-22: Order of precedence for arithmetic, comparison, and logical operators

Using the Truth Tables (continued) Figure 306.2-23: Evaluation steps for an expression containing arithmetic, comparison, and logical operators

Using Logical Operators in an If Then Else Statement Data validation: Process of verifying that the input data is within the expected range Use an If Then Else statement to validate input data Figure 306.2-24: AndAlso and OrElse logical operators in the If Then Else statement

Figure 306.2-24: AndAlso and OrElse logical operators in the If Then Else statement (continued)

Using Logical Operators in an If Then Else Statement (continued) Figure 306.2-25: Sample run of the application that contains the calcbutton s Click event procedure

Generating Random Integers Pseudo-random number generator: a device that produces a sequence of numbers that meets certain statistical requirements for randomness Random object: represents a pseudorandom number generator Random.Next method: Generates a random integer Can specify a minimum and maximum value

Generating Random Integers (continued) Figure 306.2-26: How to generate random numbers

Generating Random Integers (continued) Figure 306.2-27: Sample run of the Random Integers application

Generating Random Integers (continued) Figure 306.2-28: The generatebutton s Click event procedure

Programming Tutorial Figure 306.2-30: User interface

Programming Example Figure 306.2-38: User interface