Chapter five selected exercises with solutions. Exercises 5.1.

Slides:



Advertisements
Similar presentations
Decision Structures - If / Else If / Else. Decisions Often we need to make decisions based on information that we receive. Often we need to make decisions.
Advertisements

Chapter 4 - Control Statements
Chapter 4 Decision Making Lecture Slides to Accompany An Introduction to Computer Science Using Java (2nd Edition) by S.N. Kamin, D. Mickunas, E. Reingold.
CSE 1301 Lecture 5B Conditionals & Boolean Expressions Figures from Lewis, “C# Software Solutions”, Addison Wesley Briana B. Morrison.
Chapter 5 Decisions. Outline and Objectives Relational and Logical Operators If Blocks Select Case Blocks.
General Computer Science for Engineers CISC 106 Lecture 21 Dr. John Cavazos Computer and Information Sciences 04/10/2009.
Conditional Statements If these were easy then everyone would them!
C++ Programming: From Problem Analysis to Program Design, Third Edition Chapter 4: Control Structures I (Selection)
Chapter 6 - Repetition. Introduction u Many applications require certain operations to be carried out more than once. Such situations require repetition.
COMP 14 Introduction to Programming Miguel A. Otaduy May 18, 2004.
Chapter 5: Repetition Statements. In this chapter, you will learn about: Basic loop structures while loops Interactive while loops for loops Loop programming.
Java Programming: From Problem Analysis to Program Design, 4e Chapter 4 Control Structures I: Selection.
C++ for Engineers and Scientists Third Edition
The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL Adrian Ilie COMP 14 Introduction to Programming Adrian Ilie June 30, 2005.
Review for Exam 2 School of Business Eastern Illinois University © Abdou Illia, Spring 2003 (Week 10, Friday 3/21/2003) - IF Blocks - Do Loops - Select.
Chapter 3 Making Decisions
Object-Oriented Programming Using C++ Third Edition Chapter 3 Making Decisions.
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 J ava P rogramming: From Problem Analysis to Program Design, From Problem Analysis to Program Design, Second Edition Second.
Lecture Set 5 Control Structures Part A - Decisions Structures.
Lesson 6-3B Objective: Solve inequalities using more than one step…continued.
Flow of Control Part 1: Selection
Programming Logic and Design Sixth Edition Chapter 5 Looping.
An Object-Oriented Approach to Programming Logic and Design Fourth Edition Chapter 4 Looping.
 Learn about control structures  Examine relational and logical operators  Explore how to form and evaluate logical (Boolean) expressions  Learn how.
If Statements If statements: allow the computer to make a decision Syntax: if (some condition) { then do this; } else { then do that; } no semicolons on.
CSE 1301 Lecture 8 Conditionals & Boolean Expressions Figures from Lewis, “C# Software Solutions”, Addison Wesley Richard Gesick.
Liang, Introduction to C++ Programming, (c) 2007 Pearson Education, Inc. All rights reserved X1 Chapter 3 Control Statements.
Programming 1 DCT 1033 Control Structures I (Selection) if selection statement If..else double selection statement Switch multiple selection statement.
Java Programming: From Problem Analysis to Program Design, 3e Chapter 4 Control Structures I: Selection.
ICT Introduction to Programming Chapter 4 – Control Structures I.
Review for Final (Part 2) School of Business Eastern Illinois University © Abdou Illia, Spring 2003 (Week 15, Friday 5/2/2003)
Data And Variables Chapter Names vs. Values Michael Jordan name (the letter sequence used to refer to something) value (the thing itself)
1 Agenda If Statement True/False Logical Operators Nested If / Switch Exercises & Misc.
EGR 115 Introduction to Computing for Engineers Branching & Program Design – Part 3 Friday 03 Oct 2014 EGR 115 Introduction to Computing for Engineers.
Chapter 6 - Repetition. while Loop u Simplest loop u Two parts: test expression and loop body u Pre-tested loop –Execute loop body if test true –Bypass.
USING CONDITIONAL CODE AMIR KHANZADA. Conditional Statement  Conditional statements are the set of commands used to perform different actions based on.
CS Class 04 Topics  Selection statement – IF  Expressions  More practice writing simple C++ programs Announcements  Read pages for next.
JAVASCRIPT A quick review. True False ■The DOM is a standardized way of referring to parts of a Web page. ■TRUE ■In the DOM, attributes have their own.
C++ Programming: From Problem Analysis to Program Design, Fifth Edition Chapter 2: Control Structures (Selection & Repetition)
Identities, Contradictions and Conditional Equations.
Select Case Blocks School of Business Eastern Illinois University © Abdou Illia, Spring 2003 (Week 8, Monday 3/03/2003)
C++ for Engineers and Scientists Second Edition Chapter 4 Selection Structures.
Engineering H192 - Computer Programming Gateway Engineering Education Coalition Lect 10P. 1Winter Quarter Repetition Structures Lecture 10.
Control Structures I Chapter 3
Chapter 3 Control Statements
COMP 14 Introduction to Programming
CS 115 Lecture Flags.
Chapter 4: Control Structures I
Lecture 7: Repeating a Known Number of Times
CHAPTER 4 Selection CSEG1003 Introduction to Computing
Chapter 3 Control Statements Lecturer: Mrs Rohani Hassan
SELECTION STATEMENTS (1)
CHAPTER FIVE Decision Structures.
And the text with form..
Chapter 4: Control Structures I
Conditions and Ifs BIS1523 – Lecture 8.
CS 115 Lecture Flags.
Chapter 5 - Visual Basic Schneider
Chapter 5: Control Structure
Chapter 4: Control Structures I (Selection)
CHAPTER 6: Control Flow Tools (for and while loops)
Chapter 5 Decisions.
The Selection Structure
CHAPTER 3 Logic.
Data Types and Maths Programming Guides.
Agenda Warmup Review Finish 1.2 Assignments Lesson 1.3 (If Statements)
Selection Control Structure
Agenda Warmup Review Finish 1.2 Assignments Lesson 1.3 (If Statements)
Presentation transcript:

