Computer Science: A Structured Programming Approach Using C1 5-3 Multiway Selection In addition to two-way selection, most programming languages provide.

Slides:



Advertisements
Similar presentations
Topics discussed in this section:
Advertisements

© Janice Regan, CMPT 128, Jan CMPT 128: Introduction to Computing Science for Engineering Students Control Structures Nested ifs, switch statements.
Computer Science: A Structured Programming Approach Using C Converting File Type A rather common but somewhat trivial problem is to convert a text.
C++ Programming: From Problem Analysis to Program Design, Third Edition Chapter 4: Control Structures I (Selection)
true (any other value but zero) false (zero) expression Statement 2
Chapter 4: Control Structures: Selection
C++ for Engineers and Scientists Third Edition
Visual C++ Programming: Concepts and Projects
© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Tutorial 9 – Income Tax Calculator Application: Introducing.
C How to Program, 6/e Summary © by Pearson Education, Inc. All Rights Reserved.
Fundamentals of Python: From First Programs Through Data Structures
Fundamentals of Python: First Programs
Java Programming, 3e Concepts and Techniques Chapter 3 Section 62 – Manipulating Data Using Methods – Day 1.
Computer Science: A Structured Programming Approach Using C1 Objectives ❏ To understand design concepts for fixed-length and variable- length strings ❏
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Structural Program Development: If, If-Else Outline.
1 Chapter 4: Selection Structures. In this chapter, you will learn about: – Selection criteria – The if-else statement – Nested if statements – The switch.
Chapter 4: Control Structures I (Selection). Objectives In this chapter, you will: – Learn about control structures – Examine relational operators – Discover.
Chapter 4: Control Structures I
Chapter 4: Control Structures I (Selection). Objectives In this chapter, you will: – Learn about control structures – Examine relational and logical operators.
Conditional Statements For computer to make decisions, must be able to test CONDITIONS IF it is raining THEN I will not go outside IF Count is not zero.
Computer Science: A Structured Programming Approach Using C1 Objectives ❏ To be able to list and describe the six expression categories ❏ To understand.
Computer Science: A Structured Programming Approach Using C1 Objectives ❏ To understand how decisions are made in a computer ❏ To understand the logical.
Control Structures 1. Control Structures Java Programming: From Problem Analysis to Program Design, D.S. Malik 2.
Chapter 4: Control Structures SELECTION STATEMENTS.
Copyright © 2012 Pearson Addison-Wesley. All rights reserved. CIS_IS20_CSLO 1. Explain computer programming concepts CSLO1.6. Explain the purpose of general.
1 Objectives ❏ To understand how decisions are made in a computer ❏ To understand the logical operators: and, or, and not ❏ To understand how a C program.
Dale Roberts 1 Program Control - Algorithms Department of Computer and Information Science, School of Science, IUPUI CSCI N305.
Refer to Ivor Horton’s Beginning ANSI C++ The Complete Language, 3rd Ed. APress Media, LLC. Choices and Decisions if statement if-else statement Relational.
Programming 1 DCT 1033 Control Structures I (Selection) if selection statement If..else double selection statement Switch multiple selection statement.
Computer Science: A Structured Programming Approach Using C1 5-2 Two-Way Selection The decision is described to the computer as a conditional statement.
Computer Science: A Structured Programming Approach Using C1 5-2 Two-Way Selection The decision is described to the computer as a conditional statement.
Selection-making Decisions Selection allows you to choose between two or more possible program flow --- it lets you make decisions in your program. Examples.
Computer Science: A Structured Programming Approach Using C1 2-7 Input/Output Although our programs have implicitly shown how to print messages, we have.
1 CS161 Introduction to Computer Science Topic #8.
Chapter 4: Control Structures I (Selection). Objectives In this chapter, you will: – Learn about control structures – Examine relational and logical operators.
Computer Science: A Structured Programming Approach Using C1 6-6 Loop Examples This section contains several short examples of loop applications. Each.
CONTROL STRUCTURE. 2 CHAPTER OBJECTIVES  Learn about control structures.  Examine relational and logical operators.  Explore how to form and evaluate.
CPS120: Introduction to Computer Science Decision Making in Programs.
Computer Science: A Structured Programming Approach Using C1 5-5 Incremental Development Part II In Chapter 4, we introduced the concept of incremental.
Computer Science: A Structured Programming Approach Using C1 Objectives ❏ To understand how decisions are made in a computer ❏ To understand the logical.
C++ for Engineers and Scientists Second Edition Chapter 4 Selection Structures.
Topics discussed in this section:
Selection—Making Decisions
Test Review Computer Science History
The Selection Structure
Topics discussed in this section:
Topics discussed in this section:
Topics discussed in this section:
Topics discussed in this section:
Topics discussed in this section:
Decision Making.
IF if (condition) { Process… }
3-3 Side Effects A side effect is an action that results from the evaluation of an expression. For example, in an assignment, C first evaluates the expression.
Regular Grammar.
Unit 1: Introduction Lesson 1: PArts of a java program
3-3 Side Effects A side effect is an action that results from the evaluation of an expression. For example, in an assignment, C first evaluates the expression.
Topics discussed in this section:
Topics discussed in this section:
Topics discussed in this section:
MatLab – Palm Chapter 4, Part 2 The if and switch structure
MatLab – Palm Chapter 4, Part 2 The if and switch structure
Topics discussed in this section:
Topics discussed in this section:
Section 3.7 Switching Circuits
Selection—Making Decisions
Topics discussed in this section:
Topics discussed in this section:
Topics discussed in this section:
Structural Program Development: If, If-Else
Presentation transcript:

