Module 3 Selection Structures 4/3/2019 CSE 1321 Module 3.

Slides:



Advertisements
Similar presentations
AP Computer Science Anthony Keen. Computer 101 What happens when you turn a computer on? –BIOS tries to start a system loader –A system loader tries to.
Advertisements

Computer Programming Lab(7).
C++ Basics March 10th. A C++ program //if necessary include headers //#include void main() { //variable declaration //read values input from user //computation.
Computer Programming Lab 8.
Introduction to C# Erick Pranata © Sekolah Tinggi Teknik Surabaya 1.
CSCI S-1 Section 5. Deadlines for Problem Set 3 Part A – Friday, July 10, 17:00 EST Parts B – Tuesday, July 14, 17:00 EST Getting the code examples from.
Making Choices (Chap 3) If you wish to defrost, press the defrost button; otherwise press the full power button. Let the dough rise in a warm place until.
Switch structure Switch structure selects one from several alternatives depending on the value of the controlling expression. The controlling expression.
 To be able to write larger programs ◦ By breaking them down into smaller parts and passing data between the parts.  To understand the concepts of Methods.
Computer Programming Lab(4).
Implementing Control Logic in C# Svetlin Nakov Telerik Corporation
Computer Programming Lab(5).
Introduction to Classes SWE 344 Internet Protocols & Client Server Programming.
Programming Methodology (1). import java.util.*; public class FindCost3 { public static void main(String[] args ) { Scanner sc = new Scanner(System.in);
Control Structures A control structure is simply a pattern for controlling the flow of a program module. The three fundamental control structures of a.
Scott Marino MSMIS Kean University MSAS5104 Programming with Data Structures and Algorithms Week 5 Scott Marino.
Basic Java Programming CSCI 392 Week Two. Stuff that is the same as C++ for loops and while loops for (int i=0; i
1 Conditional statements Dept. of Computer Engineering Faculty of Engineering, Kasetsart University Bangkok, Thailand.
Parameters. Overview A Reminder Why Parameters are Needed How Parameters Work Value Parameters Reference Parameters Out Parameters.
CSI 1390: Introduction to Computers TA: Tapu Kumar Ghose Office: STE 5014 Office hours: Thursday 1300 – 1400hrs.
Branches and Program Design
BEGINNING PROGRAMMING.  Literally – giving instructions to a computer so that it does what you want  Practically – using a programming language (such.
CS110 Programming Language I Lab 4: Control Statements I Computer Science Department Spring 2014.
Lesson 4 Input. JAVA Input JAVA input is not straightforward and is different depending on the JAVA environment that you are using. The reason it is not.
Introduction to Computing Concepts Note Set 15. JOptionPane.showMessageDialog Message Dialog Allows you to give a brief message to the user Can be used.
Additional Pair Programming Exercises 1. Problem 1 For a wheel of radius r feet, how many revolutions are required for that wheel to travel 1 mile? What.
Formatted Output (printf) CSE 1310 – Introduction to Computers and Programming Vassilis Athitsos University of Texas at Arlington 1.
FOR LOOP WALK THROUGH public class NestedFor { public static void main(String [] args) { for (int i = 1; i
 CSC111 Quick Revision. Problem Write a java code that read a string, then show a list of options to the user to select from them, where:  L to print.
©2016 Pearson Education, Inc. Upper Saddle River, NJ. All Rights Reserved. CSC 110 – INTRO TO COMPUTING - PROGRAMMING Switch Statement.
import java.util.Scanner; class myCode { public static void main(String[] args) { Scanner input= new Scanner(System.in); int num1; System.out.println(“Enter.
Computer Science A 1. Course plan Introduction to programming Basic concepts of typical programming languages. Tools: compiler, editor, integrated editor,
Introduction to Programming G50PRO University of Nottingham Unit 6 : Control Flow Statements 2 Paul Tennent
Methods Matthew Harrison. Overview ● There are five main aspects of methods... ● 1) Modifiers – public, private ● 2) Method Name ● 3) Parameters ● 4)
PYTHON PROGRAMMING Year 9. Objective and Outcome Teaching Objective Today we will look at conditional statements in order to understand how programs can.
Chapter 2 Clarifications
TemperatureConversion
Compound Condition Break , Continue Switch Statements in Java
TEMPERATURE CONVERSION
Temperature: Comparing degrees Celsius (C) and degrees Fahrenheit (F)
Something about Java Introduction to Problem Solving and Programming 1.
Computing Adjusted Quiz Total Score
Lecture 11 C Parameters Richard Gesick.
Stack Memory 2 (also called Call Stack)
The switch statement: an alternative to writing a lot of conditionals
Module 4 Loops and Repetition 2/1/2019 CSE 1321 Module 4.
class PrintOnetoTen { public static void main(String args[]) {
Module 3 Selection Structures 2/19/2019 CSE 1321 Module 3.
Module 4 Loops and Repetition 4/7/2019 CSE 1321 Module 4.
Module 2 - Part 1 Variables, Assignment, and Data Types
Lecture 1 Review of 1301/1321 CSE /26/2018.
Methods and Data Passing
Module 3 Selection Structures 4/4/2019 CSE 1321 Module 3.
Scope of variables class scopeofvars {
Module 2 Variables, Assignment, and Data Types
Module 4 Loops and Repetition 4/4/2019 CSE 1321 Module 4.
Methods and Data Passing
CSE Module 1 A Programming Primer
Life is Full of Alternatives
CSE Module 1 A Programming Primer
Module 3 Selection Structures 4/5/2019 CSE 1321 Module 3.
Object-Oriented Programming and class Design
Var Name =Console . ReadLine();
Module 4 Loops and Repetition 4/15/2019 CSE 1321 Module 4.
Object-Oriented Programming and class Design
CSE Module 1 A Programming Primer
Module 3 Selection Structures 6/25/2019 CSE 1321 Module 3.
Module 3 Selection Structures 12/7/2019 CSE 1321 Module 3.
Object-Oriented Design AND CLASS PROPERTIES
Presentation transcript:

Module 3 Selection Structures 4/3/2019 CSE 1321 Module 3

Pseudocode - IF Statement MAIN Fahrenheit ← 0, Celsius ← 0 PRINT “Enter Celsius temperature: ” READ user input Celsius ← user input Fahrenheit ← 9.0 / 5.0 * Celsius + 32 PRINT Fahrenheit IF (Fahrenheit > = 90) THEN PRINT “heat warning” ENDIF END MAIN Ps 4/3/2019 CSE 1321 Module 3

C# Example - if Statement using System; class Program { public static void Main(string[] args) double celsius = 0.0, fahrenheit = 0.0; Console.Write("What is the Celsius temperature? "); celsius = Convert.ToDouble(Console.ReadLine()); fahrenheit = 9.0 / 5.0 * celsius + 32; Console.WriteLine("The temperature is " + fahrenheit + " degrees Fahrenheit"); if (fahrenheit >= 90) Console.WriteLine("It is really hot out there!"); } 4/3/2019 CSE 1321 Module 3

Pseudocode – IF-ELSE Statement MAIN Fahrenheit ← 0, Celsius ← 0 PRINT “Enter Celsius temperature: ” READ user input Celsius ← user input Fahrenheit ← 9.0 / 5.0 * Celsius + 32 PRINT Fahrenheit IF (Fahrenheit > = 90) THEN PRINT “heat warning” ELSE PRINT “there is no extreme heat” ENDIF END MAIN Ps 4/3/2019 CSE 1321 Module 3

C# Example – if-else (Code Snippet) double celsius = 0.0, fahrenheit = 0.0; Console.Write("What is the Celsius temperature? "); celsius = Convert.ToDouble(Console.ReadLine()); fahrenheit = 9.0 / 5.0 * celsius + 32; Console.WriteLine("The temperature is " + fahrenheit + " degrees Fahrenheit"); if (fahrenheit >= 90) { Console.WriteLine("It is really hot out there, be careful!"); } else { Console.WriteLine(“There is no extreme heat today.”); 4/3/2019 CSE 1321 Module 3

Pseudocode – IF-ELSE-IF MAIN Fahrenheit ← 0, Celsius ← 0 PRINT “Enter Celsius temperature: ” READ user input Celsius ← user input Fahrenheit ← 9.0 / 5.0 * Celsius + 32 PRINT Fahrenheit IF (Fahrenheit > = 90) THEN PRINT “heat warning” ELSE IF (Fahrenheit >= 80) THEN PRINT “it is warm, but there is no extreme heat” ELSE IF (Fahrenheit >= 70) THEN PRINT “the temperature is pleasant and suggest a picnic” ELSE PRINT “a suggestion to take a jacket” END IF END MAIN Ps 4/3/2019 CSE 1321 Module 3

C# Example – if-else-if double celsius = 0.0, fahrenheit = 0.0; Console.Write("What is the Celsius temperature? "); celsius = Convert.ToDouble(Console.ReadLine()); fahrenheit = 9.0 / 5.0 * celsius + 32; Console.WriteLine("The temperature is " + fahrenheit + "degrees Fahrenheit"); if(fahrenheit >= 90){ Console.WriteLine(“It is really hot!”); } else if (fahrenheit >= 80){ Console.WriteLine(“It is very warm!”); else if (fahrenheit >= 70){ Console.WriteLine(“It is very pleasant!”) else { Console.WriteLine(“It is cool today”); 4/3/2019 CSE 1321 Module 3

Pseudocode – switch Statement // Read user input like before conditions ← compute using Fahrenheit variable / 10 CASE conditions OF 10 : PRINT “stay inside”, BREAK 9 : PRINT “be careful due to heat”, BREAK 8 : PRINT “it is hot, but not extreme”, BREAK 7 : PRINT “pack a picnic”, BREAK DEFAULT : PRINT “take a jacket”, BREAK ENDCASE Ps 4/3/2019 CSE 1321 Module 3

C# switch Example int conditions = (int)fahrenheit / 10; Console.WriteLine("It is in the " + conditions + "0's."); switch (conditions) { case 10: Console.WriteLine("It’s hot! Stay inside!"); break; case 9: Console.WriteLine("It is really hot out there!"); case 8: Console.WriteLine("It is warm, but no extreme heat!"); case 7: Console.WriteLine("It is very pleasant today!"); default: Console.WriteLine("Take a jacket!"); } 4/3/2019 CSE 1321 Module 3