Selection and Testing Shirley Moore CS 1401 Spring 2013 February 21 and 26, 2013 1.

Slides:



Advertisements
Similar presentations
CSCI 51 Introduction to Programming Dr. Joshua Stough February 10, 2009.
Advertisements

The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL Adrian Ilie COMP 14 Introduction to Programming Adrian Ilie July 5, 2005.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved Chapter 3 Control Statements.
Introduction to Java Programming, 4E Y. Daniel Liang.
Liang, Introduction to Java Programming, Seventh Edition, (c) 2009 Pearson Education, Inc. All rights reserved Chapter 3 Selections.
COMP 14 Introduction to Programming Miguel A. Otaduy May 20, 2004.
1 Lab Session-6 CSIT-121 Spring 2005 Structured Choice The do~While Loop Lab Exercises.
The If/Else Statement, Boolean Flags, and Menus Page 180
Flow of Control Loops – Chapter 3.2. Java Loop Statements: Outline the while Statement the do-while Statement the for Statement.
C++ for Engineers and Scientists Third Edition
Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved Control Statements.
1 CS 105 Lecture 5 Logical Operators; Switch Statement Wed, Feb 16, 2011, 5:11 pm.
COMP 110 Introduction to Programming Mr. Joshua Stough September 19, 2007.
Quiz 1 Exam 1 Next Week. Nested if Statements if (myGrade >= 80) if (myGrade >= 90) cout
If statements Chapter 3. Selection Want to be able to do a statement sometimes, but not others if it is raining, wear a raincoat. Start first with how.
COMP 110 Introduction to Programming Mr. Joshua Stough September 24, 2007.
Section 3 - Selection and Repetition Constructs. Control Structures 1. Sequence 2. Selection 3. Repetition.
CSC 1051 M.A. Papalaskari, Villanova University Repetition CSC 1051 – Data Structures and Algorithms I Dr. Mary-Angela Papalaskari Department of Computing.
Java Programming Constructs 1 MIS 3023 Business Programming Concepts II The University of Tulsa Professor: Akhilesh Bajaj All slides in this presentation.
CONTROL STATEMENTS IF-ELSE, SWITCH- CASE Introduction to Computer Science I - COMP 1005, 1405 Instructor : Behnam Hajian
1 Chapter 4: Selection Structures. In this chapter, you will learn about: – Selection criteria – The if-else statement – Nested if statements – The switch.
COMP 110: Introduction to Programming Tyler Johnson Feb 2, 2009 MWF 11:00AM-12:15PM Sitterson 014.
More on Input Output Input Stream : A sequence of characters from an input device (like the keyboard) to the computer (the program running). Output Stream.
Liang, Introduction to Programming with C++, Second Edition, (c) 2010 Pearson Education, Inc. All rights reserved Chapter 3 Selections.
Dr. Yang, QingXiong (with slides borrowed from Dr. Yuen, Joe) LT3: Conditional Statements CS2311 Computer Programming.
Selection (if-then-else) Programming Has 3 Types of Control: Sequential (normal): Control of Execution Proceeds One after the Other Selection (if-then-else):
Floating Point Numbers Expressions Scanner Input Algorithms to Programs Shirley Moore CS 1401 Spring 2013 February 12, 2013.
Your First Data Structure: 1D Array Shirley Moore CS 1401 Spring 2013 cs1401spring2013.pbworks.com April 9-11, 2013.
Chapter 3 Selections Liang, Introduction to Java Programming, Seventh Edition, (c) 2009 Pearson Education, Inc. All rights reserved
PROBLEM SOLVING & ALGORITHMS CHAPTER 5: CONTROL STRUCTURES - SELECTION.
CHAPTER 8 CONTROL STRUCTURES Prepared by: Lec. Ghader R. Kurdi.
Number Representation, Data Types and Elementary Programming Shirley Moore CS 1401 February 5-7, 2013.
1 COMS 261 Computer Science I Title: C++ Fundamentals Date: September 21, 2005 Lecture Number: 10.
1 Example: Solution of Quadratic Equations We want to solve for real values of x, for given values of a, b, and c. The value of x can be determined from.
CS Class 05 Topics  Selection: switch statement Announcements  Read pages 74-83, ,
Chapter 7 Selection Dept of Computer Engineering Khon Kaen University.
Liang, Introduction to C++ Programming, (c) 2007 Pearson Education, Inc. All rights reserved X1 Chapter 3 Control Statements.
Control Flow Computer Engineering Department Java Course Asst. Prof. Dr. Ahmet Sayar Kocaeli University - Fall 2014.
Introduction to Methods Shirley Moore CS 1401 Spring 2013 cs1401spring2013.pbworks.com April 1, 2013.
Control statements Mostafa Abdallah
Iterative Structures (Loops) CS 1401 Spring 2013 Shirley Moore, Instructor February 28, 2013.
Programming Fundamentals by Dr. Nadia Y. Yousif1 Control Structures (Selections) Topics to cover here: Selection statements in the algorithmic language:
COMP Loop Statements Yi Hong May 21, 2015.
CHAPTER#3 STRUCTURED PROGRAM DEVELOPMENT IN C++ 2 nd semester King Saud University College of Applied studies and Community Service Csc 1101.
Chapter 3. Control Structure C++ Programing. Conditional structure C++ programming language provides following types of decision making statements. Click.
CS Class 04 Topics  Selection statement – IF  Expressions  More practice writing simple C++ programs Announcements  Read pages for next.
Program Control: Selection Subject: T0016 – ALGORITHM AND PROGRAMMING Year: 2013.
4 - Conditional Control Structures CHAPTER 4. Introduction A Program is usually not limited to a linear sequence of instructions. In real life, a programme.
CHAPTER#3 STRUCTURED PROGRAM DEVELOPMENT IN C 1 A.AlOsaimi King Saud University College of Applied studies and Community Service Csc 1101.
Selection (if-then-else) Programming Has 3 Types of Control: Sequential (normal): Control of Execution Proceeds One after the Other Selection (if-then-else):
Quiz 1 Exam 1 Next Monday. Nested if Statements if (myGrade >= 80) if (myGrade >= 90) System.out.println(“You have an A!” ); else System.out.println(“You.
Control Structures- Decisions. Smart Computers Computer programs can be written to make computers seem smart Making computers smart is based on decision.
Lecture 3 Selection Statements
Chapter 3 Selection Statements
Chapter 3 Control Statements
Selection—Making Decisions
C++ Basic Syntax – Homework Exercises
Chapter 5: Control Structure
Chapter 3 Control Statements Lecturer: Mrs Rohani Hassan
SELECTION STATEMENTS (1)
Compound Assignment Operators in C++
Selection (if-then-else)
SELECTION STATEMENTS (2)
CS2011 Introduction to Programming I Selections (II)
SELECTIONS STATEMENTS
More on conditional statements
Announcements Lab 3 was due today Assignment 2 due next Wednesday
Flow of Control Flow of control is the order in which a program performs actions. Up to this point, the order has been sequential. A branching statement.
Lecture 9: Implementing Complex Logic
Presentation transcript:

Selection and Testing Shirley Moore CS 1401 Spring 2013 February 21 and 26,

Agenda Feb 21 – Announcements (5-10 min) – Concepts of if statements and Boolean expressions (20 min) – Checkpoint questions (30 min) – Test plans (15 min) – Wrapup (5 min) Feb 26 – Announcements (5 min) – Quiz 3 (15 min) – Programming exercises 3.1, 3.8 (20 min) – Switch statement (10 min) – Testing video clips and discussion (20 min) – Research projects ( 5 min) – Wrapup, assignment for next time (5 min) 2

Announcements Seminar today at 1:30: Eduard Dragut, CyberShare Viz Lab, Classroom Building 4 th floor Exam 1 IPO Algorithm/Programming retest Unit 2 Outcomes and Schedule New due dates for Lab 3 and Lab 4 3

Checking for Valid Program Input Why should you do it? What is the logic? – Example: Program to input base radius and length of a cylinder and compute the volume How can we implement the logic? – If statement condition(s) to test – relational operators, =, ==, != – logical operators &&, ||, ! actions to take depending on value of condition 4

Boolean Data Type and Expressions Can have values true and false Examples (can type in Dr Java Interactions)  3 < 5  -3 < -5  ‘a’ < ‘b’  (3 10)  double radius = -0.5;  radius >= 0.0  boolean checkRadius = (radius >= 0.0);  checkRadius 5

If Statement Syntax if (boolean-expression) { statement(s) } if (boolean-expression) { statements(s) // for the true case } else { statement(s) // for the false case } Can be nested Class exercise: Use if-else to add input checking to cylinder problem 6

CheckPoint Questions p. 92, 3.8 if ( x > 2 ) { if (y > 2) { z = x + y; System.out.println(“z is “ + z); } } else { System.out.println(“x is “ + x); } Test inputs o x = 3, y = 2 o x = 3, y = 4 o x = 2, y = 2 7

Checkpoint Questions (cont.) p. 92, 3.9 if (x > 2) if (y > 2) { z = x + y; System.out.println(“z is “ + z); } else System.out.println(“x is “ + x); Test inputs o x = 2, y = 3 o x = 3, y = 2 o x = 3, y = 3 8

Checkpoint Questions (cont.) p. 92, 3.10 if (score >= 60.0) grade = ‘D’; else if (score >= 70.0) grade = ‘C’; else if (score >= 80.0) grade = ‘B’; else if (score >= 90.0) grade = ‘A’; else grade = ‘F’; What do you think was the intent of the above code? Does it accomplish this intent? If not, how can you fix it? 9

Programming Exercises p. 121, 3.1 Write a program that inputs real values a, b, and c for the coefficients of a quadratic equation and outputs the result based on the discriminant. If the discriminant is positive, output two roots. If the discriminant is 0, output one root. If the discriminant is negative, output that the equation has no real roots. 10

Programming Exercises (cont.) p. 123, exercise 3.8 Write a program that inputs three integers into variables num1, num2, num3 and outputs the integers sorted from least to greatest. 11

Switch Statement Syntax: switch (expression) { case constant-1: statements-1 break; case constant-2: statements-2 break;.. // (more cases). case constant-N: statements-N break; default: // optional default case statements-(N+1) } // end of switch statement Discuss semantics 12

In-class Exercise The commission rate for a sale at a shop varies depending on the sales class of the item, as given in the table below. Any other sales class besides those listed has zero commission. Write a program that inputs a price and sales class for an item and outputs the commission that the sales person will earn for selling that item. Use a switch statement to select the commission rate. Write a step-by-step algorithm before writing the ajava code. 13 Sales Class Commission Rate 12 % 23.5% 25% 46%

Testing Your Program Developing a test plan Video clips – The Machine That Changed the World, Part 5 42:00-52:00 – Tacoma Bridge disaster dge10.htm 14

Research mini-Projects History of computing Using programming to teach math Software reliability More topics to come (feel free to suggest topics in which you are interested!) 15

Assignment for Thursday, Feb 28 Do Chapter 3 end-of-chapter programming exercises 3.19, 3.20, 3.22, Follow steps discussed in class. Hand-write neatly or print out to turn in and/or discuss at beginning of class. Read Chapter 4 sections Write down any questions you have. Write answers to CheckPoint questions. 16