Presentation is loading. Please wait.

Presentation is loading. Please wait.

CS 123 Lab 4 Instructor: Mark Boady Course Designer: Professor Bruce Char Department of Computer Science Drexel University Spring 2013.

Similar presentations


Presentation on theme: "CS 123 Lab 4 Instructor: Mark Boady Course Designer: Professor Bruce Char Department of Computer Science Drexel University Spring 2013."— Presentation transcript:

1 CS 123 Lab 4 Instructor: Mark Boady Course Designer: Professor Bruce Char Department of Computer Science Drexel University Spring 2013

2 Administrative Notes Please send your instructor your AVL form immediately if you are eligible for extended time for the Proficiency Exam Please also review your bbLearn Lab and Quiz grades and report any discrepancies to your instructor As with cs121 and cs122, there will be an opportunity to earn a 2% bonus for submitting a student evaluation. Details to follow! The lab 4 makeup lab will be moved to Tuesday, 5/28 due to the Memorial Day holiday on 5/27 – Room to be determined

3 Example New Question You can find the slope of a line from two points using the following formula: (y2-y1)/(x2-x1) Create a procedure slope:=proc(x1,y1,x2,y2) that returns the slope of the line. For example, slope(0,0,1,1) should return 1 Submit the Procedure

4 Proficiency Exam Preview Same logistics as in cs121 and cs122 – Proctored format – Two quizzes (25 and 70 minutes) – Sign-in and score verification To be conducted during week of June 3rd (week 10) in class for your regularly scheduled lab session Practice – week of May 27 (week 9) – All 4 quizzes and quizlets taken throughout the term will be re-posted on Tuesday, 5/28 – note that quiz 4 will take place during week 9 – A special quiz containing some problems not included in regular quizzes will also be issued – these questions are candidates for inclusion – A problem to develop a simple proc will also be included. It will be original and not from any of the quizzes. – Full quiz week (9) CLC coverage – Monday through Friday Graduating seniors are NOT exempt from the proficiency exam!!

5 Quiz Week (9) Activities Quiz 4 will be released on Friday (5/24) at 6 PM – Deadline: Thursday (5/30) at 4:30 PM – Makeup quiz – from Friday (5/31) at 9 AM through Sunday (6/2) at 11:00 PM 30% penalty No Pre-lab quizlet Be sure to visit the CLC for quiz assistance and use the quiz tips as needed. Practice week for Proficiency Exam – Will be posting practice quizzes on Tuesday, 5/28 – Exam to be conducted during week of June 3 (week 10 - final week of regular classes)

6 Programming is the same in any language Variables Procedure/functions Loops (for and while) Conditions (if statements) The next slides will show the Rabbit Problem from CS 122 in a number of different languages. You should see similarities to what you learned in Maple

7 Maple bunnies:=proc(year) local a,b,g,s,initial_rabbits,initial_foxes,r,f,i,nextr,nextf; a:=0.04; b:=5e-4; g:=0.2; s:=5e-5; initial_rabbits:=5891; initial_foxes:=16; r:=initial_rabbits; f:=initial_foxes; for i from 1 to year do nextr := r+floor(r*(a-b*f)); nextf := f-floor(f*(g-s*r)); r:=nextr; f:=nextf; end do: return [r,f]; end proc; bunnies(99);

8 Matlab function [ r,f ] = bunnies( year ) a = 0.04; b = 5e-4; g = 0.2; s = 5e-5; initial_rabbits=5891; initial_foxes=16; r=initial_rabbits; f=initial_foxes; for i=1:year nextr = r+floor(r*(a-b*f)); nextf = f-floor(f*(g-s*r)); r=nextr; f=nextf; end; end [r,f]=bunnies(99)

9 PHP function bunnies($years) { $a=0.04; $b=5e-4; $g=0.2; $s=5e-5; $initial_rabbits=5891; $initial_foxes=16; $r=$initial_rabbits; $f=$initial_foxes; for($i=1; $i <= $years; $i++) { $nextr = $r+floor($r*($a-$b*$f)); $nextf = $f-floor($f*($g-$s*$r)); $r=$nextr; $f=$nextf; } return array($r,$f); } echo print_r(bunnies(99));

10 C++ void bunnies(int years) { float a=0.04; float b=5e-4; float g=0.2; float s=5e-5; float initial_rabbits=5891; float initial_foxes=16; float r=initial_rabbits; float f=initial_foxes; for(int i=1; i <= years; i++) { float nextr = r+floor(r*(a-b*f)); float nextf = f-floor(f*(g-s*r)); r=nextr; f=nextf; } cout << r << ", " << f << endl; } //For simplicity the result is printed to the screen

11 Java static ArrayList bunnies(int years) { double a=0.04; double b=5e-4; double g=0.2; double s=5e-5; double initial_rabbits = 5891; double initial_foxes = 16; double r=initial_rabbits; double f=initial_foxes; for(int i=1; i <= years; i++) { double nextr = r+Math.floor(r*(a-b*f)); double nextf = f-Math.floor(f*(g-s*r)); r=nextr; f=nextf; } ArrayList res= new ArrayList (); res.add(new Integer( (int)(r))); res.add(new Integer( (int)(f))); return res; } System.out.println(bunnies(99));

12 Conclusions Topics in CS 121-123 are in every programming language The following concepts were in each example Variable creation Assignment For Loops Procedure Definitions Return results Formal Parameters

13 Bounce Game API Game API – 3 key functions available – createTarget(x,y,w,h) Creates a target area consisting of 2x2 squares – x, y represent the coordinates of the lower left corner of the target area – w, h represent the target area’s width and height – drawBoard(T) Takes the list of target coordinates (T) and creates a plot structure of the target area for display – detectHits(x,y,radius,T) Performs collision detection (number of squares in the target area that have been knocked over) – x, y = coordinates of the center of the ball (disk object) – radius = radius of the ball – T = target list as created by createTarget function


Download ppt "CS 123 Lab 4 Instructor: Mark Boady Course Designer: Professor Bruce Char Department of Computer Science Drexel University Spring 2013."

Similar presentations


Ads by Google