Chapter 3 part 4 Flashcards

1
Q

Lets begin with problem we will break down for the rest of this segment

A

Observations about the program:
- The program must pocess 10 test results. We’ll use a for statement and the range function to control iteration
- Each test result is a number - either 1 or a 2. Each time the program reads a test result, the program must determine if the number is a 1 or a 2. We test for a 1 in our algorithm. If the number is not a 1, we assume that it’s a 2
- We’ll use 2 counters - one to count the number of students who passed the exam and one to count the number of students who failed
- After the script processes all the results, it must decide if more than 8 students passed the exam so that it can bonus the instructor

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Based on the following pseudocode, what would be our first refinement?
Analyze exam results and decide wether instructor should receive a bonus

A

Initialize variables

Input the ten exam grades and count passes and failures

Summarize the exam results and decide whether instructor should receive a bonus

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Based on our first refinement:
Initialize variables

Input the ten exam grades and count passes and failures

Summarize the exam results and decide whether instructor should receive a bonus

What should be our second refinement? (part 1)

A
  • Commit to specific variables
  • Need counters to record the passes and failures, and a variable to store the user input
  • Initialize variables can be refined as follows:

Initialize passes to zero

Initialize failures to zero

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Based on our first refinement:
Initialize variables

Input the ten exam grades and count passes and failures

Summarize the exam results and decide whether instructor should receive a bonus

What should be our second refinement? (part 2)

A
  • Input the ten exam grades and count passes and failures requires a loop that successively inputs the result of each exam
  • We know there are ten results, so the for statement and the range function are appropriate
  • The refinement is

For each of the ten students
…Input the next exam result
…If the student passed
……Add one to passes
…Else
……Add one to failures

Pretend the periods are indentations

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Based on our first refinement:
Initialize variables

Input the ten exam grades and count passes and failures

Summarize the exam results and decide whether instructor should receive a bonus

What should be our second refinement? (part 3)

A
  • Summarize the exam results and decide whether instructor should receive a bonus may be refined as follows:

Display the number of passes
Display the number of failures

If more than 8 students passed
…Display “Bonus to instructor”

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What would be our complete pseudocode algorithm now with everything together?

A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What would be the actual algorithm with everything together?

A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q
A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly