Download Counter < B

Document related concepts

Boolean satisfiability problem wikipedia , lookup

Transcript
Homework 7- Problem 1
 Write a pseudocode and draw a flowchart for a program that reads two integer
numbers A&B from the user, then calculates and prints 𝐴𝐡 ( A raised to the power
of B).
 Construct a tracing table for the flowchart mentioned above, assuming that the
user has entered A=3, B=4.
Homework 7- Problem 1-Think Logically
If you want to solve a problem, you should ask yourself these questions:
β€’ What is the input of the problem? A, B (2 integer numbers)
β€’ What is the output of the problem? 𝐴𝐡
β€’ What are processes that could be applied on the input to get the output.
Repeated multiplication : A*A*….*A (B times)
β€’ Do I need selection & repetition structures? If yes, where and how?
We need a repetition structure.
β€’ What are the variables that I may need to use?
o
Variable(s) for storing the input: A,B.
o
Variable(s) for storing the output: Result
o
Variable(s) for counting (if you have a repetition): Counter
o
Intermediate variable(s) for the simplification of calculations: no need
Homework 7- Problem 1-Think Logically
When you want to construct a FOR structure, you should find the answers for these
questions:
1. What is the maximum number of repetition? Let us keep it in a vaiable named
MaxR.
2. What is the initial value of the counter? Let us keep it in a vaiable named Counter.
3. What is the logical condition (the condition of repetition)?
4. How to update the Counter?, shoud I increment or drcrement the Counter after
each iteration? (We have MaxR iterations)
5. What are the actions that should be repeated?
Counter = initial value
True
Logical Test
(Repetition condition)
False
Actions to be
repeated
Counter = Counter - 1
Or
Counter = Counter +1
Homework 7- Problem 1-Think Logically
 Write a pseudocode and draw a flowchart for a program that reads two integer
numbers A&B from the user, then calculates and prints 𝐴𝐡 ( A raised to the power
of B).
Questions to answer before you start:
1. What is the maximum number of
repetition?
Homework 7- Problem 1-Think Logically
 Write a pseudocode and draw a flowchart for a program that reads two integer
numbers A&B from the user, then calculates and prints 𝐴𝐡 ( A raised to the power
of B).
Questions to answer before you start:
1. What is the maximum number of
repetition?
B
2. What is the initial value of the counter?
Homework 7- Problem 1-Think Logically
 Write a pseudocode and draw a flowchart for a program that reads two integer
numbers A&B from the user, then calculates and prints 𝐴𝐡 ( A raised to the power
of B).
Questions to answer before you start:
1. What is the maximum number of
repetition?
B
2. What is the initial value of the counter?
Counter = 0
3. What is the condition of repetition?
Homework 7- Problem 1-Think Logically
 Write a pseudocode and draw a flowchart for a program that reads two integer
numbers A&B from the user, then calculates and prints 𝐴𝐡 ( A raised to the power
of B).
Questions to answer before you start:
1. What is the maximum number of
repetition?
B
2. What is the initial value of the counter?
Counter = 0
3. What is the condition of repetition?
Counter < B
4. Shoud I increment or drcrement the
Counter after each iteration?
Homework 7- Problem 1-Think Logically
 Write a pseudocode and draw a flowchart for a program that reads two integer
numbers A&B from the user, then calculates and prints 𝐴𝐡 ( A raised to the power
of B).
Questions to answer before you start:
1. What is the maximum number of
repetition?
B
2. What is the initial value of the counter?
Counter = 0
3. What is the condition of repetition?
Counter < B
4. Shoud I increment or drcrement the
Counter after each iteration?
Counter = Counter+1
5. What are the actions that should be
repeated?
Homework 7- Problem 1-Think Logically
 Write a pseudocode and draw a flowchart for a program that reads two integer
numbers A&B from the user, then calculates and prints 𝐴𝐡 ( A raised to the power
of B).
Questions to answer before you start:
1. What is the maximum number of
repetition?
B
2. What is the initial value of the counter?
Counter = 0
3. What is the condition of repetition?
Counter < B
4. Shoud I increment or drcrement the
Counter after each iteration?
Counter = Counter+1
5. What are the actions that should be
repeated?
Multiply A with result, and increment
the Counter
Homework 7- Problem 1 Pseudocode
 Write a pseudocode and draw a flowchart for a program that reads two integer
numbers A&B from the user, then calculates and prints 𝐴𝐡 ( A raised to the power
of B).
Questions to answer before you start:
Psudocode:
1. What is the maximum number of
repetition?
Declare A,B, Counter, Result=1
B
2. What is the initial value of the counter?
Counter = 0
3. What is the condition of repetition?
Counter < B
4. Shoud I increment or drcrement the
Counter after each iteration?
Counter = Counter+1
5. What are the actions that should be
repeated?
Multiply A with result, and increment
the Counter
Read A,B
FOR(Counter = 0; Counter < B ; Counter = Counter+1)
Result=Result*A;
ENDFOR
Write Result
Homework 7- Problem 1 Flowchart
 Write a pseudocode and draw a flowchart for a program that reads two integer
numbers A&B from the user, then calculates and prints 𝐴𝐡 ( A raised to the power
of B).
START
Psudocode:
Declare A,B, Counter, Result=1
Read A,B
FOR (Counter = 0; Counter < B ; Counter = Counter+1)
Result=Result*A;
ENDFOR
Write Result
Homework 7- Problem 1 Flowchart
 Write a pseudocode and draw a flowchart for a program that reads two integer
