Char ch; ch ‘L’‘X’‘V’‘I’ As in Roman numerals Want to give each a value, n say switch (ch) { case ‘I’:n = 1; break; case ‘V’:n = 5; break; … default:cout.

Slides:



Advertisements
Similar presentations
#include void main() { float x = 1.66, y = 1.75; printf(%f%f,ceil(x), floor(y)); }
Advertisements

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.
Recursive Descent Technique CMSC 331. UMBC 2 The Header /* This program matches the following A -> B { '|' B } B -> C { '&' C } C -> D { '^' D } D ->
For(int i = 1; i
Making Choices in C if/else statement logical operators break and continue statements switch statement the conditional operator.
C++ Basics March 10th. A C++ program //if necessary include headers //#include void main() { //variable declaration //read values input from user //computation.
Java Syntax Part I Comments Identifiers Primitive Data Types Assignment.
Conditional Operator (?:) Conditional operator (?:) takes three arguments (ternary) Syntax for using the conditional operator:
Switch Switch case statements are a substitute for long if statements that compare a variable to several "integral" values ("integral" values are simply.
Introduction to Computers and Programming Lecture 7:
Programming Switch command. COMP102 Prog. Fundamentals: Switch command / Slide 2 Multiple Selection: The switch Statement value1 action 1 value2 action.
1 10/20/08CS150 Introduction to Computer Science 1 do/while and Nested Loops Section 5.5 & 5.11.
Overview creating your own functions calling your own functions.
COMP 110 If / Else and Case Statements Tabitha Peck M.S. February 4, 2008 MWF 3-3:50 pm Philips
Selection Structures: Switch CSC 1401: Introduction to Programming with Java Week 4 – Lecture 1 Wanda M. Kunkle.
Tutorial#3 if..../if.....else/if.....else if/ switch Solution.
C++ programming I Lab#3 Control Statements Instructor: Eng. Ruba A. Salamah Tuseday: 17/10/2010.
14-Jul-15 State Machines Abbreviated lecture. 2 What is a state machine? A state machine is a different way of thinking about computation A state machine.
The switch statement: an N-way selection statement.
Switch Statements. Switch Statement Often you want to do a series of tests –if i==0 … else if i==1 …. else if i==2 … else if i==3 …. C++ provides the.
CP104 Introduction to Programming Selection Structures_3 Lecture 11 __ 1 The Switch Statement The switch statement provides another means to select one.
Selection Statements in C++ If Statement in C++ Semantics: These statements have the same meaning as in the algorithmic language. 2- Two way selection:
IF-ELSE IF-ELSE STATEMENT SWITCH-CASE STATEMENT Computer Programming Asst. Prof. Dr. Choopan Rattanapoka and Asst. Prof. Dr. Suphot Chunwiphat.
Switch Statement in C++. Syntax switch (selector) { case L1: statements1; break; case L2: statements2; break; … default: statements_n; } Semantics: This.
Java Programming Constructs 3 MIS 3023 Business Programming Concepts II The University of Tulsa Professor: Akhilesh Bajaj All slides in this presentation.
Decision II. CSCE 1062 Outline  Boolean expressions  switch statement (section 4.8)
© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Tutorial 9 – Income Tax Calculator Application: Introducing.
Flow of Control Part 1: Selection
ITIP © Ron Poet Lecture 12 1 Finding Out About Objects.
1 COMS 261 Computer Science I Title: C++ Fundamentals Date: September 21, 2005 Lecture Number: 10.
Chapter 05 (Part III) Control Statements: Part II.
CSE 1301 Lecture 8 Conditionals & Boolean Expressions Figures from Lewis, “C# Software Solutions”, Addison Wesley Richard Gesick.
13-Nov-1513-Nov-1513-Nov-15 State Machines. What is a state machine? A state machine is a different way of thinking about computation A state machine.
CSC1201: Programming Language 2 Lecture 1 Level 2 Course Nouf Aljaffan (C) CSC 1201 Course at KSU1.
Chapter 6. else-if & switch Copyright © 2012 Pearson Education, Inc.
Chapter 3 More Flow of Control Goals: To analyze the use of Boolean expressions To analyze the use of Boolean expressions To introduce the notion of enumerated.
Catie Welsh February 7,  Grades ◦ Lab 2, Project 1 Grades are now on Blackboard 2.
1 CS161 Introduction to Computer Science Topic #8.
CSCI 171 Presentation 3. Operators Instructs C to perform some operation Assignment = Mathematical Relational Logical.
LESSON 4 Decision Control Structure. Decision Control Structures 1. if statement 2. if-else statement 3. If-else-if statement 4. nested if statement 5.
 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.
CMSC 1041 More Loops ‘for’ loops and ‘do-while’ loops.
LOOPING IN C. What would be the output of the following program main( ) { int j ; while ( j
AND Gate Inputs Output Input A (Switch) Input B (Switch) Output Y (Lamp) 0 (Open) 0 (OFF) A B Lamp.
C syntax (simplified) BNF. Program ::= [ ] Directives ::= [ ] ::= | |… ::=#include > ::=#define.
Introduction to programming in java Lecture 21 Arrays – Part 1.
More on conditional statements. Conditionals In some situations the typical if-else statements may become cumbersome Depending on the situation, there.
Switch-Case Statement. What is a switch-case?  The switch-case statement is really nothing more than a glorified.
Switch statement.
Welcome to Who Wants to be a Millionaire
Control Structures Combine individual statements into a single logical unit with one entry point and one exit point. Used to regulate the flow of execution.
Compound Condition Break , Continue Switch Statements in Java
Unit-1 Introduction to Java
LESSON 4 Decision Control Structure
Decisions Chapter 4.
LESSON 3 IO, Variables and Operators
A mechanism for deciding whether an action should be taken
Chapter 4: Making Decisions.
Control Statement Examples
Introduction to Programming
Variables, Loops, Decision Statements, etc
The switch Statement Topics Multiple Selection switch Statement
CSC215 Homework Homework 03 Due date: Oct 07, 2016.
do/while Selection Structure
Fundamental Programming
Welcome back to Software Development!
CS150 Introduction to Computer Science 1
Special Registers, Date functions, Case and User Defined Functions!!
Reading from and Writing to Files Part 2
Range check 範圍檢查: int age; int score; int month; 1-12
Presentation transcript:

char ch; ch ‘L’‘X’‘V’‘I’ As in Roman numerals Want to give each a value, n say switch (ch) { case ‘I’:n = 1; break; case ‘V’:n = 5; break; … default:cout << “error”; break; } ch n = 1n = 5n = 10n = 50 ‘I’ ‘V’‘X’ ‘L’

If letter is ‘X’, ‘L’, ‘M’, ‘S’ switch (letter) { case ‘X’: statement 1; break; case ‘L’: case ‘M’: statement 2; break; case ‘S’: statement 3; break; default:statement 4; } statement 5;

Problem: Given as input 3 integers representing a date (MM/DD/YYYY) output the date of the next day. int day, month, year; 2/17/2001  2/18/2001 1/31/2001  2/1/ /31/2001  1/1/2002 2/28/2001  3/1/2001 Need days_in_month

switch (month) { case 1: case 3: case 5: case 7: case 8: case 10: case 12: days_in_month = 31; break; case 4: case 6: case 9: case 11: days_in_month = 30; break; case 2:if () days_in_month = 28; else days_in_month = 29; break; }

switch (month) { case 1: case 3: … case 12: days_in_month = 31; break; … } If (day == days_in_month) { day = 1; if (month == 12) { month = 1; year++; } else month++; } else day++;