CS 121 Engineering Computation Lab

CS 122 Engineering Computation Lab
Lab 4
Dan De Sousa and Bruce Char
Department of Computer Science
Drexel University
February 2009
©By the author. All rights reserved. Permission is given to CS122 Winter
2009 staff and students to use and reproduce these notes for their own use.
Your class instructor and TA
• Instructor for this section:
Office:
Email:
Telephone:
• Your TAs are:
Announcements
• You may show us your completed Lab 3,
Part 2.3 for points
• This is the last lab of the term
• Proficiency exam next time we meet
Lab Parts
• Part 1, Sections 1.1-1.3
– Loops, If Statements, Plots
• Part 2, Sections 2.1-2.4
– Animations and Motion
– 2.4 Must Be Explained
Lecture Overview
• If Statements
• If
• If Else
• If Elif ... Else
• Boolean operations
If Statements
• If statements allow programmers to
choose different paths to follow in code,
depending on the condition.
• If <x> is true, do this.
Sample Syntax:
if <condition> then
<instruction 1>;
<instruction 2>;
…
<instruction n>;
end if;
If Statement Example
If a is less than or equal to b, add a and b together.
If Statements
• If statements are different from loops.
• Loops repeat while a condition is true.
• If statements perform an action once if a
condition is true.
• Also have the ability to branch off into
multiple conditions.
If-Else
Sample Syntax:
if <condition> then
<instruction 1>;
<instruction 2>;
…
<instruction n>;
else
<instruction 1>;
<instruction 2>;
…
<instruction n>;
end if;
• If condition is true,
perform the first set of
instructions
• Otherwise, perform
the other set of
instructions
If-Else Example
If-Elif-…-Else
Sample Syntax:
if <condition> then
<instructions>;
elif <condition> then
<instructions>;
elif <condition> then
<instructions>;
:
:
else
<instructions>;
end if;
• If condition is true,
perform the first set of
instructions.
• Otherwise if the
second is true, perform
the second set.
• So on until we get to
the end.
If-Elif-...-Else
• If’s / Elif’s are processed in order from top
to bottom.
• Similar to a piecewise, but we can specify
many instructions.
• Good when we have many different
conditions and the actions are different.
If-Elif-…-Else Example
Boolean Operations
• Until now, we’ve only needed to specify one
condition in our loops and if statements.
• What if the condition depends on two things?
• Example:
• Do something if x greater than 0 and x less
than 100.
Boolean Operations
• We can modify Boolean expressions in three
ways: and, or, and not operations.
• We can use these operators in if statements, as
well as for and while loops.
• Saw these operations in piecewise functions
• The result of each of these expressions:
a and b: True only if both a and b are true
a or b: True if at least one of a or b is true
not a: Inverts (takes opposite of) the value of a
‘and’ / ‘or’
• We have two keywords we can use to group
conditions together.
• and
• or
• We say: if (x > 0 and x < 100) then … end if:
Both Must Be True
One Must Be True
a and b
a
a or b
a
a
True
False
a
True
False
b
True
True
False
b
True
True
False
b
False
False
False
b
False
False
False
Example with ‘and’
Find the number of B’s and D’s.
Example with ‘or’
Finds the number of out of bounds errors.
Proficiency Exam Information
Winter 2009
Proficiency Exam
• In class exam, during regular class hour
• The exam counts for approximately 36% of
your final grade
– The exam will be in two Maple TA quizzes.
One quiz will have How did I do? Turned on.
One part will have it turned off. The part
where it is turned off will be the multiple choice
or similar questions where getting feedback
would make the question useless from an
evaluation viewpoint.
Proficiency Exam
• For the exam, you will do two tests in
Maple TA.
• One quiz will have How did I do? turned
on.
• One part will have it turned off. The part
where it is turned off will be the multiple
choice or similar questions where getting
feedback would make the question useless
from an evaluation viewpoint.
Proficiency Exam
• Questions for the exam will be drawn from past
quizzes, and from a small set of new questions.
• This means that everyone will know what the
questions could be, ahead of time. They will
also be able to prepare a plan for answering
them, ahead of time.
Practicing
• All questions will be posted on Maple TA in
practice form starting Wednesday March 4 and
running through the exam period.
• Lab Solutions will be available on Blackboard
Vista at that time.
• For exam security, we will turn off access to the
practice quizzes while exams are being run in
the labs.
• Access to Blackboard Vista will be turned off
during the exam, as well.
Exam Security
• During the exam
•You must use the laptop (be it Mac or Windows)
provided. You may not use your own computer.
•You may use
•Maple
•Maple TA
•Browse
www.cs.drexel.edu/complab/cs122/winter2009 ,
which has copies of the lab directions and lecture
notes.
•No notes or other aids
•Blackboard access to the course turned off during the
exam
Exam security
• Computer usage will be monitored, both by
visual checks by course staff and by software
monitoring built into the computers you use.
• Unlike the labs, we will be in full “Big Brother”
mode during the exam: We will be able to watch
what you do, log every key stroke and mouse
click, and take movies and screenshots of what
you are doing.
A reminder about cheating
•Unauthorized access to information for the exam
will be a violation of the Academic Honesty policy.
So will accessing unauthorized information nonelectronically or any other form of cheating.
•The minimum penalty will be a reduction in the final
grade for the course.
•We reserve the right to give you a course grade of
F with no opportunity to withdraw, or to begin
proceedings to expel you from the university.
•If you have concerns about your grade for the
course, talk to your instructor.
Proficiency Exam Policy
• If you have a conflict or are unable to
attend the scheduled exam due to a
reasonable medical or personal excuse,
you should contact your section instructor
and arrange an alternative time as soon as
possible.
• If you miss your exam and delay
contacting your instructor until after the
proficiency exam week has passed, our
policy will be to give you a zero for the
exam.
What you should do now
• Connect to class web page:
www.cs.drexel.edu/complab
• Start up Maple 12
• Read Lab 4 directions.
• Do the work with your partner(s). Both
should try to do the work, but the grader
will need to look at only one answer to
give you credit for doing the problem.
Finishing up – save files
• Make sure your name/user id/section number/
date,time/instructor name are on the verification sheet.
• Get the verification sheet signed and handed in.
• Save worksheet on desktop if you haven’t done so
already. You can call the file “MyLab4CS122”. This will
create a file called MyLab4CS122.mw.
• Submit a copy to Blackboard site.
• Email a copy to yourself and/or your lab partners as an
attachment so you can look at what you did for review
purposes later.
• .mw file should open correctly on any Maple 12 (Mac,
Windows, Linux) – file format is portable across system
types.
Next week – Take quiz 4!
• Take the fourth quiz!
• Go to CLC if you need face-to-face help!
• Don’t wait until the last minute to start the
work!
• Prepare for the proficiency exam!