numbers A&B from the user, then calculates and prints 𝐴𝐡 ( A raised to the power
of B).
START
Psudocode:
Declare A,B, Counter, Result=1
Read A,B
FOR (Counter = 0; Counter < B ; Counter = Counter+1)
Result=Result*A;
ENDFOR
Write Result
Declare A,B
Counter=0,
Result=1
Homework 7- Problem 1 Flowchart
 Write a pseudocode and draw a flowchart for a program that reads two integer
numbers A&B from the user, then calculates and prints 𝐴𝐡 ( A raised to the power
of B).
START
Psudocode:
Declare A,B, Counter, Result=1
Declare A,B
Counter=0,
Result=1
Read A,B
FOR (Counter = 0; Counter < B ; Counter = Counter+1)
Result=Result*A;
ENDFOR
Write Result
Read A,B
Homework 7- Problem 1 Flowchart
 Write a pseudocode and draw a flowchart for a program that reads two integer
numbers A&B from the user, then calculates and prints 𝐴𝐡 ( A raised to the power
of B).
START
Declare A,B
Counter=0,
Result=1
Psudocode:
Declare A,B, Counter, Result=1
Read A,B
Read A,B
FOR (Counter = 0; Counter < B ; Counter = Counter+1)
Result=Result*A;
ENDFOR
Write Result
False
Logical
Condition
True
Homework 7- Problem 1 Flowchart
 Write a pseudocode and draw a flowchart for a program that reads two integer
numbers A&B from the user, then calculates and prints 𝐴𝐡 ( A raised to the power
of B).
START
Declare A,B
Counter=0,
Result=1
Psudocode:
Declare A,B, Counter, Result=1
Read A,B
Read A,B
FOR (Counter = 0; Counter < B ; Counter = Counter+1)
Result=Result*A;
ENDFOR
Write Result
False
Counter<B
True
Homework 7- Problem 1 Flowchart
 Write a pseudocode and draw a flowchart for a program that reads two integer
numbers A&B from the user, then calculates and prints 𝐴𝐡 ( A raised to the power
of B).
START
Declare A,B
Counter=0,
Result=1
Psudocode:
Declare A,B, Counter, Result=1
Read A,B
Read A,B
FOR (Counter = 0; Counter < B ; Counter = Counter+1)
Result=Result*A;
ENDFOR
Write Result
False
Counter<B
True
Actions that should
be repeated
Homework 7- Problem 1 Flowchart
 Write a pseudocode and draw a flowchart for a program that reads two integer
numbers A&B from the user, then calculates and prints 𝐴𝐡 ( A raised to the power
of B).
START
Declare A,B
Counter=0,
Result=1
Psudocode:
Declare A,B, Counter, Result=1
Read A,B
Read A,B
FOR (Counter = 0; Counter < B ; Counter = Counter+1)
Result=Result*A;
ENDFOR
Write Result
False
Counter<B
Counter=Counter+1
True
result= result*A
Homework 7- Problem 1 Flowchart
 Write a pseudocode and draw a flowchart for a program that reads two integer
