Presentation is loading. Please wait.

Presentation is loading. Please wait.

CS122 Engineering Computation Lab Lab 2 Bruce Char Department of Computer Science Drexel University Winter 2012.

Similar presentations


Presentation on theme: "CS122 Engineering Computation Lab Lab 2 Bruce Char Department of Computer Science Drexel University Winter 2012."— Presentation transcript:

1 CS122 Engineering Computation Lab Lab 2 Bruce Char Department of Computer Science Drexel University Winter 2012

2 Review of Lab 1 Cycle Lab 1 – pre lab quizlet, lab 1 and quiz 1 completed along with pre lab 2 quizlet –Quiz grades to be issued this week –More usage of CLC noticed than in cs121 Initial lab completion session held on 1/24 – about 112 attendees Major Lab 1 concepts to remember –Use of code edit regions to develop, test and debug scripts –Use of Car Simulator API to learn about “while” loops

3 Administrative Notes Please contact your individual instructors with questions and problems CLC (room 147 UC) will be staffed at same times as for cs121 in Fall (odd weeks) In order to be eligible for a lab completion session, please see you instructor at the end of the lab period In order to be eligible for a makeup lab session, you must contact your instructor for permission as soon as you miss your regularly scheduled lab Extra Consultation sessions –If you have not already done so, please apply as per the global email directions (enrollment ends on Friday, 2/3) –Students with B or lower in cs121 eligible –1 st session on Tuesday, 2/7

4 Lab 2 Overview Based on materials from Chapter 10, 11 and 12 readings –More practice using the Car Simulator API to simulate engr102 robot lab manipulations Additional usage of simple and nested “while” loops and counter variables –Repetitive action “for” loops – chapter 12 –Using “if” statements to make decisions – also from chapter 12

5 Lab 2 Overview – Part 0 Part 0 exercises include: –A – introduction to “for” loops –B – introduction to “if” statements –C – review of Lab 1 Car Simulator exercise (Problem 5 – moving to the nth gap) – comparing “while” and “for” loop based solutions In this lab’s Part 0, we will focus on analyzing and comparing existing code solutions as opposed to developing and running code

6 Lab 2 Overview Problem 1 – moving in a figure 8 Problem 2 – recognizing a 4 way intersection Problem 3 – moving on a diagonal Problem 4 – moving around a barrier to a target

7 Lab 2 programming concepts Nested loop constructs Using both “while” and “for” loops Introduction to “for” and “if” Advanced techniques for specifying conditions –Used in both “while” loop and “if” statement constructs –Emphasis on boolean operators “and” and “or”

8 Lab 2 programming concepts Nested loop constructs In lab 1 – moving in a square problem (1) –Outer loop  loop over 4 sides »Inner loop  create 1 side by “move(1)” In lab 1 – nth gap problem (5) – outer loop  loop over n or n-1 gaps »Inner loop  move(1) until you get to a gap Nested loop opportunity in lab 2 –Problem 1 – figure 8 (using 2 squares)

9 Lab 2 programming concepts “for” loop introduction –Appropriate to use when the number of loop iterations is known prior to loop entry Ex – move(1) n times to trace the side of a square Ex – loop 4 times to trace all 4 sides of a square Ex – loop over a list of elements where “nops” defines the loop size –Basic syntax for i from 1 to n do –Loop action end do; –Will demo with introductory examples in Part 0

10 Lab 2 programming concepts “if” statement introduction –Enables a program to selectively execute code only if a condition is true –Basic “if” syntax if (condition) then –Action to execute if condition is true end if; –We will cover additional variants of the “if” later if – else if – elif - else –Will demo with introductory examples in Part 0

11 Lab 2 programming concepts Constructing conditions –while (condition) do –if (condition) then Value of condition is always “true” or “false” In Lab 1: –while isTouching(d, ‘bt’) do move(1); –end do; Also  not isTouching(d,’bt’)  if not touching a barrier is true, then keep moving – not at the target yet

12 Lab 2 programming concepts Constructing conditions –while (condition) do –if (condition) then In lab 2: –Problem 2 – detecting a 4 way intersection while (isTouching(0,’bt’) or isTouching(Pi/2,’bt’) or etc……. –If any side of the car is touching any wall, then keep moving – you are not at an intersection Use “and” instead of “or” if you want to check if touching several walls –Problem 3 (diagonal step movement) printing message when number of steps exceeds 10 –if (stepcount = 11) then # set to 11 if you are testing within the loop »Print(“some message”) –end if;

13 Course activities next week (2/6-2/12) Quiz 2 will be released on Friday (2/3) at 6 PM –Deadline: Thursday (2/9) at 4:30 PM –Makeup quiz – from Friday (2/10) at 9 AM through Sunday (2/12) at 11:00 PM 30% penalty Pre-lab 3 quizlet –From Thursday (2/9 – noon) through Monday (2/13 – 8 AM) Be sure to visit the CLC for quiz assistance


Download ppt "CS122 Engineering Computation Lab Lab 2 Bruce Char Department of Computer Science Drexel University Winter 2012."

Similar presentations


Ads by Google