CSE 113 Introduction to Computer Programming Lecture slides for Week 10 Monday, October 31 th, 2011 Instructor: Scott Settembre.

Slides:



Advertisements
Similar presentations
Control Structures.
Advertisements

CISC Data Structures Ben Perry University of Delaware Summer 2011.
CSE 113 Introduction to Computer Programming Lecture slides for Week 3 Monday, September 12 th, 2011 Instructor: Scott Settembre.
No calculators or notes can be used on this quiz.
Creating PHP Pages Chapter 7 PHP Decisions Making.
Objectives Using functions to organize PHP code
CSE 113 Introduction to Computer Programming Lecture slides for Week 6 Monday, October 3 rd, 2011 Instructor: Scott Settembre.
PHP Functions and Control Structures. 2 Defining Functions Functions are groups of statements that you can execute as a single unit Function definitions.
Mock test review Revision of Activity Diagrams for Loops,
Introduction to Computers and Programming Lecture 10: For Loops Professor: Evan Korth New York University.
Chapter 4 Functions and Control Structures PHP Programming with MySQL.
Administrative Issues ICS 151 Fall 2007 Instructor: Eli Bozorgzadeh.
Computer Programming 1 Repetition. Computer Programming 2 Objectives Repetition structures Study while and do loops Examine for loops A practical example.
Please CLOSE YOUR LAPTOPS, and turn off and put away your cell phones, and get out your note-taking materials. Today’s Gateway Test will be given during.
Today’s quiz on 8.2 B Graphing Worksheet 2 will be given at the end of class. You will have 12 minutes to complete this quiz, which will consist of one.
ECE200 – Computer Organization Course Introduction.
Please open your laptops, log in to the MyMathLab course web site, and open Daily Quiz 18. You will have 10 minutes for today’s quiz. The second problem.
Please open your laptops, log in to the MyMathLab course web site, and open Quiz 4.1/4.2. IMPORTANT NOTE: If you have time left after you finish this quiz,
Please open your laptops and pull up Quiz Only the provided online calculator may be used on this quiz. You may use your yellow formula sheet for.
Next class session: Test 1 on all sections covered from Chapters 1 and 2 Remember: If you haven’t yet passed the Gateway Quiz, you need to review your.
CIS3931 – Intro to JAVA Lecture Note Set 3 19-May-05.
Welcome to Math 110 Online Section 001, Summer 2015.
CHEMISTRY 10123/10125 Spring 2007 Instructor: Professor Tracy Hanna Phone: Office: SWR 418
Lecture 10 Instructor: Craig Duckett. Assignment 2 Revision TONIGHT DUE TONIGHT Wednesday, August 5 th Assignment 3 NEXT DUE NEXT Monday, August 10 th.
CPS 2231 Computer Organization and Programming Instructor: Tian (Tina) Tian.
Instructor: Alexander Stoytchev CprE 185: Intro to Problem Solving (using C)
CSE 113 Introduction to Computer Programming Lecture slides for Week 4 Monday, September 19 th, 2011 Instructor: Scott Settembre.
Social Psychology: Attitudes & Persuasion (PSY320)
Administrative Issues ICS 151 Winter 2010 Instructor: Eli Bozorgzadeh.
Chapter 4: Decision Making with Control Structures and Statements JavaScript - Introductory.
CSE 113 Introduction to Computer Programming Lecture slides for Week 2 Wednesday, September 7 th, 2011 Instructor: Scott Settembre.
CPS120 Introduction to Computer Science Iteration (Looping)
CSCI 3328 Object Oriented Programming in C# Chapter 5: C# Control Statement – Part II UTPA – Fall
CSE 113 Introduction to Computer Programming Lecture slides for Week 5 Monday, September 26 th, 2011 Instructor: Scott Settembre.
CS122 Engineering Computation Lab Lab 3 Bruce Char Department of Computer Science Drexel University Spring 2011.
CS123 Engineering Computation Lab Lab 4 Bruce Char Department of Computer Science Drexel University Spring 2010.
PHP Programming with MySQL Slide 4-1 CHAPTER 4 Functions and Control Structures.
CSE 113 Introduction to Computer Programming Lecture slides for Week 1 Monday, August 29 th, 2011 Instructor: Scott Settembre.
CSE 113 Introduction to Computer Programming Lecture slides for Week 7 Monday, October 10 th, 2011 Instructor: Scott Settembre.
CSE 113 Introduction to Computer Programming Lecture slides for Week 12 Monday, November 14 th, 2011 Instructor: Scott Settembre.
BIT 115: Introduction To Programming Instructor: Jon Peck
Chapter 2 Functions and Control Structures PHP Programming with MySQL 2 nd Edition.
Current Assignments Homework 2 is available and is due in three days (June 19th). Project 1 due in 6 days (June 23 rd ) Write a binomial root solver using.
CMPSC 16 Problem Solving with Computers I Spring 2014 Instructor: Lucas Bang Lecture 5: Introduction to C: More Control Flow.
Please CLOSE YOUR LAPTOPS, and turn off and put away your cell phones, and get out your note- taking materials.
CPS120 Introduction to Computer Science Iteration (Looping)
ITEC 109 Lecture 11 While loops. while loops Review Choices –1 st –2 nd to ?th –Last What happens if you only use ifs? Can you have just an else by itself?
REMINDER: If you haven’t yet passed the Gateway Quiz, make sure you take it this week! (You can find more practice quizzes online in the Gateway Info menu.
Beginning C For Engineers Fall 2005 Lecture 3: While loops, For loops, Nested loops, and Multiple Selection Section 2 – 9/14/05 Section 4 – 9/15/05 Bettina.
CSE 1340 Introduction to Computing Concepts Class 1 ~ Intro.
1 Project 7: Looping. Project 7 For this project you will produce two Java programs. The requirements for each program will be described separately on.
CISC105 – General Computer Science Class 4 – 06/14/2006.
Instructor: Alexander Stoytchev CprE 185: Intro to Problem Solving (using C)
Instructor: Alexander Stoytchev CprE 185: Intro to Problem Solving (using C)
CS122 Engineering Computation Lab Lab 2 Bruce Char Department of Computer Science Drexel University Winter 2012.
CS122 Engineering Computation Lab Lab 3 Bruce Char Department of Computer Science Drexel University Winter 2010.
REMINDER: If you haven’t yet passed the Gateway Quiz, make sure you take it this week! (You can find more practice quizzes online in the Gateway Info menu.
WELCOME TO MANAGERIAL ECONOMICS MT 445 Discussion of Syllabus and Expectations in the Class.
CMSC201 Computer Science I for Majors Lecture 05 – Comparison Operators and Boolean (Logical) Operators Prof. Katherine Gibson Prof. Jeremy.
CprE 185: Intro to Problem Solving (using C)
Midterm Exam Preperation
Lecture Notes – Week 3 Lecture-2
Final Exam End of Semester
Administrative Issues
CprE 185: Intro to Problem Solving (using C)
Midterm Review October 23, 2006 ComS 207: Programming I (in Java)
Administrative Issues
CprE 185: Intro to Problem Solving (using C)
Module 4 Loops and Repetition 9/19/2019 CSE 1321 Module 4.
Presentation transcript:

CSE 113 Introduction to Computer Programming Lecture slides for Week 10 Monday, October 31 th, 2011 Instructor: Scott Settembre

COURSE ADMINISTRATION Section 1 Monday, Oct. 31st, 2011 University at Buffalo: CSE 113 Instructor: Scott Settembre 2

For Project Assistance You can find the up-to-date hours and locations in the “Contact” section of UBLearns. Here are the names, s, and office hours as of 10/31/2011: (Also come to additional labs if you need help) Monday, Oct. 31st, 2011 University at Buffalo: CSE 113 Instructor: Scott Settembre 3 Name addressOffice hours Bich (pronounced “Bic”) (11-11:50am) Bell 329 F (12-12:50pm) Bell 329 Troy (3-5pm) Bell 329 Scott (10-11am) Bell 232 F (10-11am) Bell 340 Also at all times by AND video conference by appointment.

You are behind the class if… If you have not: – completed chapter 1-6, then you are behind the rest of the class. Please do the following: – Finish chapter 6 in lab this week. – Begin working on project 2. Monday, Oct. 31st, 2011 University at Buffalo: CSE 113 Instructor: Scott Settembre 4

Lecture and Lab this Week Lectures will go over the following: – Project 2 – switch statement – for loop Lab will have you do the following: – Finish chapter 6. – Start your project 1. – Lab Quiz on chapters 6. Monday, Oct. 31st, 2011 University at Buffalo: CSE 113 Instructor: Scott Settembre 5

MIDTERM / FINAL EXAM / PROJECT Section 2 Monday, Oct. 31st, 2011 University at Buffalo: CSE 113 Instructor: Scott Settembre 6

Midterm exam (15%) The midterm exam will be held in lecture on October 21 st. It will cover chapters 1-6.4, including the exercises in the chapter that you do in lab. It will be a series of true/false, multiple choice, and code examination (running the code in your head), similar to the quizzes that you will have taken. Grades have been released. Monday, Oct. 31st, 2011 University at Buffalo: CSE 113 Instructor: Scott Settembre 7

Final Exam (25%) The final exam will be during class during the last week of class. It will span two days, 45 minutes (or less) each day. It will consist of questions like the quizzes, as well as some code reading and understanding. More on this in November. Monday, Oct. 31st, 2011 University at Buffalo: CSE 113 Instructor: Scott Settembre 8

Project 1 Project 1 grades have been posted. Good job! Monday, Oct. 31st, 2011 University at Buffalo: CSE 113 Instructor: Scott Settembre 9

Project 2 Due date: November 22 nd, 2011 at or before 11:59:59 PM We will design the abstract class we will be using in class, together. The project description will be discussed on Monday and Wednesday. The abstract class and Greenfoot project you will use will be distributed in lab. Monday, Oct. 31st, 2011 University at Buffalo: CSE 113 Instructor: Scott Settembre 10

CHAPTER 6 Section 3 Monday, Oct. 31st, 2011 University at Buffalo: CSE 113 Instructor: Scott Settembre 11

The “break” command Using “break” will tell the computer to run outside of the current block (remember, a block is what is enclosed between “{“ and “}”). For example: int count=0; while (count < 5) { count=count + 1; if (count == 2) break; // when count==2, leave block } displayOutput("count == " + count); Here is the output: count == 2 Thursday, June 16th, 2011 University at Buffalo: EAS 230 Instructor: Scott Settembre 12

switch statment The switch statement really helps organize. switch (Age) { case 0: case 1:// If age == 0 or == 1, then newborn = 1 newborn = 1; can_drive = 0; break; case 2:// If age == 2, then execute next line case 3:// If age == 3, then toddler = 1 toddler = 1; can_drive = 0; break; case 16:// If age == 16, then execute next line case 17:// If age == 17, then child = 1, but can drive child = 1; can_drive = 1; break; default:// If age >= 18, then adult = 1 adult = 1; can_drive = 1; } Question: What happens if Age > 3 and Age < 16? Answer: The default section runs!!! Be careful with switch, you don’t always get what you think! Thursday, June 9th, 2011 University at Buffalo: EAS 230 Instructor: Scott Settembre 13

“break” is needed for switch..case Using “break” is especially important on the switch..case statement. For example, the “default” section will be run after the “< 18” section: int MyAge = 15; switch (MyAge < 18) { case true: displayOutput("You are a child."); default: displayOutput("You are an adult."); } displayOutput("Switch..case complete."); Here is the output: You are a child. You are an adult. Switch..case complete. Thursday, June 16th, 2011 University at Buffalo: EAS 230 Instructor: Scott Settembre 14 You would want to put a “break;” statement here. You are a child. Switch..case complete. To get this output

The “continue” command Using “continue” will tell the computer to restart at the top of the current looping block, performing the conditional check if needed. For example: int count=0; while (count < 3) { count = count + 1; if (count == 2) continue; // when count==2, restart block displayOutput("count == " + count); } displayOutput("Loop complete."); Here is the output: count == 1 count == 3 Loop complete. Thursday, June 16th, 2011 University at Buffalo: EAS 230 Instructor: Scott Settembre 15

This is a counter loop We mostly used the while statement as a “counter” loop to “count” while we did some instructions over and over. We could have also written it like this: int count=0; while (count++ < 3) { // The “++” replaces this line: count=count + 1; displayOutput("count == " + count); } displayOutput("Loop complete."); Here is the output: count == 1 count == 2 count == 3 Loop complete. Tuesday, June 11th, 2011 University at Buffalo: EAS 230 Instructor: Scott Settembre 16

The “for” loop Since counter loops are used so much, there is a quick and easy way to do them, the “for” loop. (sometimes called the “for..next” loop) Here is an example: for (int count=1; count <= 3; count++) { displayOutput("count == " + count); } displayOutput("Loop complete.“); Here is the output: count == 1 count == 2 count == 3 Loop complete. Tuesday, June 11th, 2011 University at Buffalo: EAS 230 Instructor: Scott Settembre 17

Components of a “for” loop You have the keyword “for” followed by an “expression” followed by a “statement” (or block). The expression contains 3 statements – First, a declaration or initialization that is run only once at the beginning of the loop. – Second, a Boolean expression or condition to evaluate to see if the loop should still run. – Lastly, an action to perform, usually an increment or iteration of some sort, performed at the end of the loop. “for” loops are quite nice to use as they cut down on the code clutter. Tuesday, June 28th, 2011 University at Buffalo: EAS 230 Instructor: Scott Settembre 18

Compare the “while” to “for” int count=0; while (count++ < 3) { displayOutput("count == " + count); } displayOutput("Loop complete."); for (int count=1; count <= 3; count++) { displayOutput("count == " + count ); } displayOutput("Loop complete." ); Tuesday, June 28th, 2011 University at Buffalo: EAS 230 Instructor: Scott Settembre 19

A “for” example This code finds the largest number (the Max) in an array: // Define the list and initialize values int MyList[5]={9, 2, 66, -5, 14}; // This will be the max number in the list int MaxNumber=0; // Create a loop to iterate through the list for (int x=0; x < 5; x++) { if (MyList[x] > MaxNumber) MaxNumber=MyList[x]; } // Output the max number displayOutput( MaxNumber ); Tuesday, June 28th, 2011 University at Buffalo: EAS 230 Instructor: Scott Settembre 20