numbers A&B from the user, then calculates and prints 𝐴𝐡 ( A raised to the power
of B).
START
Declare A,B
Counter=0,
Result=1
Psudocode:
Declare A,B, Counter, Result=1
Read A,B
Read A,B
FOR (Counter = 0; Counter < B ; Counter = Counter+1)
Result=Result*A;
ENDFOR
Write Result
False
Counter<B
Counter=Counter+1
Print result
End
True
result= result*A
Homework 7- Problem 1 Tracing Table
Construct a tracing table for the flowchart mentioned above, assuming that the user
has entered A=3, B=4.
START
Declare A,B
Counter=0,
Result=1
Read A,B
False
Counter<B
Counter=Counter+1
Print result
End
True
result= result*A
Homework 7- Problem 1 Tracing Table
Construct a tracing table for the flowchart mentioned above, assuming that the user
has entered A=3, B=4.
Counter <B
A
B
result
counter
START
Declare A,B
Counter=0,
Result=1
Read A,B
False
Counter<B
Counter=Counter+1
Print result
End
True
result= result*A
Homework 7- Problem 1 Tracing Table
Construct a tracing table for the flowchart mentioned above, assuming that the user
has entered A=3, B=4.
Declaration &
Initialization:
Counter <B
A
B
result
counter
?
?
?
1
0
START
Declare A,B
Counter=0,
Result=1
Read A,B
False
Counter<B
Counter=Counter+1
Print result
End
True
result= result*A
Homework 7- Problem 1 Tracing Table
Construct a tracing table for the flowchart mentioned above, assuming that the user
has entered A=3, B=4.
Counter <B
A
B
result
counter
Declaration &
Initialization:
?
?
?
1
0
Input
?
3
4
1
START
Declare A,B
Counter=0,
Result=1
0
Read A,B
False
Counter<B
Counter=Counter+1
Print result
End
True
result= result*A
Homework 7- Problem 1 Tracing Table
Construct a tracing table for the flowchart mentioned above, assuming that the user
has entered A=3, B=4.
Counter <B
A
B
result
counter
Declaration &
Initialization:
?
?
?
1
0
Input
?
3
4
1
0
Itr 1 of
repetition
True
3
4
3
1
START
Declare A,B
Counter=0,
Result=1
Read A,B
False
Counter<B
Counter=Counter+1
Print result
End
True
result= result*A
Homework 7- Problem 1 Tracing Table
Construct a tracing table for the flowchart mentioned above, assuming that the user
has entered A=3, B=4.
Counter <B
A
B
result
counter
Declaration &
Initialization:
?
?
?
1
0
Input
?
3
4
1
0
Itr 1 of
repetition
True
3
4
3
1
Itr 2 of
repetition
True
3
4
9
2
START
Declare A,B
Counter=0,
Result=1
Read A,B
False
Counter<B
Counter=Counter+1
Print result
End
True
result= result*A
Homework 7- Problem 1 Tracing Table
Construct a tracing table for the flowchart mentioned above, assuming that the user
has entered A=3, B=4.
Counter <B
A
B
result
counter
Declaration &
Initialization:
?
?
?
1
0
Input
?
3
4
1
0
Itr 1 of
repetition
True
3
4
3
1
Itr 2 of
repetition
True
3
4
9
2
START
Declare A,B
Counter=0,
Result=1
Read A,B
False
Counter<B
Itr 3 of
repetition
True
3
4
27
3
Counter=Counter+1
Print result
End
True
result= result*A
Homework 7- Problem 1 Tracing Table
Construct a tracing table for the flowchart mentioned above, assuming that the user
has entered A=3, B=4.
Counter <B
A
B
result
counter
Declaration &
Initialization:
?
?
?
1
0
Input
?
3
4
1
0
Itr 1 of
repetition
True
3
4
3
1
Itr 2 of
repetition
True
3
4
9
2
START
Declare A,B
Counter=0,
Result=1
Read A,B
False
Counter<B
Itr 3 of
repetition
True
3
4
27
3
End
Itr 4 of
repetition
True
3
4
81
4
Counter=Counter+1
Print result
True
result= result*A
Homework 7- Problem 1 Tracing Table
Construct a tracing table for the flowchart mentioned above, assuming that the user
has entered A=3, B=4.
Counter <B
A
B
result
counter
Declaration &
Initialization:
?
?
?
1
0
Input
?
3
4
1
0
Itr 1 of
repetition
True
3
4
3
1
Itr 2 of
repetition
True
3
4
9
2
START
Declare A,B
Counter=0,
Result=1
Read A,B
False
Counter<B
Itr 3 of
repetition
True
3
4
27
3
End
Itr 4 of
repetition
True
3
4
81
4
End of
repetition
& output
false
3
4
81
4
Counter=Counter+1
Print result
True
result= result*A
Homework 7- Problem 2
 Write a pseudocode and draw a flowchart for a program that reads an integer
numbers x from the user, then calculates and prints y= 𝑒 π‘₯ +2π‘₯ 3 +1.
Homework 7- Problem 2-Think Logically
If you want to solve a problem, you should ask yourself these questions:
β€’ What is the input of the problem? X (an integer number)
β€’ What is the output of the problem? y= 𝑒 π‘₯ +2π‘₯ 3 +1
β€’ What are processes that could be applied on the input to get the output.
Repeated multiplication: e*e*….*e (X times), addition, multiplication
β€’ Do I need selection & repetition structures? If yes, where and how?
We need repetition and selection (is X negative, positive, or zero ?) structures
β€’ What are the variables that I may need to use?
o
Variable(s) for storing the input: X.
o
Variable(s) for storing the output: Result
o
Variable(s) for counting (if you have a repetition): Counter
o
Intermediate variable(s) for the simplification of calculations: Part1= 𝑒 π‘₯ , Part2=2π‘₯ 3 +1
Homework 7- Problem 2-Think Logically
When you want to construct a FOR structure, you should find the answers for these
questions:
1. What is the maximum number of repetition? Let us keep it in a vaiable named
MaxR.
2. What is the initial value of the counter? Let us keep it in a vaiable named Counter.
3. What is the logical condition (the condition of repetition)?
4. Shoud I increment or drcrement the Counter after each iteration? (we have MaxR
iterations)
5. What are the actions that should be repeated?
Counter = initial value
True
Logical Test
(Repetition condition)
False
Actions to be
repeated
Counter = Counter - 1
Or
Counter = Counter +1
Homework 7- Problem 2-Think Logically
 Write a pseudocode and draw a flowchart for a program that reads an integer
numbers x from the user, then calculates and prints y= 𝑒 π‘₯ +2π‘₯ 3 +1.
Case 1: X >=0
Case 2: X <0
Homework 7- Problem 2-Think Logically
 Write a pseudocode and draw a flowchart for a program that reads an integer
numbers x from the user, then calculates and prints y= 𝑒 π‘₯ +2π‘₯ 3 +1.
Case 1: X >=0
Questions to answer before you start:
1. What is the maximum number of
repetition?
Case 2: X <0
Homework 7- Problem 2-Think Logically
 Write a pseudocode and draw a flowchart for a program that reads an integer
numbers x from the user, then calculates and prints y= 𝑒 π‘₯ +2π‘₯ 3 +1.
Case 1: X >=0
Questions to answer before you start:
1. What is the maximum number of
repetition?
X
2. What is the initial value of the counter?
Case 2: X <0
Homework 7- Problem 2-Think Logically
 Write a pseudocode and draw a flowchart for a program that reads an integer
