cs 123 lab 4 instructor: mark boady course designer: professor bruce char department of computer...
TRANSCRIPT
CS 123 Lab 4Instructor: Mark Boady
Course Designer: Professor Bruce Char
Department of Computer Science
Drexel University
Spring 2013
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
Example New QuestionYou 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
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!!
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)
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
Maplebunnies:=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 donextr := 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);
Matlabfunction [ 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)
PHPfunction 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));
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
Javastatic ArrayList<Integer> 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<Integer>();res.add(new Integer( (int)(r)));res.add(new Integer( (int)(f)));return res;
}System.out.println(bunnies(99));
ConclusionsTopics in CS 121-123 are in every programming
language
The following concepts were in each exampleVariable creationAssignmentFor LoopsProcedure DefinitionsReturn resultsFormal Parameters
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