Chapter five selected exercises with solutions

Exercises 5.1

1. True 2. False 3. True 4. False 5. True 6. False 7. True 8. True 9. False 10. False 11. False 12. True 13. True 14. True 15. True 16. True 17. False 18. True 19. False 20. True 21. False 22. False 23. True 24. True

Exercises 5.1

25. Equivalent 26. Not Equivalent 27. Not Equivalent 28. Equivalent 29. Equivalent 30. Not Equivalent 31. Not Equivalent 32. Not equivalent 33. Equivalent 34. Not Equivalent

Exercises a <= b 36. (a <> b) And (a <> d) 37. (a >= b) Or (c = d) 38. (a = b) Or (a > b) 39. (a = "") Or (a >= b) Or (Len(a) >= 5)

Exercises 5.2

1. Less than ten 2. Student 3. tomorrow is another day. 4. Your change contains 3 dollars Cost of call: $ To be or not to be. 9. The number of vowels is Hi

Exercises positive 12. You are eligible to vote in 2 years 13. Incorrect condition. Should be If (1 < num) And (num < 3) Then 14. The variable num is missing from the second part of the condition.. Should be If (num > 5) And (num < 9) Then 15. no Then in second line 16. Incorrect condition. Should be If (major = "Business") Or (major = "Computer Science") Then Also, the variable major was never assigned a value. 17. Comparing numeric and string data 18. Faulty logic. If the user enters "off", the switch changes to "on" and then back to "off". 19. Incorrect condition. Should be If (j = 4) Or (k = 4) Then 20. Missing End If for outermost If block

Exercises a = If (answer = "y") Or (answer = "Y") Then picOutput.Print "YES" End If 'or If UCase(answer) = "Y" Then picOutput.Print "YES" End If 23. If j = 7 Then b = 1 Else b = 2 End If 24. If (a < b) And (b < c) Then picOutput.Print b; "is between"; a; "and"; c End If

Exercises message = "Is Alaska bigger than Texas and California combined?" answer = InputBox(message) If UCase(Left(answer, 1)) = "Y" Then picOutput.Print "Correct" Else picOutput.Print "Wrong" End If 26. message = "How tall (in feet) is the Statue of Liberty?" feet = Val(InputBox(message)) If (feet > 141) And (feet < 161) Then picOutput.Print "Close" Else picOutput.Print "Nope" End If picOutput.Print "The Statue of Liberty is feet" picOutput.Print "from base to torch."

Exercises 5.3

1. The price is $3.75 The price is $ case 2 case 1 case 3 3. Mesozoic Era Paleozoic Era ? 4. Sorry, Work on the ENIAC began in June Correct No, By then IBM had built a stored-program computer. 5. Nope. He worked with the developer, von Neumann, on the ENIAC. Correct.

Exercises 5.3

6. The equation has no real solutions. The equation has two real solutions. The equation has exactly one solution. 7. The less things change, the more they remain the same. Less is more. Time keeps everything from happening at once. 8. Hi Hi 9.Should have a Case clause. 10. Both Case statements are invalid. The first one should be 3 To 10. The second one should have a comma instead of a semicolon. 11. Case a = "Bob" should be Case "Bob"

Exercises 5.3

12. In Case clause, h should be "h" 13. Error in second Case clause. 14. First Case is executed every time, no matter what the value of num is. 15. Logical error: >= "Peach" should be >= "PEACH" Syntax error: "ORANGE TO PEACH" should be "ORANGE" To "PEACH" 16. Invalid second Case. Should be Case To Valid 18. Valid 19. Invalid 20. Invalid 21. Valid 22. Invalid

Exercises 5.3

23. Select Case a Case 1 picOutput.Print "one" Case Is > 5 picOutput.Print "two" End Select 24. Select Case a Case 1 picOutput.Print "lambs" picOutput.Print "eat“ Case Is <=3 picOutput.Print "eat" Case 5, Is > 7 picOutput.Print "ivy" End Select

Exercises Select Case a Case 2 picOutput.Print "yes" Case Is < 5 picOutput.Print "no" End Select 26. Select Case a Case 1, 3 a = 2 Case 2 a = 3 End Select