numbers x from the user, then calculates and prints y= 𝑒 π‘₯ +2π‘₯ 3 +1.
Case 1: X >=0
Questions to answer before you start:
1. What is the maximum number of
repetition?
X
2. What is the initial value of the counter?
Counter = 0
3. What is the condition of repetition?
Case 2: X <0
Homework 7- Problem 2-Think Logically
 Write a pseudocode and draw a flowchart for a program that reads an integer
numbers x from the user, then calculates and prints y= 𝑒 π‘₯ +2π‘₯ 3 +1.
Case 1: X >=0
Questions to answer before you start:
1. What is the maximum number of
repetition?
X
2. What is the initial value of the counter?
Counter = 0
3. What is the condition of repetition?
Counter < X
4. Shoud I increment or drcrement the
Counter after each iteration?
Case 2: X <0
Homework 7- Problem 2-Think Logically
 Write a pseudocode and draw a flowchart for a program that reads an integer
numbers x from the user, then calculates and prints y= 𝑒 π‘₯ +2π‘₯ 3 +1.
Case 1: X >=0
Questions to answer before you start:
1. What is the maximum number of
repetition?
X
2. What is the initial value of the counter?
Counter = 0
3. What is the condition of repetition?
Counter < X
4. Shoud I increment or drcrement the
Counter after each iteration?
Counter = Counter+1
5. What are the actions that should be
repeated?
Case 2: X <0
Homework 7- Problem 2-Think Logically
 Write a pseudocode and draw a flowchart for a program that reads an integer
numbers x from the user, then calculates and prints y= 𝑒 π‘₯ +2π‘₯ 3 +1.
Case 1: X >=0
Questions to answer before you start:
1. What is the maximum number of
repetition?
X
2. What is the initial value of the counter?
Counter = 0
3. What is the condition of repetition?
Counter < X
4. Shoud I increment or drcrement the
Counter after each iteration?
Counter = Counter+1
5. What are the actions that should be
repeated?
Multiply e with Part1, and increment the
Counter
Case 2: X <0
Homework 7- Problem 2-Think Logically
 Write a pseudocode and draw a flowchart for a program that reads an integer
numbers x from the user, then calculates and prints y= 𝑒 π‘₯ +2π‘₯ 3 +1.
Case 1: X >=0
Case 2: X <0
Questions to answer before you start:
Questions to answer before you start:
1. What is the maximum number of
repetition?
1. What is the maximum number of
repetition?
X
2. What is the initial value of the counter?
Counter = 0
3. What is the condition of repetition?
Counter < X
4. Shoud I increment or drcrement the
Counter after each iteration?
Counter = Counter+1
5. What are the actions that should be
repeated?
Multiply e with Part1, and increment the
Counter
Homework 7- Problem 2-Think Logically
 Write a pseudocode and draw a flowchart for a program that reads an integer
numbers x from the user, then calculates and prints y= 𝑒 π‘₯ +2π‘₯ 3 +1.
Case 1: X >=0
Case 2: X <0
Questions to answer before you start:
Questions to answer before you start:
1. What is the maximum number of
repetition?
1. What is the maximum number of
repetition?
X
2. What is the initial value of the counter?
Counter = 0
3. What is the condition of repetition?
Counter < X
4. Shoud I increment or drcrement the
Counter after each iteration?
Counter = Counter+1
5. What are the actions that should be
repeated?
Multiply e with Part1, and increment the
Counter
|X|
2. What is the initial value of the counter?
Homework 7- Problem 2-Think Logically
 Write a pseudocode and draw a flowchart for a program that reads an integer
numbers x from the user, then calculates and prints y= 𝑒 π‘₯ +2π‘₯ 3 +1.
Case 1: X >=0
Case 2: X <0
Questions to answer before you start:
Questions to answer before you start:
1. What is the maximum number of
repetition?
1. What is the maximum number of
repetition?
X
2. What is the initial value of the counter?
Counter = 0
3. What is the condition of repetition?
Counter < X
4. Shoud I increment or drcrement the
Counter after each iteration?
Counter = Counter+1
5. What are the actions that should be
repeated?
Multiply e with Part1, and increment the
Counter
|X|
2. What is the initial value of the counter?
Counter = 0
3. What is the condition of repetition?
Homework 7- Problem 2-Think Logically
 Write a pseudocode and draw a flowchart for a program that reads an integer
numbers x from the user, then calculates and prints y= 𝑒 π‘₯ +2π‘₯ 3 +1.
Case 1: X >=0
Case 2: X <0
Questions to answer before you start:
Questions to answer before you start:
1. What is the maximum number of
repetition?
1. What is the maximum number of
repetition?
X
2. What is the initial value of the counter?
Counter = 0
3. What is the condition of repetition?
Counter < X
4. Shoud I increment or drcrement the
Counter after each iteration?
Counter = Counter+1
5. What are the actions that should be
repeated?
Multiply e with Part1, and increment the
Counter
|X|
2. What is the initial value of the counter?
Counter = 0
3. What is the condition of repetition?
Counter > X
4. Shoud I increment or drcrement the
Counter after each iteration?
Homework 7- Problem 2-Think Logically
 Write a pseudocode and draw a flowchart for a program that reads an integer
