cs 122 engineering computation lab lab 4 dan de sousa and bruce char department of computer science...

29
CS 122 Engineering Computation Lab Lab 4 Dan De Sousa and Bruce Char Department of Computer Science Drexel University Summer 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.

Upload: dwain-robertson

Post on 19-Jan-2016

215 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: CS 122 Engineering Computation Lab Lab 4 Dan De Sousa and Bruce Char Department of Computer Science Drexel University Summer 2009 ©By the author. All rights

CS 122 Engineering Computation Lab Lab 4

Dan De Sousa and Bruce CharDepartment of Computer Science

Drexel UniversitySummer 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.

Page 2: CS 122 Engineering Computation Lab Lab 4 Dan De Sousa and Bruce Char Department of Computer Science Drexel University Summer 2009 ©By the author. All rights

Your class instructor and TA

• Instructor for this section: Office: Email: Telephone:

• Your TAs are:

Page 3: CS 122 Engineering Computation Lab Lab 4 Dan De Sousa and Bruce Char Department of Computer Science Drexel University Summer 2009 ©By the author. All rights

Remaining Activities

• Lab - Today

• No quiz this week

• Proficiency exam – Wednesday (in class)

Page 4: CS 122 Engineering Computation Lab Lab 4 Dan De Sousa and Bruce Char Department of Computer Science Drexel University Summer 2009 ©By the author. All rights

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

Page 5: CS 122 Engineering Computation Lab Lab 4 Dan De Sousa and Bruce Char Department of Computer Science Drexel University Summer 2009 ©By the author. All rights

Lecture Overview

• If Statements

• If

• If Else

• If Elif ... Else

• Boolean operations

Page 6: CS 122 Engineering Computation Lab Lab 4 Dan De Sousa and Bruce Char Department of Computer Science Drexel University Summer 2009 ©By the author. All rights

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;

Page 7: CS 122 Engineering Computation Lab Lab 4 Dan De Sousa and Bruce Char Department of Computer Science Drexel University Summer 2009 ©By the author. All rights

If Statement Example

If a is less than or equal to b, add a and b together.

Page 8: CS 122 Engineering Computation Lab Lab 4 Dan De Sousa and Bruce Char Department of Computer Science Drexel University Summer 2009 ©By the author. All rights

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.

Page 9: CS 122 Engineering Computation Lab Lab 4 Dan De Sousa and Bruce Char Department of Computer Science Drexel University Summer 2009 ©By the author. All rights

If-ElseSample 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

Page 10: CS 122 Engineering Computation Lab Lab 4 Dan De Sousa and Bruce Char Department of Computer Science Drexel University Summer 2009 ©By the author. All rights

If-Else Example

Page 11: CS 122 Engineering Computation Lab Lab 4 Dan De Sousa and Bruce Char Department of Computer Science Drexel University Summer 2009 ©By the author. All rights

If-Elif-…-ElseSample 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.

Page 12: CS 122 Engineering Computation Lab Lab 4 Dan De Sousa and Bruce Char Department of Computer Science Drexel University Summer 2009 ©By the author. All rights

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.

Page 13: CS 122 Engineering Computation Lab Lab 4 Dan De Sousa and Bruce Char Department of Computer Science Drexel University Summer 2009 ©By the author. All rights

If-Elif-…-Else Example

Page 14: CS 122 Engineering Computation Lab Lab 4 Dan De Sousa and Bruce Char Department of Computer Science Drexel University Summer 2009 ©By the author. All rights

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.

Page 15: CS 122 Engineering Computation Lab Lab 4 Dan De Sousa and Bruce Char Department of Computer Science Drexel University Summer 2009 ©By the author. All rights

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

Page 16: CS 122 Engineering Computation Lab Lab 4 Dan De Sousa and Bruce Char Department of Computer Science Drexel University Summer 2009 ©By the author. All rights

‘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:

True False

True True False

False False False

a and b a or ba

b

a

b

True False

True True False

False False False

a

b

a

b

Both Must Be True One Must Be True

Page 17: CS 122 Engineering Computation Lab Lab 4 Dan De Sousa and Bruce Char Department of Computer Science Drexel University Summer 2009 ©By the author. All rights

Example with ‘and’

Find the number of B’s and D’s.

Page 18: CS 122 Engineering Computation Lab Lab 4 Dan De Sousa and Bruce Char Department of Computer Science Drexel University Summer 2009 ©By the author. All rights

Example with ‘or’

Finds the number of out of bounds errors.

Page 19: CS 122 Engineering Computation Lab Lab 4 Dan De Sousa and Bruce Char Department of Computer Science Drexel University Summer 2009 ©By the author. All rights

Proficiency Exam Information

Winter 2009

Page 20: CS 122 Engineering Computation Lab Lab 4 Dan De Sousa and Bruce Char Department of Computer Science Drexel University Summer 2009 ©By the author. All rights

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.

Page 21: CS 122 Engineering Computation Lab Lab 4 Dan De Sousa and Bruce Char Department of Computer Science Drexel University Summer 2009 ©By the author. All rights

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.

Page 22: CS 122 Engineering Computation Lab Lab 4 Dan De Sousa and Bruce Char Department of Computer Science Drexel University Summer 2009 ©By the author. All rights

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.

Page 23: CS 122 Engineering Computation Lab Lab 4 Dan De Sousa and Bruce Char Department of Computer Science Drexel University Summer 2009 ©By the author. All rights

Practicing

• All questions will be posted on Maple TA in practice form starting Tuesday July 20 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.

Page 24: CS 122 Engineering Computation Lab Lab 4 Dan De Sousa and Bruce Char Department of Computer Science Drexel University Summer 2009 ©By the author. All rights

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

Page 25: CS 122 Engineering Computation Lab Lab 4 Dan De Sousa and Bruce Char Department of Computer Science Drexel University Summer 2009 ©By the author. All rights

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.

Page 26: CS 122 Engineering Computation Lab Lab 4 Dan De Sousa and Bruce Char Department of Computer Science Drexel University Summer 2009 ©By the author. All rights

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 non-electronically 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.

Page 27: CS 122 Engineering Computation Lab Lab 4 Dan De Sousa and Bruce Char Department of Computer Science Drexel University Summer 2009 ©By the author. All rights

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 aspossible.

• 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.

Page 28: CS 122 Engineering Computation Lab Lab 4 Dan De Sousa and Bruce Char Department of Computer Science Drexel University Summer 2009 ©By the author. All rights

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.

Page 29: CS 122 Engineering Computation Lab Lab 4 Dan De Sousa and Bruce Char Department of Computer Science Drexel University Summer 2009 ©By the author. All rights

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.