Computer Science: A Structured Programming Approach Using C1 5-3 Multiway Selection In addition to two-way selection, most programming languages provide another selection concept known as multiway selection. Multiway selection chooses among several alternatives. C has two different ways to implement multiway selection: the switch statement and else-if construct. The switch Statement The else-if Topics discussed in this section:

Computer Science: A Structured Programming Approach Using C2 FIGURE 5-19 switch Decision Logic

Computer Science: A Structured Programming Approach Using C3 FIGURE 5-20 switch Statement Syntax

Computer Science: A Structured Programming Approach Using C4 FIGURE 5-21 switch Flow

Computer Science: A Structured Programming Approach Using C5 PROGRAM 5-6Demonstrate the switch Statement

Computer Science: A Structured Programming Approach Using C6 FIGURE 5-22 switch Results

Computer Science: A Structured Programming Approach Using C7 FIGURE 5-23 A switch with break Statements

Computer Science: A Structured Programming Approach Using C8 PROGRAM 5-7Multivalued case Statements

Computer Science: A Structured Programming Approach Using C9 Table 5-5Summary of switch Statement Rules

Computer Science: A Structured Programming Approach Using C10 PROGRAM 5-8Student Grading

Computer Science: A Structured Programming Approach Using C11 PROGRAM 5-8Student Grading

Computer Science: A Structured Programming Approach Using C12 PROGRAM 5-8Student Grading

Computer Science: A Structured Programming Approach Using C13 FIGURE 5-24 The else-if Logic Design for Program 5-9

Computer Science: A Structured Programming Approach Using C14 The else-if is an artificial C construct that is only used when 1. The selection variable is not an integral, and 2. The same variable is being tested in the expressions. Note

Computer Science: A Structured Programming Approach Using C15 PROGRAM 5-9Convert Score to Grade

Computer Science: A Structured Programming Approach Using C16 PROGRAM 5-9Convert Score to Grade

Computer Science: A Structured Programming Approach Using C17 PROGRAM 5-9Convert Score to Grade

Computer Science: A Structured Programming Approach Using C More Standard Functions One of the assets of the C language is its rich set of standard functions that make programming much easier. For example, C99 has two parallel but separate header files for manipulating characters: ctype.h and wctype.h. Standard Characters Functions A Classification Program Handling Major Errors Topics discussed in this section:

Computer Science: A Structured Programming Approach Using C19 FIGURE 5-25 Classifications of the Character Type

Computer Science: A Structured Programming Approach Using C20 Table 5-6Classifying Functions continued

Computer Science: A Structured Programming Approach Using C21 Table 5-6Classifying Functions (continued)

Computer Science: A Structured Programming Approach Using C22 Table 5-7Conversion Functions

Computer Science: A Structured Programming Approach Using C23 PROGRAM 5-10Demonstrate Classification Functions

Computer Science: A Structured Programming Approach Using C24 PROGRAM 5-10Demonstrate Classification Functions