numbers x from the user, then calculates and prints y= 𝑒 π‘₯ +2π‘₯ 3 +1.
Case 1: X >=0
Case 2: X <0
Questions to answer before you start:
Questions to answer before you start:
1. What is the maximum number of
repetition?
1. What is the maximum number of
repetition?
X
2. What is the initial value of the counter?
Counter = 0
3. What is the condition of repetition?
Counter < X
4. Shoud I increment or drcrement the
Counter after each iteration?
Counter = Counter+1
5. What are the actions that should be
repeated?
Multiply e with Part1, and increment the
Counter
|X|
2. What is the initial value of the counter?
Counter = 0
3. What is the condition of repetition?
Counter > X
4. Shoud I increment or drcrement the
Counter after each iteration?
Counter = Counter-1
5. What are the actions that should be
repeated?
Homework 7- Problem 2-Think Logically
 Write a pseudocode and draw a flowchart for a program that reads an integer
numbers x from the user, then calculates and prints y= 𝑒 π‘₯ +2π‘₯ 3 +1.
Case 1: X >=0
Case 2: X <0
Questions to answer before you start:
Questions to answer before you start:
1. What is the maximum number of
repetition?
1. What is the maximum number of
repetition?
X
2. What is the initial value of the counter?
Counter = 0
3. What is the condition of repetition?
Counter < X
4. Shoud I increment or drcrement the
Counter after each iteration?
Counter = Counter+1
5. What are the actions that should be
repeated?
Multiply e with Part1, and increment the
Counter
|X|
2. What is the initial value of the counter?
Counter = 0
3. What is the condition of repetition?
Counter > X
4. Shoud I increment or drcrement the
Counter after each iteration?
Counter = Counter-1
5. What are the actions that should be
repeated?
Divide Part1 over e, and decrement the
Counter
Homework 7- Problem 2 Pseudocode
 Write a pseudocode and draw a flowchart for a program that reads an integer
numbers x from the user, then calculates and prints y= 𝑒 π‘₯ +2π‘₯ 3 +1.
Pseudocode:
Declare X, Counter, Part1=1, Part2, Result
Read X
IF (X<0)
THEN
ELSE
ENDIF
Homework 7- Problem 2 Pseudocode
 Write a pseudocode and draw a flowchart for a program that reads an integer
numbers x from the user, then calculates and prints y= 𝑒 π‘₯ +2π‘₯ 3 +1.
Pseudocode:
Declare X, Counter, Part1=1, Part2, Result
Read X
IF (X<0)
THEN
FOR(Counter=0; Counter>X; Counter=Counter-1)
Part1=Part1/e
ENDFOR
ELSE
ENDIF
Homework 7- Problem 2 Pseudocode
 Write a pseudocode and draw a flowchart for a program that reads an integer
numbers x from the user, then calculates and prints y= 𝑒 π‘₯ +2π‘₯ 3 +1.
Pseudocode:
Declare X, Counter, Part1=1, Part2, Result
Read X
IF (X<0)
THEN
FOR(Counter=0; Counter>X; Counter=Counter-1)
Part1=Part1/e
ENDFOR
ELSE
FOR(Counter=0; Counter<X; Counter=Counter+1)
Part1=Part1*e
ENDFOR
ENDIF
Homework 7- Problem 2 Pseudocode
 Write a pseudocode and draw a flowchart for a program that reads an integer
numbers x from the user, then calculates and prints y= 𝑒 π‘₯ +2π‘₯ 3 +1.
Pseudocode:
Declare X, Counter, Part1=1, Part2, Result
Read X
IF (X<0)
THEN
FOR(Counter=0; Counter>X; Counter=Counter-1)
Part1=Part1/e
ENDFOR
ELSE
FOR(Counter=0; Counter<X; Counter=Counter+1)
Part1=Part1*e
ENDFOR
ENDIF
Part2=2*X*X*X+1
Result=Part1+Part2
Write Result
Homework 7- Problem 2 Flowchart
Declare X, Counter, Part1=1, Part2, Result
Read X
START
Declare X, Counter=0,
Part1=1,Part2,Result
IF (X<0)
THEN
FOR(Counter=0; Counter>X; Counter=Counter-1)
Part1=Part1/e
ENDFOR
ELSE
FOR(Counter=0; Counter<X; Counter=Counter+1)
Part1=Part1*e
ENDFOR
ENDIF
Part2=2*X*X*X+1
Result=Part1+Part2
Write Result
Read X
Homework 7- Problem 2 Flowchart
START
Declare X, Counter, Part1=1, Part2, Result
Read X
Declare X, Counter=0,
Part1=1,Part2,Result
IF (X<0)
Read X
THEN
FOR(Counter=0; Counter>X; Counter=Counter-1)
Part1=Part1/e
ENDFOR
ELSE
FOR(Counter=0; Counter<X; Counter=Counter+1)
Part1=Part1*e
ENDFOR
ENDIF
Part2=2*X*X*X+1
Result=Part1+Part2
Write Result
True
X<0
False
Homework 7- Problem 2 Flowchart
START
Declare X, Counter, Part1=1, Part2, Result
Declare X, Counter=0,
Part1=1,Part2,Result
Read X
IF (X<0)
Read X
THEN
True
FOR(Counter=0; Counter>X; Counter=Counter-1)
Part1=Part1/e
ENDFOR
ELSE
Counter>X
True
Part1= Part1/e
FOR(Counter=0; Counter<X; Counter=Counter+1)
Part1=Part1*e
ENDFOR
ENDIF
Part2=2*X*X*X+1
Result=Part1+Part2
Write Result
Counter=Counter-1
X<0
False
Homework 7- Problem 2 Flowchart
START
Declare X, Counter, Part1=1, Part2, Result
Declare X, Counter=0,
Part1=1,Part2,Result
Read X
IF (X<0)
Read X
THEN
True
FOR(Counter=0; Counter>X; Counter=Counter-1)
X<0
False
Part1=Part1/e
ENDFOR
ELSE
Counter>X
True
Part1= Part1/e
Counter<X
True
Part1= Part1*e
FOR(Counter=0; Counter<X; Counter=Counter+1)
Part1=Part1*e
ENDFOR
ENDIF
Part2=2*X*X*X+1
Result=Part1+Part2
Write Result
Counter=Counter-1
Counter=Counter+1
Homework 7- Problem 2 Flowchart
START
Declare X, Counter, Part1=1, Part2, Result
Declare X, Counter=0,
Part1=1,Part2,Result
Read X
IF (X<0)
Read X
THEN
True
FOR(Counter=0; Counter>X; Counter=Counter-1)
Part1=Part1/e
ENDFOR
ELSE
Counter>X
False
X<0
False
False
Counter<X
True
True
Part1= Part1/e
Part1= Part1*e
FOR(Counter=0; Counter<X; Counter=Counter+1)
Part1=Part1*e
Counter=Counter-1
Counter=Counter+1
ENDFOR
ENDIF
Part2= 2*X*X*X+1
Part2=2*X*X*X+1
Result=Part1+Part2
Result=Part1+Part2
Print result
Write Result
END
Homework 7- Problem 2
START
 Does this flowchart represent another correct
