Вы находитесь на странице: 1из 22

ETH

Eidgenössische Technische Hochschule Zürich


Swiss Federal Institute of Technology Zürich

Reverse Engineering  

Code Restructuring Mainframe

Guest Lecture

Exercises
October 2007 – 3rd Version
presented by
Dipl. Ing. Werner Hoffmann
A member of IEEE and ACM

EMAIL: pwhoffmann@t­online.de Please see the


notes pages for
 
See: © Copyright Note in Note Page. additional
Date: 27.10.2007 comments.
Page: 1
SE_CodeRestructuring_Exercises.ppt
Agenda ­ Exercises

1. Basic Methods
2. Restructuring
3. Some more complex examples

Date: 21.06.2007 Code Restructuring - Exercises Page: 2


Agenda ­ Exercises

• Basic Methods
• Restructuring
• Some more complex examples

Date: 21.06.2007 Code Restructuring - Exercises Page: 3


Exercise: Basic Methods  (1)

A) Name the method(s) which are used for source code restructuring in
the following example. Additional name the resulting structural control
blocks.
___________________

F
T
1 F1 p1 ?

3 = 3
F2
T
F
2 p2 ?

Method:
___________________

_____________________________

Date: 21.06.2007 Code Restructuring - Exercises Page: 4


Exercise: Basic Methods  (2)

B) Name the method(s) which are used for source code restructuring in
the following example. Name additional methods to get structural
control blocks.
__________________________
J
__________________________ T
1 F
1
1 J 1 K p1

__________________________

K 3 4
K J
T T
2 F F
2 p1 3 = 2
2 p1 L

L
_____________________________

____________________________
Method:

Date: 21.06.2007 Code Restructuring - Exercises Page: 5


Exercise: Basic Methods  (3)

C) Name the method(s) which are used for source code restructuring in
the following example.

H H

1 2 H = H 1 2

H
Method:

____________________________

Date: 21.06.2007 Code Restructuring - Exercises Page: 6


Exercise: Basic Methods  (4)

D) Name the method(s) which are used for source code restructuring in
the following example. Name additional methods to get basic structural
control blocks.

G
__________________________

F F,G,E
E
T T
F F
1 I p1 H = 1 I p1 H

____________________________

Method:

Date: 21.06.2007 Code Restructuring - Exercises Page: 7


Exercise: Basic Methods  (5)

E) Name the method(s) which are used for source code restructuring in
the following example.

B
B 1 A
1

C 2 = C 2 3

D 3 D

Method: ____________________________

Date: 21.06.2007 Code Restructuring - Exercises Page: 8


Exercise: Basic Methods  (6)

F) Name the method(s) which are used for source code restructuring in
the following example. Means:______________________

A A
F T
T F
1 p = 1 ¬p

T F
F T
1 A q = 1 A ¬q

Means:______________________

Method: ____________________________

Date: 21.06.2007 Code Restructuring - Exercises Page: 9


Agenda ­ Exercises

• Basic Methods
• Restructuring
• Some more complex examples

Date: 21.06.2007 Code Restructuring - Exercises Page: 10


Exercise: Restructuring  (1)

A) Restructure following flowchart and describe used methods/rules:

A
T
F
1 B p

Date: 21.06.2007 Code Restructuring - Exercises Page: 11


Exercise: Restructuring  (2)

B) Restructure following flowchart and describe used methods/rules:

A
T
q
F
T

p 2

1 B

Date: 21.06.2007 Code Restructuring - Exercises Page: 12


Exercise: Restructuring  (3)

C) Restructure following flowchart and describe used methods/rules:

T
T
p 2 q
F
F

1 B

Date: 21.06.2007 Code Restructuring - Exercises Page: 13


Exercise: Restructuring  (3)

D) Restructure following flowchart and describe used methods/rules:

F3

T
T F
1 F1 2 p1 p2

F2

Date: 21.06.2007 Code Restructuring - Exercises Page: 14


Agenda ­ Exercises

• Basic Methods
• Restructuring
• Some more complex
examples

Date: 21.06.2007 Code Restructuring - Exercises Page: 15


Exercise: Example 1  (1)

A) Specification:

A bank offers two mortgages. The first is for $55,000 at a monthly


rate 0f 0.6 percent. The second is for $26,000 at a monthly rate of
0.9 percent.
If the payment is $1,500 per month,

• How long will it take to pay off both mortgages if the


monthly payments reduce the first mortgages first?
• How much will be the last payment be?

Use following Pseudo-Code as starting point for a code restructure


task.

After restructuring analyze and discuss the result.

Date: 21.06.2007 Code Restructuring - Exercises Page: 16


Exercise: Example 1  (2)

A) Pseudo-Code:
L1 = 55000 *loan 1 Paid_Off:
I1 = 0.006 *interest 1 Print m ‘left=‘ p-L2
L2 = 26000 *loan 2 EXIT
I2 = 0.009 *interest 2 Low_Payment:
Pay = 1500 *monthly payment Print ‘payment < interest’
M = 0 *month number EXIT
Next_Month:
M = M + 1
p = Pay – (L1*I1) – (L2*I2)
IF p <= 0 goto Low_Payment
IF L1 <= 0 goto Mortgate2
IF p <= L1
THEN L1 = L1 – p; p = 0
ELSE p = p – L1; L1 = 0
IF p <= 0 goto Next_Month
Mortage2:
if p >= L2 goto Paid_Off
L2 = L2 – p
goto Next_Month
Date: 21.06.2007 Code Restructuring - Exercises Page: 17
Exercise: Example 2  (1)

A) An old Batch-Program: Task: Restructure this


START flowchart and write
Initialization_Routine resulting Pseudo-Code.
(1)
Jump to new page
Print Header Lines
(2)
Read Order Record O
If EOF –Y- Termination_Routine; END
(3)
Read Address Record A
If key O = key A –N-
If O.Count >= 0 –N- Prepare Print_Line (O,A fields)
If O.Price >= 0 –N- Print Line
Calculate Sum (O.Count*O.Price) Clear Sum
Prepare Sum in Print_Line If Page_overflow –N-
-Y-

Date: 21.06.2007 Code Restructuring - Exercises Page: 18


Exercise: Example 3  (1)

• College Admission Program :

Task: Restructure this


flowchart and write
resulting Pseudo-Code.

Date: 21.06.2007 Code Restructuring - Exercises Page: 19


Exercise: Example 4  (1)

A) A typical commercial program:

Task: Restructure this


flowchart and write
resulting Pseudo-Code.

Date: 21.06.2007 Code Restructuring - Exercises Page: 20


Questions / Comments… 
???
Questions, comments, further
information?
Please feel free to e-mail me!
Dipl.Ing. Werner Hoffmann
EMAIL: pwhoffmann@t­online.de or
    pwhoffmann@aol.com 
Date: 27.10.2007 SE_CodeRestructuring_Exercises.ppt Page: 21
The End…

 Code Restructuring

 
I tha
n
for y k you
o
atte ur
ntio
n!

Date: 21.06.2007 Code Restructuring - Exercises Page: 22

Вам также может понравиться