Tue Nov 11 & Thu Nov 13 : complete Ch 5 Thu Nov 13/Fri Nov 14 : lab exercises Ch 5. Tue Nov 18 : TERM TEST #3 (Ch.4,5)
|
|
- Agnes Fisher
- 5 years ago
- Views:
Transcription
1 CSE1710 Click to edit Master Week text 10, styles Lecture 18 Second level Third level Fourth level Fifth level Fall 2013! Tuesday, Nov 11, Overview Tue Nov 11 & Thu Nov 13 : complete Ch 5 Thu Nov 13/Fri Nov 14 : lab exercises Ch 5 Tue Nov 18 : TERM TEST #3 (Ch.4,5) Thu Nov 20/Fri Nov 21 : Labtest #3 (Ch 4,5) 3 lectures allotted for Ch 6 2 lab sessions allotted for Ch 6 2 1
2 Forms of Iteration the "enhanced" for loop the "boolean" for loop 3 RasterImage services how to create instances? lab exercises demonstrated several different ways default constructor constructor with 2 int parameters constructor with single string parameter (switch display over to Eclipse, to demonstrate the different constructors) 4 2
3 Iterating over the pixels in a RasterImage instance (3 methods) 1. the RasterImage object itself is a collection this means we can use it in an enhanced for loop 2. use the service for accessing the collection of pixels, namely getpixelarray() this provides us with an array data structure; we can iterate over the elements in two ways using an enhanced for loop access the elements by index; iterate over all the indices 5 Iterating over the pixels in a RasterImage instance (3 methods) 3. use the service for accessing a particular pixel, by column and row indices, namely getpixel(int, int) we can access each pixel by column and row position iterate over all columns and row indices using two boolean for loops, one nested inside the other 6 3
4 The Enhanced For Loop!! a collection is simply a bunch of elements, possibly in a particular order, but not necessarily"! the elements must have a type (e.g., Pixel)"! there are certain sub categories for collections"! a set is a collection in which duplicates are not permitted"! a list is a collection in which the elements are ordered"! an array is a specific kind of list " collection, set, list ": "abstractions, not specific to Java" array " " ": "a Java programming element " 7 The Enhanced For Loop!! for ( Type-of-Element e : Identifier-of-Collection ) // here is the body of the loop This is called an enhanced for loop 8 8" 4
5 The Enhanced For Loop! It just so happens that a RasterImage object can function as a collection of Pixel elements for (Pixel p : myimage) // here is the body of the loop 9 9" The Boolean For Loop! for (; boolean expression ;) // here is the body of the loop 10 10" 5
6 The Boolean For Loop! for ( initial ; boolean expression ; bottom ) // here is the body of the loop 11 11" The Boolean For Loop What do we need in order to use the boolean for loop?" let's start with the array version" RasterImage myimage = Pixel[] thepixels = myimage.getpixelarray(); now we need a way to visit each pixel in the array once and only once 12 6
7 Some arbitrary element in an array RasterImage myimage = Pixel[] pixels = myimage.getpixelarray(); Pixel p = thepixels[60]; this retrieves the 61 tst element in the array! What happens it there is no 61 st element?! 13 The first and final indices for an array RasterImage myimage = Pixel[] pixels = myimage.getpixelarray(); int firstpixelindex = 0; int lastpixelindex = thepixels.length-1; length is a special final attribute of arrays in Java! WHY minus 1?! 14 7
8 The first and final elements of an array RasterImage myimage = Pixel[] pixels = myimage.getpixelarray(); int firstpixelindex = 0; int lastpixelindex = thepixels.length-1; Pixel pfirst = thepixels[0]; // the first element Pixel plast = thepixels[lastpixelindex]; // the final //element 15 java.lang.arrayindexoutofboundsexception Pixel[] thepixels = mypict.getpixelarray(); int firstpixelindex = 0; int lastpixelindex = thepixels.length-1; Pixel p1 = thepixels[firstpixelindex -1]; // runtime error Pixel p2 = thepixels[lastpixelindex+1]; // runtime error 16 8
9 Exercise #1 change the colour of each pixel to green RasterImage myimage = Pixel[] pixels = myimage.getpixelarray(); int firstpixelindex = 0; int lastpixelindex = thepixels.length-1; thepixels[firstpixelindex].setcolor(color.green); // thepixels[lastpixelindex].setcolor(color.green); 17 Exercise #1 (partial solution) thepixels[firstpixelindex].setcolor(color.green); thepixels[firstpixelindex+1].setcolor(color.green); thepixels[firstpixelindex+2].setcolor(color.green); thepixels[firstpixelindex+3].setcolor(color.green); // keep going until firstpixelindex+i=lastpixelindex so how could we automate this? 18 9
10 Exercise #1 (solution) Pixel[] thepixels = mypict.getpixels(); int firstpixelindex = 0; int lastpixelindex = thepixels.length-1; int currentindex = firstpixelindex; boolean iswithinbounds = currentindex <= lastpixelindex; for( ; iswithinbounds ; ) Pixel currentpixel = thepixels[currentindex]; currentpixel.setcolor(color.red); mypict.repaint(); currentindex++ iswithinbounds = currentindex <= lastpixelindex; 19 Exercise #1 (solution) Pixel[] thepixels = mypict.getpixels(); int firstpixelindex = 0; int lastpixelindex = thepixels.length-1; int currentindex = firstpixelindex; for( ; currentindex <= lastpixelindex; ) Pixel currentpixel = thepixels[currentindex]; currentpixel.setcolor(color.red); mypict.repaint(); currentindex
11 Exercise #1 (solution) Pixel[] thepixels = mypict.getpixels(); int firstpixelindex = 0; int lastpixelindex = thepixels.length-1; for(int currentindex = firstpixelindex; currentindex <= lastpixelindex; ) Pixel currentpixel = thepixels[currentindex]; currentpixel.setcolor(color.red); mypict.repaint(); currentindex++ 21 Exercise #1 (solution) Pixel[] thepixels = mypict.getpixels(); int firstpixelindex = 0; int lastpixelindex = thepixels.length-1; for(int currentindex = firstpixelindex; currentindex <= lastpixelindex; currentindex++) Pixel currentpixel = thepixels[currentindex]; currentpixel.setcolor(color.red); mypict.repaint(); 22 11
12 Exercise #2 change the colour of each pixel to green, using getpixel(int,int) RasterImage myimage = int finalcolindex = int finalrowindex = myimage.getpixel(0,0).setcolor(color.green); // myimage.getpixel(finalcolindex,finalrowindex).setcolor(color.green); 23 Exercise #2 (partial solution) Pixel[] thepixels = myimage.getpixels(); int finalcolindex = myimage.getwidth(); int finalrowindex = myimage.getheight(); for(int currentcolindex = 0; this will iterate over all of the currentcolindex <= finalcolindex; columns, and will change the currentcolindex++) first pixel of each column Pixel currentpixel = myimage(currentcolindex, 0); currentpixel.setcolor(color.green); mypict.repaint(); 24 12
13 Exercise #2 (solution) Pixel[] thepixels = myimage.getpixels(); int finalcolindex = myimage.getwidth(); int finalrowindex = myimage.getheight(); for(int currentcolindex = 0; currentcolindex <= finalcolindex; currentcolindex++) for(int currentrowindex = 0; currentrowindex <= finalrowindex; currentrowindex++) Pixel currentpixel = myimage(currentcolindex, currentrowindex); currentpixel.setcolor(color.green); mypict.repaint(); Flow of Control! I t e r a t i o n loop body S B 1 B 2 X 26 13
14 5.2.2 The for statement! Flow: Syntax : false 27 S for X initial condition body bottom condition true Statement -S for (initial; condition; b ottom) body; Statement -X Algorithm: 1. Start the for scope 2. Execute initial 3. If condition is false go to 9 4. Start the body scope 5. Execute the body 6. End the body scope 7. Execute bottom 8. If condition is true go to 4 9. End the for scope Example! final int MAX = 10; final double SQUARE_ROOT = 0.5; for (int i = 0; i < MAX; i = i + 1) double sqrt = Math.pow(i, SQUARE_ROOT); output.print(i); output.print("\t"); // tab output.println(sqrt); 28 14
15 for (initial; condition; bottom)! for (int i = 0; i < MAX; i = i + 1)... int i; for (; i < MAX; i = i + 1) for (initial; condition; bottom)! Can it be omitted?! Can it be set to the literal true?! What if it were false at the beginning?! Is it monitored throughout the body?! 30 15
16 for (initial; condition; bottom)! Can it be any statement?! Will the loop be infinite if it is omitted?! Flow of Control What is control; how does it flow? Sequence versus Selection Flow (a) (b) S 1 S 2 A 1 B 1 C 1 X S n 32 16
17 5.1.2 The if Statement S Statement -S A 1 true false if ( condition ) Statement -A1 A 2 Statement -A2 X Statement -X 33 Example Write a fragment that reads an int and outputs its abs value without using Math.abs
18 Example Write a fragment that reads an int and outputs its abs value without using Math.abs. output.print("enter an integer... "); int entry = input.nextint(); int absvalue = entry; if (entry < 0) absvalue = -entry; output.println(absvalue); 35 Pitfall What is wrong with this? output.print("enter an integer... "); int entry = input.nextint(); int absvalue = entry; if (entry < 0); absvalue = -entry; output.println(absvalue); 36 18
19 The if-else Statement S Statement -S A 1 A 2 true false B 1 B 2 if ( condition ) Statement -A1 Statement -A2... X else Statement -B1 Statement -B2... Statement -X 37 Example Rewrite the abs value fragment using if-else 38 19
20 Example Rewrite the abs value fragment using if-else int absvalue; if (entry < 0) absvalue = -entry; else absvalue = entry; 39 Pitfall What is wrong with this? if (entry < 0) int absvalue = -entry; else int absvalue = entry; 40 20
21 5.1.3 Building the Condition Relational Expression if (k < 0) Boolean Variable boolean b = k < 0 if (b) Boolean Expression if (k < 0 b && m > h) 41 Uses boolean operators: &&,, and! Operator Precedence ! cast * / % + - < <= > >= ==!= && = op= 21
22 Examples Express the condition x [a, b) Express the condition x [a, b) 43 Examples Express the condition x [a, b) if (x >= a && x < b) Express the condition x [a, b) if (!(x >= a && x < b)) Can use demorgan s Law to convert negated conjunctions to disjunctions. if (x < a x >= b) 44 22
23 Example Write a fragment to determine if the objects of two given references x and y are equal. if (x.equals(y)) But what if x were null? 45 Example Write a fragment to determine if the objects of two given references x and y are equal. if (x!= null && x.equals(y)) But wouldn t this crash anyway? Lazy (short-circuit) evaluation of && and
24 5.1.4 Multiway Branching Reduce an n-way branch to n-1 2-way branches A 1 A2 S true X false true false B 1 C1 B 2 C2 Statement -S if (condition -1) Statement -A1 Statement -A2... else if (condition -2) Statement -B1 Statement -B2... else Statement -C1 Statement -C2... Statement -X 47 Example Write a fragment to determine the full letter grade given the mark (out of 100) in a course
25 Example char grade; if (mark >= 80) grade = 'A'; else if (mark >= 70) grade = 'B'; else if (mark >= 60) grade = 'C'; else if (mark >= 50) grade = 'D'; else grade = 'F'; 49 25
Control Structures/Lespérance 1
EEC1022 MOBILE COMPUTING What is control; how does it flow? equence versus elec%on Flow (a) (b) 1 2 A1 B1 C1 PROF. Y. LEPÉRANCE n Dept. of Electrical Engineering & Computer cience 1 2 A 1 A 2 true false
More informationIntroduction to Programming Using Java (98-388)
Introduction to Programming Using Java (98-388) Understand Java fundamentals Describe the use of main in a Java application Signature of main, why it is static; how to consume an instance of your own class;
More informationProgramming for Experimental Research. Flow Control
Programming for Experimental Research Flow Control FLOW CONTROL In a simple program, the commands are executed one after the other in the order they are typed. Many situations require more sophisticated
More informationV2 2/4/ Ch Programming in C. Flow of Control. Flow of Control. Flow of control The order in which statements are executed
Programming in C 1 Flow of Control Flow of control The order in which statements are executed Transfer of control When the next statement executed is not the next one in sequence 2 Flow of Control Control
More informationFlow of Control. Flow of control The order in which statements are executed. Transfer of control
1 Programming in C Flow of Control Flow of control The order in which statements are executed Transfer of control When the next statement executed is not the next one in sequence 2 Flow of Control Control
More informationReview for Test 1 (Chapter 1-5)
Review for Test 1 (Chapter 1-5) 1. Introduction to Computers, Programs, and Java a) What is a computer? b) What is a computer program? c) A bit is a binary digit 0 or 1. A byte is a sequence of 8 bits.
More informationExam 1 Prep. Dr. Demetrios Glinos University of Central Florida. COP3330 Object Oriented Programming
Exam 1 Prep Dr. Demetrios Glinos University of Central Florida COP3330 Object Oriented Programming Progress Exam 1 is a Timed Webcourses Quiz You can find it from the "Assignments" link on Webcourses choose
More informationSlide 1 CS 170 Java Programming 1 The Switch Duration: 00:00:46 Advance mode: Auto
CS 170 Java Programming 1 The Switch Slide 1 CS 170 Java Programming 1 The Switch Duration: 00:00:46 Menu-Style Code With ladder-style if-else else-if, you might sometimes find yourself writing menu-style
More informationMotivation of Loops. Loops. The for Loop (1) Learning Outcomes
Motivation of Loops Loops EECS1022: Programming for Mobile Computing Winter 2018 CHEN-WEI WANG We may want to repeat the similar action(s) for a (bounded) number of times. e.g., Print the Hello World message
More informationLoops. EECS1022: Programming for Mobile Computing Winter 2018 CHEN-WEI WANG
Loops EECS1022: Programming for Mobile Computing Winter 2018 CHEN-WEI WANG Learning Outcomes Understand about Loops : Motivation: Repetition of similar actions Two common loops: for and while Primitive
More informationChapter 6 Primitive types
Chapter 6 Primitive types Lesson page 6-1. Primitive types Question 1. There are an infinite number of integers, so it would be too ineffient to have a type integer that would contain all of them. Question
More informationSelections. EECS1021: Object Oriented Programming: from Sensors to Actuators Winter 2019 CHEN-WEI WANG
Selections EECS1021: Object Oriented Programming: from Sensors to Actuators Winter 2019 CHEN-WEI WANG Learning Outcomes The Boolean Data Type if Statement Compound vs. Primitive Statement Common Errors
More informationQUIZ: What value is stored in a after this
QUIZ: What value is stored in a after this statement is executed? Why? a = 23/7; QUIZ evaluates to 16. Lesson 4 Statements, Expressions, Operators Statement = complete instruction that directs the computer
More informationPlease write your name and username here legibly: C212/A592 6W2 Summer 2017 Early Evaluation Exam: Fundamental Programming Structures in Java
Please write your name and username here legibly: C212/A592 6W2 Summer 2017 Early Evaluation Exam: Fundamental Programming Structures in Java Use BigDecimal (a class defined in package java.math) to write
More informationCSCI 131, Midterm Exam 1 Review Questions This sheet is intended to help you prepare for the first exam in this course. The following topics have
CSCI 131, Midterm Exam 1 Review Questions This sheet is intended to help you prepare for the first exam in this course. The following topics have been covered in the first 5 weeks of the course. The exam
More informationPace University. Fundamental Concepts of CS121 1
Pace University Fundamental Concepts of CS121 1 Dr. Lixin Tao http://csis.pace.edu/~lixin Computer Science Department Pace University October 12, 2005 This document complements my tutorial Introduction
More informationEECS1710. Announcements. epost updated, please check online Next Labtest: Thu Oct 23/Fri Oct 24. Next Term Test: Tue Oct 28.
EECS1710 Click to edit Master Week text 06, styles Lecture 11 Second level Third level Fourth level Fifth level Fall 2014! Tuesday, Oct 14, 2014 1 Announcements epost updated, please check online Next
More informationMotivation of Loops. Loops. The for Loop (1) Learning Outcomes
Motivation of Loops Loops EECS1021: Object Oriented Programming: from Sensors to Actuators Winter 2019 CHEN-WEI WANG We may want to repeat the similar action(s) for a (bounded) number of times. e.g., Print
More informationThe next three class meetings will focus on Chapter 6 concepts. There will be a labtest on Chapter 5 concepts on Thurs Nov 28/Fri Nov 29.
CSE1710 Click to edit Master Week text 12, styles Lecture 22 Second level Third level Fourth level Fifth level Fall 2013 Tuesday, Nov 26, 2013 1 2 Big Picture The next three class meetings will focus on
More informationLoops. EECS1021: Object Oriented Programming: from Sensors to Actuators Winter 2019 CHEN-WEI WANG
Loops EECS1021: Object Oriented Programming: from Sensors to Actuators Winter 2019 CHEN-WEI WANG Learning Outcomes Understand about Loops : Motivation: Repetition of similar actions Two common loops: for
More informationUEE1302(1102) F10: Introduction to Computers and Programming
Computational Intelligence on Automation Lab @ NCTU UEE1302(1102) F10: Introduction to Computers and Programming Programming Lecture 02 Flow of Control (I): Boolean Expression and Selection Learning Objectives
More informationMotivating Examples (1.1) Selections. Motivating Examples (1.2) Learning Outcomes. EECS1022: Programming for Mobile Computing Winter 2018
Motivating Examples (1.1) Selections EECS1022: Programming for Mobile Computing Winter 2018 CHEN-WEI WANG 1 import java.util.scanner; 2 public class ComputeArea { 3 public static void main(string[] args)
More informationC++ Programming Lecture 1 Software Engineering Group
C++ Programming Lecture 1 Software Engineering Group Philipp D. Schubert Contents 1. More on data types 2. Expressions 3. Const & Constexpr 4. Statements 5. Control flow 6. Recap More on datatypes: build-in
More informationThe next three class meetings will focus on Chapter 6 concepts. There will be a labtest on Chapter 5 concepts on Thurs Nov 20/Fri Nov 21.
CSE1710 Click to edit Master Week text 11, styles Lecture 21 Second level Third level Fourth level Fifth level Fall 2014! Thurs, Nov 20, 2014 1 Big Picture The next three class meetings will focus on Chapter
More informationFall 2017 CISC124 9/16/2017
CISC124 Labs start this week in JEFF 155: Meet your TA. Check out the course web site, if you have not already done so. Watch lecture videos if you need to review anything we have already done. Problems
More informationLecture 5 Tao Wang 1
Lecture 5 Tao Wang 1 Objectives In this chapter, you will learn about: Selection criteria Relational operators Logical operators The if-else statement Nested if statements C++ for Engineers and Scientists,
More informationFlow Control. CSC215 Lecture
Flow Control CSC215 Lecture Outline Blocks and compound statements Conditional statements if - statement if-else - statement switch - statement? : opertator Nested conditional statements Repetitive statements
More informationChapter 5 Control Structures
Chapter 5 Control Structures I. Scott MacKenzie 1 Outline 2 Flow of Control 3 if Statement 4 if Statement Example IO.print("Is is raining? (1=yes, 2=no)... "); int response = IO.readInt(); SE.require(response
More informationMidterm Review Topics Java Basics and Structure Variables Branching Loops Methods Arrays. Midterm Review Kage Weiss Lab 001 TA, SPR 17
Midterm Review Topics Java Basics and Structure Variables Branching Loops Methods Arrays Midterm Review Kage Weiss Lab 001 TA, SPR 17 Java Basics and Structure Class{ class variables; methods{ method variables;
More informationCOMP 250: Java Programming I. Carlos G. Oliver, Jérôme Waldispühl January 17-18, 2018 Slides adapted from M. Blanchette
COMP 250: Java Programming I Carlos G. Oliver, Jérôme Waldispühl January 17-18, 2018 Slides adapted from M. Blanchette Variables and types [Downey Ch 2] Variable: temporary storage location in memory.
More informationEECS1710. Announcements. Labtests have been returned Term Test #01 marking is in progress. Next Labtest: Thu Oct 23/Fri Oct 24
EECS1710 Click to edit Master Week text 05, styles Lecture 10 Second level Third level Fourth level Fifth level Fall 2014! Thursday, Oct 09, 2014 1 Announcements Labtests have been returned Term Test #01
More informationControl Structures in Java if-else and switch
Control Structures in Java if-else and switch Lecture 4 CGS 3416 Spring 2017 January 23, 2017 Lecture 4CGS 3416 Spring 2017 Selection January 23, 2017 1 / 26 Control Flow Control flow refers to the specification
More informationAnnouncements. Lab Friday, 1-2:30 and 3-4:30 in Boot your laptop and start Forte, if you brought your laptop
Announcements Lab Friday, 1-2:30 and 3-4:30 in 26-152 Boot your laptop and start Forte, if you brought your laptop Create an empty file called Lecture4 and create an empty main() method in a class: 1.00
More informationVARIABLES AND TYPES CITS1001
VARIABLES AND TYPES CITS1001 Scope of this lecture Types in Java the eight primitive types the unlimited number of object types Values and References The Golden Rule Primitive types Every piece of data
More informationObject Oriented Programming. Java-Lecture 6 - Arrays
Object Oriented Programming Java-Lecture 6 - Arrays Arrays Arrays are data structures consisting of related data items of the same type In Java arrays are objects -> they are considered reference types
More informationCourse Text. Course Description. Course Objectives. StraighterLine Introduction to Programming in C++
Introduction to Programming in C++ Course Text Programming in C++, Zyante, Fall 2013 edition. Course book provided along with the course. Course Description This course introduces programming in C++ and
More informationMultiple Choice (Questions 1 13) 26 Points Select all correct answers (multiple correct answers are possible)
Name Closed notes, book and neighbor. If you have any questions ask them. Notes: Segment of code necessary C++ statements to perform the action described not a complete program Program a complete C++ program
More informationMcGill University School of Computer Science COMP-202A Introduction to Computing 1
McGill University School of Computer Science COMP-202A Introduction to Computing 1 Midterm Exam Thursday, October 26, 2006, 18:00-20:00 (6:00 8:00 PM) Instructors: Mathieu Petitpas, Shah Asaduzzaman, Sherif
More informationAdministration. Conditional Statements. Agenda. Syntax. Flow of control. Lab 2 due now on floppy Lab 3 due tomorrow via FTP
Administration Conditional Statements CS 99 Summer 2000 Michael Clarkson Lecture 4 Lab 2 due now on floppy Lab 3 due tomorrow via FTP need Instruct account password Lab 4 posted this afternoon Prelim 1
More informationCA4003 Compiler Construction Assignment Language Definition
CA4003 Compiler Construction Assignment Language Definition David Sinclair 2017-2018 1 Overview The language is not case sensitive. A nonterminal, X, is represented by enclosing it in angle brackets, e.g.
More informationWhat we are reinforcing with the exercises this class
CSE1710 Click to edit Master Week text 01, styles Lecture 02 Second level Third level Fourth level Fifth level Fall 2013 Thursday, Sept 12, 2013 1 Checklist What we are reinforcing with the exercises this
More informationCS313D: ADVANCED PROGRAMMING LANGUAGE
CS313D: ADVANCED PROGRAMMING LANGUAGE Computer Science department Lecture 2 : C# Language Basics Lecture Contents 2 The C# language First program Variables and constants Input/output Expressions and casting
More informationLecture 1. Types, Expressions, & Variables
Lecture 1 Types, Expressions, & Variables About Your Instructor Director: GDIAC Game Design Initiative at Cornell Teach game design (and CS 1110 in fall) 8/29/13 Overview, Types & Expressions 2 Helping
More informationG Programming Languages - Fall 2012
G22.2110-003 Programming Languages - Fall 2012 Lecture 3 Thomas Wies New York University Review Last week Names and Bindings Lifetimes and Allocation Garbage Collection Scope Outline Control Flow Sequencing
More informationChapter 3. More Flow of Control. Copyright 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley
Chapter 3 More Flow of Control Overview 3.1 Using Boolean Expressions 3.2 Multiway Branches 3.3 More about C++ Loop Statements 3.4 Designing Loops Slide 3-3 Flow Of Control Flow of control refers to the
More informationCS/IT 114 Introduction to Java, Part 1 FALL 2016 CLASS 19: NOV. 15TH INSTRUCTOR: JIAYIN WANG
CS/IT 114 Introduction to Java, Part 1 FALL 2016 CLASS 19: NOV. 15TH INSTRUCTOR: JIAYIN WANG 1 Notice Assignment Class Exercise 19 is assigned Homework 8 is assigned Both Homework 8 and Exercise 19 are
More informationIteration in Programming
Iteration in Programming for loops Produced by: Mairead Meagher Dr. Siobhán Drohan Department of Computing and Mathematics http://www.wit.ie/ Topics list There are three types of loop in programming: While
More informationCSE 113 A. Announcements - Lab
CSE 113 A February 21-25, 2011 Announcements - Lab Lab 1, 2, 3, 4; Practice Assignment 1, 2, 3, 4 grades are available in Web-CAT look under Results -> Past Results and if looking for Lab 1, make sure
More informationCSCI 1061U Programming Workshop 2. C++ Basics
CSCI 1061U Programming Workshop 2 C++ Basics 1 Learning Objectives Introduction to C++ Origins, Object-Oriented Programming, Terms Variables, Expressions, and Assignment Statements Console Input/Output
More informationCS1150 Principles of Computer Science Boolean, Selection Statements
CS1150 Principles of Computer Science Boolean, Selection Statements Yanyan Zhuang Department of Computer Science http://www.cs.uccs.edu/~yzhuang CS1150 Math Center https://www.uccs.edu/mathcenter/schedules
More informationMultiple Choice (Questions 1 13) 26 Points Select all correct answers (multiple correct answers are possible)
Name Closed notes, book and neighbor. If you have any questions ask them. Notes: Segment of code necessary C++ statements to perform the action described not a complete program Program a complete C++ program
More informationControl Structures. Lecture 4 COP 3014 Fall September 18, 2017
Control Structures Lecture 4 COP 3014 Fall 2017 September 18, 2017 Control Flow Control flow refers to the specification of the order in which the individual statements, instructions or function calls
More informationTopics. Chapter 5. Equality Operators
Topics Chapter 5 Flow of Control Part 1: Selection Forming Conditions if/ Statements Comparing Floating-Point Numbers Comparing Objects The equals Method String Comparison Methods The Conditional Operator
More informationChapter 3 Selection Statements
Chapter 3 Selection Statements 3.1 Introduction Java provides selection statements that let you choose actions with two or more alternative courses. Selection statements use conditions. Conditions are
More information5. Control Statements
5. Control Statements This section of the course will introduce you to the major control statements in C++. These control statements are used to specify the branching in an algorithm/recipe. Control statements
More informationMultiple Choice (Questions 1 14) 28 Points Select all correct answers (multiple correct answers are possible)
Name Closed notes, book and neighbor. If you have any questions ask them. Notes: Segment of code necessary C++ statements to perform the action described not a complete program Program a complete C++ program
More informationControl Structures in Java if-else and switch
Control Structures in Java if-else and switch Lecture 4 CGS 3416 Spring 2016 February 2, 2016 Control Flow Control flow refers to the specification of the order in which the individual statements, instructions
More informationSTUDENT LESSON A12 Iterations
STUDENT LESSON A12 Iterations Java Curriculum for AP Computer Science, Student Lesson A12 1 STUDENT LESSON A12 Iterations INTRODUCTION: Solving problems on a computer very often requires a repetition of
More informationPIC 10A Flow control. Ernest Ryu UCLA Mathematics
PIC 10A Flow control Ernest Ryu UCLA Mathematics If statement An if statement conditionally executes a block of code. # include < iostream > using namespace std ; int main () { double d1; cin >> d1; if
More informationSelection Statements. Pseudocode
Selection Statements Pseudocode Natural language mixed with programming code Ex: if the radius is negative the program display a message indicating wrong input; the program compute the area and display
More informationCS 101 Computer Programming and utilization. Dr Deepak B Phatak Subrao Nilekani Chair Professor Department of CSE, Kanwal Rekhi Building IIT Bombay
CS 101 Computer Programming and utilization Dr Deepak B Phatak Subrao Nilekani Chair Professor Department of CSE, Kanwal Rekhi Building Bombay Lecture 4, Conditional execution of instructions Friday, August
More informationFinal exam. Final exam will be 12 problems, drop any 2. Cumulative up to and including week 14 (emphasis on weeks 9-14: classes & pointers)
Review Final exam Final exam will be 12 problems, drop any 2 Cumulative up to and including week 14 (emphasis on weeks 9-14: classes & pointers) 2 hours exam time, so 12 min per problem (midterm 2 had
More informationJava Control Statements
Java Control Statements An introduction to the Java Programming Language Produced by: Eamonn de Leastar (edeleastar@wit.ie) Dr. Siobhan Drohan (sdrohan@wit.ie) Department of Computing and Mathematics http://www.wit.ie/
More informationName Section: M/W T/TH Number Definition Matching (6 Points)
Name Section: M/W T/TH Number Definition Matching (6 Points) 1. (6 pts) Match the words with their definitions. Choose the best definition for each word. Event Counter Iteration Counter Loop Flow of Control
More informationObject-Oriented Programming
Object-Oriented Programming Java Syntax Program Structure Variables and basic data types. Industry standard naming conventions. Java syntax and coding conventions If Then Else Case statements Looping (for,
More informationChapter 4: Making Decisions
Chapter 4: Making Decisions CSE 142 - Computer Programming I 1 4.1 Relational Operators Relational Operators Used to compare numbers to determine relative order Operators: > Greater than < Less than >=
More informationBCIS 3630 Dr. GUYNES SPRING 2018 TUESDAY SECTION [JAN version] GRADER COURSE WEBSITE
COURSE WEBSITE http://www.steveguynes.com/bcis3630/bcis3630/default.html Instructor: Dr. Guynes Office: BLB 312H Phone: (940) 565-3110 Office Hours: By Email Email: steve.guynes@unt.edu TEXTBOOK: Starting
More informationcs1114 REVIEW of details test closed laptop period
python details DOES NOT COVER FUNCTIONS!!! This is a sample of some of the things that you are responsible for do not believe that if you know only the things on this test that they will get an A on any
More informationCS Week 5. Jim Williams, PhD
CS 200 - Week 5 Jim Williams, PhD The Study Cycle Check Am I using study methods that are effective? Do I understand the material enough to teach it to others? http://students.lsu.edu/academicsuccess/studying/strategies/tests/studying
More informationCS11 Java. Fall Lecture 1
CS11 Java Fall 2006-2007 Lecture 1 Welcome! 8 Lectures Slides posted on CS11 website http://www.cs.caltech.edu/courses/cs11 7-8 Lab Assignments Made available on Mondays Due one week later Monday, 12 noon
More informationSelec%on and Decision Structures in Java: If Statements and Switch Statements CSC 121 Spring 2016 Howard Rosenthal
Selec%on and Decision Structures in Java: If Statements and Switch Statements CSC 121 Spring 2016 Howard Rosenthal Lesson Goals Understand Control Structures Understand how to control the flow of a program
More informationBRANCHING if-else statements
BRANCHING if-else statements Conditional Statements A conditional statement lets us choose which statement t t will be executed next Therefore they are sometimes called selection statements Conditional
More informationCSE450. Translation of Programming Languages. Lecture 11: Semantic Analysis: Types & Type Checking
CSE450 Translation of Programming Languages Lecture 11: Semantic Analysis: Types & Type Checking Structure Project 1 - of a Project 2 - Compiler Today! Project 3 - Source Language Lexical Analyzer Syntax
More informationCIS 130 Exam #2 Review Suggestions
CIS 130 - Exam #2 Review Suggestions p. 1 * last modified: 11-11-05, 12:32 am CIS 130 Exam #2 Review Suggestions * remember: YOU ARE RESPONSIBLE for course reading, lectures/labs, and especially anything
More informationChapter 4 Loops. int x = 0; while ( x <= 3 ) { x++; } System.out.println( x );
Chapter 4 Loops Sections Pages Review Questions Programming Exercises 4.1 4.7, 4.9 4.10 104 117, 122 128 2 9, 11 13,15 16,18 19,21 2,4,6,8,10,12,14,18,20,24,26,28,30,38 Loops Loops are used to make a program
More informationLecture 8 CSE11 Fall 2013 While Loops, Switch Statement, Simplifying Conditionals
Lecture 8 CSE11 Fall 2013 While Loops, Switch Statement, Simplifying Conditionals What are Computers Really Good at? Complex calculations Repetitive tasks Identifying repetition is key to many programming
More informationLoops. In Example 1, we have a Person class, that counts the number of Person objects constructed.
Loops Introduction In this article from my free Java 8 course, I will discuss the use of loops in Java. Loops allow the program to execute repetitive tasks or iterate over vast amounts of data quickly.
More informationCOMP Primitive and Class Types. Yi Hong May 14, 2015
COMP 110-001 Primitive and Class Types Yi Hong May 14, 2015 Review What are the two major parts of an object? What is the relationship between class and object? Design a simple class for Student How to
More informationLecture 5. Review from last week. Selection Statements. cin and cout directives escape sequences
Lecture 5 Selection Statements Review from last week cin and cout directives escape sequences member functions formatting flags manipulators cout.width(20); cout.setf(ios::fixed); setwidth(20); 1 What
More informationData Types, Variables and Arrays. OOC 4 th Sem, B Div Prof. Mouna M. Naravani
Data Types, Variables and Arrays OOC 4 th Sem, B Div 2016-17 Prof. Mouna M. Naravani Identifiers in Java Identifiers are the names of variables, methods, classes, packages and interfaces. Identifiers must
More informationComputer Programming, I. Laboratory Manual. Experiment #3. Selections
Think Twice Code Once The Islamic University of Gaza Engineering Faculty Department of Computer Engineering Fall 2017 ECOM 2005 Khaleel I. Shaheen Computer Programming, I Laboratory Manual Experiment #3
More informationSelec%on and Decision Structures in Java: If Statements and Switch Statements CSC 121 Fall 2016 Howard Rosenthal
Selec%on and Decision Structures in Java: If Statements and Switch Statements CSC 121 Fall 2016 Howard Rosenthal Lesson Goals Understand Control Structures Understand how to control the flow of a program
More informationAnnouncements. Homework 0: using cin with 10/3 is NOT the same as (directly)
Branching Announcements Homework 0: using cin with 10/3 is NOT the same as 3.3333 (directly) With cin, it will stop as soon as it reaches a type that does not match the variable (into which it is storing)
More information1 Lexical Considerations
Massachusetts Institute of Technology Department of Electrical Engineering and Computer Science 6.035, Spring 2013 Handout Decaf Language Thursday, Feb 7 The project for the course is to write a compiler
More informationContents. Jairo Pava COMS W4115 June 28, 2013 LEARN: Language Reference Manual
Jairo Pava COMS W4115 June 28, 2013 LEARN: Language Reference Manual Contents 1 Introduction...2 2 Lexical Conventions...2 3 Types...3 4 Syntax...3 5 Expressions...4 6 Declarations...8 7 Statements...9
More informationMore on control structures
Lecture slides for: Chapter 5 More on control structures Java Actually: A Comprehensive Primer in Programming Khalid Azim Mughal, Torill Hamre, Rolf W. Rasmussen Cengage Learning, 2008. ISBN: 978-1-844480-933-2
More informationCIS 110: Introduction to Computer Programming
CIS 110: Introduction to Computer Programming Lecture 3 Express Yourself ( 2.1) 9/16/2011 CIS 110 (11fa) - University of Pennsylvania 1 Outline 1. Data representation and types 2. Expressions 9/16/2011
More informationChapter 2. Flow of Control. Copyright 2016 Pearson, Inc. All rights reserved.
Chapter 2 Flow of Control Copyright 2016 Pearson, Inc. All rights reserved. Learning Objectives Boolean Expressions Building, Evaluating & Precedence Rules Branching Mechanisms if-else switch Nesting if-else
More informationThe Arithmetic Operators
The Arithmetic Operators The arithmetic operators refer to the standard mathematical operators: addition, subtraction, multiplication, division and modulus. Examples: Op. Use Description + x + y adds x
More informationThe Arithmetic Operators. Unary Operators. Relational Operators. Examples of use of ++ and
The Arithmetic Operators The arithmetic operators refer to the standard mathematical operators: addition, subtraction, multiplication, division and modulus. Op. Use Description + x + y adds x and y x y
More informationThe PCAT Programming Language Reference Manual
The PCAT Programming Language Reference Manual Andrew Tolmach and Jingke Li Dept. of Computer Science Portland State University September 27, 1995 (revised October 15, 2002) 1 Introduction The PCAT language
More informationLesson 38: Conditionals #2 (W11D3)
Lesson 38: Conditionals #2 (W11D3) Balboa High School Michael Ferraro October 28, 2015 1 / 61 Do Now In Lesson38/DoNow.java, write a method called isdivisiblebyfour() that takes an int returns the boolean
More informationSimple Java Programming Constructs 4
Simple Java Programming Constructs 4 Course Map In this module you will learn the basic Java programming constructs, the if and while statements. Introduction Computer Principles and Components Software
More informationCS 211: Methods, Memory, Equality
CS 211: Methods, Memory, Equality Chris Kauffman Week 2-1 So far... Comments Statements/Expressions Variable Types little types, what about Big types? Assignment Basic Output (Input?) Conditionals (if-else)
More informationCSE115 / CSE503 Introduction to Computer Science I Dr. Carl Alphonce 343 Davis Hall Office hours:
CSE115 / CSE503 Introduction to Computer Science I Dr. Carl Alphonce 343 Davis Hall alphonce@buffalo.edu Office hours: Tuesday 10:00 AM 12:00 PM * Wednesday 4:00 PM 5:00 PM Friday 11:00 AM 12:00 PM OR
More informationCSc 10200! Introduction to Computing. Lecture 2-3 Edgardo Molina Fall 2013 City College of New York
CSc 10200! Introduction to Computing Lecture 2-3 Edgardo Molina Fall 2013 City College of New York 1 C++ for Engineers and Scientists Third Edition Chapter 2 Problem Solving Using C++ 2 Objectives In this
More informationCOMP 202 Java in one week
CONTENTS: Basics of Programming Variables and Assignment Data Types: int, float, (string) Example: Implementing a calculator COMP 202 Java in one week The Java Programming Language A programming language
More informationFollowing is the general form of a typical decision making structure found in most of the programming languages:
Decision Making Decision making structures have one or more conditions to be evaluated or tested by the program, along with a statement or statements that are to be executed if the condition is determined
More informationObjectives for this class meeting. 1. Conduct review of core concepts concerning contracts and pre/post conditions
CSE1720 Click to edit Master Week text 01, styles Lecture 02 Second level Third level Fourth level Fifth level Winter 2015! Thursday, Jan 8, 2015 1 Objectives for this class meeting 1. Conduct review of
More informationCS313D: ADVANCED PROGRAMMING LANGUAGE
CS313D: ADVANCED PROGRAMMING LANGUAGE Computer Science Department Lecture 3: C# language basics Lecture Contents 2 C# basics Conditions Loops Methods Arrays Dr. Amal Khalifa, Spr 2015 3 Conditions and
More information