method for solving problem 2?
Declare X, Flag=0
Counter=0,
Part1=1,Part2,Result
Read X
True
X=-1*X
X<0
False
Flag=1
False
Part2= 2*X*X*X+1
True
Flag==1
Counter<X
True
Counter=Counter+1
False
Part1= Part1*e
Part1=1/Part1
result=Part1+Part2
Print result
End
Homework 7- Problem 2
START
 Write an equivalent pseudocode for it.
Declare X, Flag=0
Counter=0,
Part1=1,Part2,Result
Read X
True
X=-1*X
X<0
False
Flag=1
False
Part2= 2*X*X*X+1
True
Flag==1
Counter<X
True
Counter=Counter+1
False
Part1= Part1*e
Part1=1/Part1
result=Part1+Part2
Print result
End
Homework 7- Problem 2
 Write an equivalent pseudocode for it.
START
Declare X, Flag=0
Counter=0,
Part1=1,Part2,Result
Declare X, Flag=0, Counter, Part1=1, Part2, Result
Read X
IF (X<0)
Read X
THEN
True
X=-1*X
X<0
X=-1*X
Flag=1
ENDIF
False
Flag=1
FOR(Counter=0; Counter<X; Counter=Counter+1)
False Counter<X
Part1=Part1*e
ENDFOR
Part2= 2*X*X*X+1 True
Counter=Counter+1
IF (Flag==1)
THEN
True
False
Flag==1
Part=1/Part1
Part1= Part1*e
ENDIF
Part2=2*X*X*X+1
Part1=1/Part1
Result=Part1+Part2
Print result
result=Part1+Part2
Write Result
End
Homework 7- Problem 4
 Write a pseudocode and draw a flowchart for a program that accepts two
nonnegative integer numbers A and B, divides A by B (provided B is not zero),
and reports the quotient and remainder, taking in consideration that you can’t not
use the division operation (/), and you can use only subtraction (-) and addition
(+).
 Construct a tracing table for the flowchart mention above, assuming that the user
has entered A=11 and B=4.
Homework 7- Problem 4 -Think Logically
If you want to solve a problem, you should ask yourself these questions:
β€’ What is the input of the problem? A,B (both are nonnegative integer numbers, B is not zero)
β€’ What is the output of the problem? Quotient and Remainder of A/B
β€’ What are processes that could be applied on the input to get the output.
Repeated subtraction (A-B)
β€’ Do I need selection & repetition structures? If yes, where and how?
We need a repetition structure
β€’ What are the variables that I may need to use?
o
Variable(s) for storing the input: A,B.
o
Variable(s) for storing the output: Quotient, Remainder
o
Variable(s) for counting (if you have a repetition): no need
o
Intermediate variable(s) for the simplification of calculations: no need
Homework 7- Problem 4 -Think Logically
When you want to construct a FOR structure, you should find the answers for these
questions:
1. What is the maximum number of repetition? Let us keep it in a vaiable named
MaxR.
2. What is the initial value of the counter? Let us keep it in a vaiable named Counter.
3. What is the logical condition (the condition of repetition)?
4. Shoud I increment or drcrement the Counter after each iteration? (we have MaxR
iterations)
5. What are the actions that should be repeated?
Counter = initial value
True
Logical Test
(Repetition condition)
False
Actions to be
repeated
Counter = Counter - 1
Or
Counter = Counter +1
Homework 7- Problem 4-Think Logically
 Write a pseudocode and draw a flowchart for a program that accepts two nonnegative
integer numbers A and B, divides A by B (provided B is not zero), and reports the quotient
and remainder, taking in consideration that you can’t not use the division operation (/),
and you can use only subtraction (-) and addition (+).
Questions to answer before you start:
1. What is the maximum number of repetition?
Homework 7- Problem 4-Think Logically
 Write a pseudocode and draw a flowchart for a program that accepts two nonnegative
