CS 106, Winter 2009 Class 17, Section 4
description
Transcript of CS 106, Winter 2009 Class 17, Section 4
![Page 1: CS 106, Winter 2009 Class 17, Section 4](https://reader036.fdocuments.net/reader036/viewer/2022081520/5681659d550346895dd877a2/html5/thumbnails/1.jpg)
1
CS 106, Winter 2009Class 17, Section 4
Slides by: Dr. Cynthia A. Brown, [email protected] section 4: Dr. Herbert G. Mayer, [email protected]
![Page 2: CS 106, Winter 2009 Class 17, Section 4](https://reader036.fdocuments.net/reader036/viewer/2022081520/5681659d550346895dd877a2/html5/thumbnails/2.jpg)
2
Degrees of Learning
• We talk about “learning” something, but actually there are degrees of learning.
• These were explained in a classification system, called “Bloom’s taxonomy”
• There are six major categories, each dependent on the previous one
![Page 3: CS 106, Winter 2009 Class 17, Section 4](https://reader036.fdocuments.net/reader036/viewer/2022081520/5681659d550346895dd877a2/html5/thumbnails/3.jpg)
3
Bloom’s Taxonomy (1)• Knowledge: Recall data or information.
– Examples: Recite a policy. Quote prices from memory to a customer. Knows the safety rules.
– Key Words: defines, describes, identifies, knows, labels, lists, matches, names, outlines, recalls, recognizes, reproduces, selects, states.
• Comprehension: Understand the meaning, translation, interpolation, and interpretation of instructions and problems. State a problem in one's own words.– Examples: Rewrites the principles of test writing. Explain in one’s own words
the steps for performing a complex task. Translates an equation into a computer spreadsheet.
– Key Words: comprehends, converts, defends, distinguishes, estimates, explains, extends, generalizes, gives examples, infers, interprets, paraphrases, predicts, rewrites, summarizes, translates.
![Page 4: CS 106, Winter 2009 Class 17, Section 4](https://reader036.fdocuments.net/reader036/viewer/2022081520/5681659d550346895dd877a2/html5/thumbnails/4.jpg)
4
Bloom’s taxonomy (2)• Application: Use a concept in a new situation or unprompted use of an
abstraction. Applies what was learned in the classroom into novel situations in the work place.– Examples: Use a manual to calculate an employeeís vacation time. Apply laws of statistics
to evaluate the reliability of a written test.– Key Words: applies, changes, computes, constructs, demonstrates, discovers, manipulates,
modifies, operates, predicts, prepares, produces, relates, shows, solves, uses.• Analysis: Separates material or concepts into component parts so that its
organizational structure may be understood. Distinguishes between facts and inferences. – Examples: Troubleshoot a piece of equipment by using logical deduction. Recognize logical
fallacies in reasoning. Gathers information from a department and selects the required tasks for training.
– Key Words: analyzes, breaks down, compares, contrasts, diagrams, deconstructs, differentiates, discriminates, distinguishes, identifies, illustrates, infers, outlines, relates, selects, separates.
![Page 5: CS 106, Winter 2009 Class 17, Section 4](https://reader036.fdocuments.net/reader036/viewer/2022081520/5681659d550346895dd877a2/html5/thumbnails/5.jpg)
5
Bloom’s taxonomy (3)• Synthesis: Builds a structure or pattern from diverse elements. Put
parts together to form a whole, with emphasis on creating a new meaning or structure.– Examples: Write a company operations or process manual. Design a machine to perform a
specific task. Integrates training from several sources to solve a problem. Revises and process to improve the outcome.
– Key Words: categorizes, combines, compiles, composes, creates, devises, designs, explains, generates, modifies, organizes, plans, rearranges, reconstructs, relates, reorganizes, revises, rewrites, summarizes, tells, writes.
• Evaluation: Make judgments about the value of ideas or materials.– Examples: Select the most effective solution. Hire the most qualified candidate. Explain and
justify a new budget.– Key Words: appraises, compares, concludes, contrasts, criticizes, critiques, defends,
describes, discriminates, evaluates, explains, interprets, justifies, relates, summarizes, supports.
![Page 6: CS 106, Winter 2009 Class 17, Section 4](https://reader036.fdocuments.net/reader036/viewer/2022081520/5681659d550346895dd877a2/html5/thumbnails/6.jpg)
6
Bloom’s Taxonomy Categories
• Knowledge• Comprehension• Application• Analysis• Synthesis• Evaluation
• To be able to actually use knowledge, you have to get to at least the Application stage.
![Page 7: CS 106, Winter 2009 Class 17, Section 4](https://reader036.fdocuments.net/reader036/viewer/2022081520/5681659d550346895dd877a2/html5/thumbnails/7.jpg)
7
Example: Grammar
• Knowledge: I am able to tell you some rules of grammar, but when I actually write something, it might still be grammatically incorrect
• Application: I can use the rules of grammar to write grammatically
![Page 8: CS 106, Winter 2009 Class 17, Section 4](https://reader036.fdocuments.net/reader036/viewer/2022081520/5681659d550346895dd877a2/html5/thumbnails/8.jpg)
8
Business Processes
• Having good processes is important in many business situations– Think about how orders are processed at
McDonald’s. It’s the same at every store all over the world, and they hardly ever make a mistake.
– How is a loan application processed at a bank? Some ill-advised changes led to problems!
![Page 9: CS 106, Winter 2009 Class 17, Section 4](https://reader036.fdocuments.net/reader036/viewer/2022081520/5681659d550346895dd877a2/html5/thumbnails/9.jpg)
9
Our Goal: Process Design
• We want you to actually design a business process
• This means you can apply your knowledge to carry out the steps:– Develop requirements (use cases)– Develop tests based on the requirements– Design the user interface and identify the objects– Design the actual process using typical
components
![Page 10: CS 106, Winter 2009 Class 17, Section 4](https://reader036.fdocuments.net/reader036/viewer/2022081520/5681659d550346895dd877a2/html5/thumbnails/10.jpg)
10
Process Components
• Event-driven structure• A process may involve:– Sequential steps– Encapsulation of sub-processes (procedures and
functions)– Conditional steps (various types of ifs)– Repetition (various types of loops)
![Page 11: CS 106, Winter 2009 Class 17, Section 4](https://reader036.fdocuments.net/reader036/viewer/2022081520/5681659d550346895dd877a2/html5/thumbnails/11.jpg)
11
Learning to Apply Loops
• Assignment 6 is about learning to apply loops• Instead of having you write a program, it has
you experiment with loops and observe their behavior
• You will write one small loop
![Page 12: CS 106, Winter 2009 Class 17, Section 4](https://reader036.fdocuments.net/reader036/viewer/2022081520/5681659d550346895dd877a2/html5/thumbnails/12.jpg)
12
Loop Review
![Page 13: CS 106, Winter 2009 Class 17, Section 4](https://reader036.fdocuments.net/reader036/viewer/2022081520/5681659d550346895dd877a2/html5/thumbnails/13.jpg)
13
For loop
• Repetitions are called loops in VB• A For loop is used when we can determine the
number of repetitions before starting the loopnum = Cint(txtInput.Text)strNum = txtInput.TextlstMult.Items.Clear()Forj = I To 12lstMult.Items.Add(strNum&“ x “ &CStr(j) &“ = “ & _CStr(num * j))Next
![Page 14: CS 106, Winter 2009 Class 17, Section 4](https://reader036.fdocuments.net/reader036/viewer/2022081520/5681659d550346895dd877a2/html5/thumbnails/14.jpg)
14
For loop version 2
• Let’s modify the previous example so it prints a multiplication table up to N * N, instead of going to 12.
num = Cint(txtInput.Text)strNum = txtInput.TextlstMult.Items.Clear()Forj = I To num ‘limits can be numbers, variables or expressionslstMult.Items.Add(strNum&“ x “ &CStr(j) &“ = “ & _CStr(num * j))Next
![Page 15: CS 106, Winter 2009 Class 17, Section 4](https://reader036.fdocuments.net/reader036/viewer/2022081520/5681659d550346895dd877a2/html5/thumbnails/15.jpg)
15
For Loop Syntax
ForcVar = sValToeValstatementsNext
Here cVar is the control variable, sVal is the start value for cVar, and eVal is the end value for cVar
cVar>eVal?
Execute loop statements
Increment cVar
yes
no
cVar = sVal
![Page 16: CS 106, Winter 2009 Class 17, Section 4](https://reader036.fdocuments.net/reader036/viewer/2022081520/5681659d550346895dd877a2/html5/thumbnails/16.jpg)
16
The Do-While Concept
• Sometimes we can’t tell in advance how many times a loop will need to execute
• Or, it might just be clearer to use a logic that checks as we go along
• In that case we can use a Do loop instead of a For loop
![Page 17: CS 106, Winter 2009 Class 17, Section 4](https://reader036.fdocuments.net/reader036/viewer/2022081520/5681659d550346895dd877a2/html5/thumbnails/17.jpg)
17
Do-while example• Let’s try the same program we did with the For loop, but
this time with a Do-While loop
num = Cint(txtInput.Text)strNum = txtInput.TextlstMult.Items.Clear()j = 1Do While j<= 12lstMult.Items.Add(strNum&“ x “ &CStr(j) &“ = “ & _CStr(num * j))j = j + 1 ‘what would happen if I forgot this line?Loop
![Page 18: CS 106, Winter 2009 Class 17, Section 4](https://reader036.fdocuments.net/reader036/viewer/2022081520/5681659d550346895dd877a2/html5/thumbnails/18.jpg)
18
Do-while example• Here’s the n by n version
num = Cint(txtInput.Text)strNum = txtInput.TextlstMult.Items.Clear()j = 1Do While j<= num ‘note the upper bound is now a variablelstMult.Items.Add(strNum&“ x “ &CStr(j) &“ = “ & _CStr(num * j))j = j + 1 Loop
• What happens if num = 0?
![Page 19: CS 106, Winter 2009 Class 17, Section 4](https://reader036.fdocuments.net/reader036/viewer/2022081520/5681659d550346895dd877a2/html5/thumbnails/19.jpg)
19
Do Loop Syntax (While)
Do While conditionstatement(s)Loop
(Loop statements may never be done.)
Condition true?
Execute statements within the loop.
Execute statementsthat follow the loop.
No
Yes
![Page 20: CS 106, Winter 2009 Class 17, Section 4](https://reader036.fdocuments.net/reader036/viewer/2022081520/5681659d550346895dd877a2/html5/thumbnails/20.jpg)
20
Do Loop Syntax (Until)
Dostatement(s)Loop Until condition
(Loop statements are always done at least once.)
Condition true?
Execute statements within the loop.
Execute statementsthat follow the loop.
No
Yes
![Page 21: CS 106, Winter 2009 Class 17, Section 4](https://reader036.fdocuments.net/reader036/viewer/2022081520/5681659d550346895dd877a2/html5/thumbnails/21.jpg)
21
BREAK
10 minutes
![Page 22: CS 106, Winter 2009 Class 17, Section 4](https://reader036.fdocuments.net/reader036/viewer/2022081520/5681659d550346895dd877a2/html5/thumbnails/22.jpg)
22
Nested Loops
• Remember how if statements can be “nested”: you can have an if inside another if
• We can also put whatever we want inside a loop, including another loop
• If we do this, the inner loop is executed completely, for all of its repetitions, each time the outer loop is executed once.
![Page 23: CS 106, Winter 2009 Class 17, Section 4](https://reader036.fdocuments.net/reader036/viewer/2022081520/5681659d550346895dd877a2/html5/thumbnails/23.jpg)
23
Example: Complete Multiplication Table
Dim j, k As IntegerDim tableLine As StringFor j = 1 To 12
tableLine = “”For k = 1 To 12
tableLine = tableLine & CStr( j ) & “ x “ _& CStr( k ) & “ = “ & CStr( j * k ) & “ “
Next ‘klstMult.Items.Add( tableLine )
Next ‘j
![Page 24: CS 106, Winter 2009 Class 17, Section 4](https://reader036.fdocuments.net/reader036/viewer/2022081520/5681659d550346895dd877a2/html5/thumbnails/24.jpg)
24
Recursion
• Recursion is a powerful technique for thinking about a process
• It can be used to simulate a loop, or for many other kinds of applications
• In recursion, a function or procedure calls itself• Obviously, there is a danger of an infinite regress,
so there has to be a test for stopping it, and something (usually a parameter) must change between calls