integer numbers A and B, divides A by B (provided B is not zero), and reports the quotient
and remainder, taking in consideration that you can’t not use the division operation (/),
and you can use only subtraction (-) and addition (+).
Questions to answer before you start:
1. What is the maximum number of repetition?
As much as A contains B (Quotient)
2. What is the initial value of the counter?
Homework 7- Problem 4-Think Logically
 Write a pseudocode and draw a flowchart for a program that accepts two nonnegative
integer numbers A and B, divides A by B (provided B is not zero), and reports the quotient
and remainder, taking in consideration that you can’t not use the division operation (/),
and you can use only subtraction (-) and addition (+).
Questions to answer before you start:
1. What is the maximum number of repetition?
As much as A contains B (Quotient)
2. What is the initial value of the counter?
There no explicit variable for counting
3. What is the condition of repetition?
Homework 7- Problem 4-Think Logically
 Write a pseudocode and draw a flowchart for a program that accepts two nonnegative
integer numbers A and B, divides A by B (provided B is not zero), and reports the quotient
and remainder, taking in consideration that you can’t not use the division operation (/),
and you can use only subtraction (-) and addition (+).
Questions to answer before you start:
1. What is the maximum number of repetition?
As much as A contains B (Quotient)
2. What is the initial value of the counter?
There no explicit variable for counting
3. What is the condition of repetition?
A>=B
4. Shoud I increment or drcrement the Counter after each
iteration?
Homework 7- Problem 4-Think Logically
 Write a pseudocode and draw a flowchart for a program that accepts two nonnegative
integer numbers A and B, divides A by B (provided B is not zero), and reports the quotient
and remainder, taking in consideration that you can’t not use the division operation (/),
and you can use only subtraction (-) and addition (+).
Questions to answer before you start:
1. What is the maximum number of repetition?
As much as A contains B (Quotient)
2. What is the initial value of the counter?
There no explicit variable for counting
3. What is the condition of repetition?
A>=B
4. Shoud I increment or drcrement the Counter after each
iteration?
There no explicit variable for counting
5. What are the actions that should be repeated?
Homework 7- Problem 4-Think Logically
 Write a pseudocode and draw a flowchart for a program that accepts two nonnegative
integer numbers A and B, divides A by B (provided B is not zero), and reports the quotient
and remainder, taking in consideration that you can’t not use the division operation (/),
and you can use only subtraction (-) and addition (+).
Questions to answer before you start:
1. What is the maximum number of repetition?
As much as A contains B (Quotient)
2. What is the initial value of the counter?
There no explicit variable for counting
3. What is the condition of repetition?
A>=B
4. Shoud I increment or drcrement the Counter after each
iteration?
There no explicit variable for counting
5. What are the actions that should be repeated?
Subtracting B from A, Increasing quotient by 1,
Homework 7- Problem 4 Pseudocode
 Write a pseudocode and draw a flowchart for a program that accepts two nonnegative
integer numbers A and B, divides A by B (provided B is not zero), and reports the quotient
and remainder, taking in consideration that you can’t not use the division operation (/),
and you can use only subtraction (-) and addition (+).
Questions to answer before you start:
Psudocode:
1. What is the maximum number of repetition?
Declare A,B, Quotient=0, Remainder
As much as A contains B (Quotient)
2. What is the initial value of the counter?
There no explicit variable for counting
3. What is the condition of repetition?
A>=B
4. Shoud I increment or drcrement the Counter after each
iteration?
There no explicit variable for counting
5. What are the actions that should be repeated?
Subtracting B from A, Increasing quotient by 1,
Read A,B
Homework 7- Problem 4 Pseudocode
 Write a pseudocode and draw a flowchart for a program that accepts two nonnegative
integer numbers A and B, divides A by B (provided B is not zero), and reports the quotient
and remainder, taking in consideration that you can’t not use the division operation (/),
and you can use only subtraction (-) and addition (+).
Questions to answer before you start:
Psudocode:
1. What is the maximum number of repetition?
Declare A,B, Quotient=0, Remainder
As much as A contains B (Quotient)
2. What is the initial value of the counter?
There no explicit variable for counting
3. What is the condition of repetition?
A>=B
4. Shoud I increment or drcrement the Counter after each
iteration?
There no explicit variable for counting
5. What are the actions that should be repeated?
Subtracting B from A, Increasing quotient by 1,
Read A,B
WHILE (Condition of Repetition )
Actions that should be repeated
ENDWHILE
Homework 7- Problem 4 Pseudocode
 Write a pseudocode and draw a flowchart for a program that accepts two nonnegative
integer numbers A and B, divides A by B (provided B is not zero), and reports the quotient
and remainder, taking in consideration that you can’t not use the division operation (/),
and you can use only subtraction (-) and addition (+).
Questions to answer before you start:
Psudocode:
1. What is the maximum number of repetition?
Declare A,B, Quotient=0, Remainder
As much as A contains B (Quotient)
2. What is the initial value of the counter?
There no explicit variable for counting
3. What is the condition of repetition?
A>=B
4. Shoud I increment or drcrement the Counter after each
iteration?
There no explicit variable for counting
5. What are the actions that should be repeated?
Subtracting B from A, Increasing quotient by 1,
Read A,B
WHILE(A>= B )
Actions that should be repeated
ENDWHILE
Homework 7- Problem 4 Pseudocode
 Write a pseudocode and draw a flowchart for a program that accepts two nonnegative
integer numbers A and B, divides A by B (provided B is not zero), and reports the quotient
and remainder, taking in consideration that you can’t not use the division operation (/),
and you can use only subtraction (-) and addition (+).
Questions to answer before you start:
Psudocode:
1. What is the maximum number of repetition?
Declare A,B, Quotient=0, Remainder
As much as A contains B (Quotient)
2. What is the initial value of the counter?
There no explicit variable for counting
3. What is the condition of repetition?
A>=B
4. Shoud I increment or drcrement the Counter after each
iteration?
There no explicit variable for counting
5. What are the actions that should be repeated?
Subtracting B from A, Increasing quotient by 1,
Read A,B
WHILE(A>= B )
A=A-B
Quotient= Quotient+1
ENDWHILE
Homework 7- Problem 4 Pseudocode
 Write a pseudocode and draw a flowchart for a program that accepts two nonnegative
integer numbers A and B, divides A by B (provided B is not zero), and reports the quotient
and remainder, taking in consideration that you can’t not use the division operation (/),
and you can use only subtraction (-) and addition (+).
Questions to answer before you start:
Psudocode:
1. What is the maximum number of repetition?
Declare A,B, Quotient=0, Remainder
As much as A contains B (Quotient)
2. What is the initial value of the counter?
There no explicit variable for counting
3. What is the condition of repetition?
A>=B
4. Shoud I increment or drcrement the Counter after each
iteration?
There no explicit variable for counting
5. What are the actions that should be repeated?
Subtracting B from A, Increasing quotient by 1,
Read A,B
WHILE(A>= B )
A=A-B
Quotient= Quotient+1
ENDWHILE
Remainder=A
Write Quotient, Remainder
Homework 7- Problem 4 Flowchart
 Write a pseudocode and draw a flowchart for a program that accepts two nonnegative
integer numbers A and B, divides A by B (provided B is not zero), and reports the quotient
and remainder, taking in consideration that you can’t not use the division operation (/),
and you can use only subtraction (-) and addition (+).
start
Psudocode:
Declare A,B, Quotient=0, Remainder
Declare A,B
Quotient=0
Read A,B
WHILE(A>= B )
Read A,B
A=A-B
Quotient= Quotient+1
Remainder=A
No
Aβ‰₯ B
Write Quotient, Remainder
Yes
Remainder =A
A=A-B
Quotient= Quotient+1
Write Remainder,
Quotient
end
Homework 7- Problem 4 Tracing Table
 Construct a tracing table for the flowchart mention above, assuming that the user has
entered A=11 and B=4.
A>=B
A
B
Quotient
Remainder
start
Declare A,B
Quotient=0
Read A,B
No
Aβ‰₯ B
Yes
Remainder =A
A=A-B
Quotient= Quotient+1
Write Remainder,
Quotient
end
Homework 7- Problem 4 Tracing Table
 Construct a tracing table for the flowchart mention above, assuming that the user has
entered A=11 and B=4.
Declaration
A>=B
A
B
Quotient
Remainder
?
?
?
0
?
start
Declare A,B
Quotient=0
Read A,B
No
Aβ‰₯ B
Yes
Remainder =A
A=A-B
Quotient= Quotient+1
Write Remainder,
Quotient
end
Homework 7- Problem 4 Tracing Table
 Construct a tracing table for the flowchart mention above, assuming that the user has
entered A=11 and B=4.
A>=B
A
B
Quotient
Remainder
Declaration
?
?
?
0
?
Declare A,B
Quotient=0
Input
?
11
4
0
?
Read A,B
start
No
Aβ‰₯ B
Yes
Remainder =A
A=A-B
Quotient= Quotient+1
Write Remainder,
Quotient
end
Homework 7- Problem 4 Tracing Table
 Construct a tracing table for the flowchart mention above, assuming that the user has
entered A=11 and B=4.
A>=B
A
B
Quotient
Remainder
Declaration
?
?
?
0
?
Declare A,B
Quotient=0
Input
?
11
4
0
?
Read A,B
Itr 1 of repetition
True
7
4
1
?
start
No
Aβ‰₯ B
Yes
Remainder =A
A=A-B
Quotient= Quotient+1
Write Remainder,
Quotient
end
Homework 7- Problem 4 Tracing Table
 Construct a tracing table for the flowchart mention above, assuming that the user has
entered A=11 and B=4.
A>=B
A
B
Quotient
Remainder
Declaration
?
?
?
0
?
Declare A,B
Quotient=0
Input
?
11
4
0
?
Read A,B
Itr 1 of repetition
True
7
4
1
?
Itr 2 of repetition
True
3
4
2
?
start
No
Aβ‰₯ B
Yes
Remainder =A
A=A-B
Quotient= Quotient+1
Write Remainder,
Quotient
end
Homework 7- Problem 4 Tracing Table
 Construct a tracing table for the flowchart mention above, assuming that the user has
entered A=11 and B=4.
A>=B
A
B
Quotient
Remainder
Declaration
?
?
?
0
?
Declare A,B
Quotient=0
Input
?
11
4
0
?
Read A,B
Itr 1 of repetition
True
7
4
1
?
Itr 2 of repetition
True
3
4
2
?
End of repetition
& output
Flase
3
4
2
3
start
No
Aβ‰₯ B
Yes
Remainder =A
A=A-B
Quotient= Quotient+1
Write Remainder,
Quotient
end
http://humorhub.net/which-step-have-you-reached-today/