Philadelphia University

Lecturer : Dr. Ali Fouad

Coordinator : Dr. Ali Fouad

Internal Examiner : Dr. Samer Hanna

Software Reengineering (721421) Second Exam First Semester of 2014-2015

Date: 5-12-2014 Time: 50 minutes

Information for Candidates

1.  This examination paper contains four questions, totaling 23 marks.

2.  The marks for parts of questions are shown in round brackets.

Advice to Candidates

1. You should attempt all questions.

2. You should write your answers clearly.

I. Basic concepts

Objective: The aim of the question in this part is to evaluate your knowledge and skills concerning with the basic concepts of array list and linked list data structures.

Question 1: (6 marks)

The legacy system is faced with many barriers to change into efficient, reliable and flexible systems. Give three of these barriers.

2) According to the "code ageing" concept, what is a good indication that you need to start from scratch and develop a new version of your software?

When the software has become so complex that is practically impossible (or very costly) to make any new changes.

3) In source code translation, there is a many to many mapping between programs and not one correct translation. But all programming languages have same basic capabilities.

What are the main parts for translation?

What is the most difficult part, why?

II. Familiar Problems Solving

Objectives. The aim of the questions in this part is to evaluate that the student has some basic knowledge of the key aspects of the lecture material and can attempt to solve familiar problems.

Question 2: (7 marks)

Assume the following c++ code:

void main()

{

char inwords[3]=’no’;

int n1 = 0;

int nc = 0;

int nw =0;

char c=getchar();

while (c!=EOF)

{

nc =nc +1;

if (c==’\n’) n1++;

if (c==’ ’|| c==’\n’ || c==’\t’)

if (inwords=’NO’)

inwords=’YES’;

else

nw=nw +1;

else

n1++;

c=getchar();

}

cout<n1;

cout<nw;

cout<nc;

}

Draw a Flow Dependency Graph

Draw the Control Dependency Graph

Draw the Program Dependency Graph

Question 3: (5 marks)

The term spaghetti code is used to mean code that is hard to follow because of how it uses loops, control variables or jump statements. This following C# program with spaghetti code shows how the goto statement can be used to create a looping construct. Four labels are used to describe code and several goto statements are used throughout the program. Use restructuring methodology to rewrite the code to be clearer with methods and loops.

using System;

class Program

{

static void Main()

{

int value = 0;

SWITCH:

switch (value)

{

case 0: goto ADD1;

case 1: goto MULTIPLY3;

default: goto SUBTRACT1;

}

MULTIPLY3:

value *= 3;

goto SWITCH;

ADD1:

value += 1;

goto SWITCH;

SUBTRACT1:

value -= 1;

Console.WriteLine(value);

}

}

using System;

class Program

{

static void Main()

{

int value = 0;

while (true)

{

if (value == 0)

{

value += 1;

continue;

}

if (value == 1)

{

value *= 3;

continue;

}

value -= 1;

break;

}

Console.WriteLine(value);

}

}

III.  Unfamiliar Problems Solving

Objectives. The aim of the questions in this part is to evaluate that the student can solve familiar problems with ease and can make progress towards the solution of unfamiliar problems, and can set out reasoning and explanation in a clear and coherent manner.

Question 4: (5 marks)

Assume the following code:

int n,max,min,s,i,k;

int a[100] ;

1. void findmax(int s1, int s2)

{

2. if (s1 > s2)

3. s = s1; /* correctly s2 := s1;

}

4. void findmin(int x, int y)

{

5. if (x < y)

6. y = x;

}

void main()

{

7. cin>n;

8. cin>k;

9. i := 1;

10. while (i <=n) {

11. cin>a[i];

12. i = i + 1;

}

13. max = a[1];

14. min = a[1];

15. s = a[1];

16. i = k + 1;

17. while (i <= n){

18. if (a[i]>0) {

19. Findmax(a[i],max);

20. Findmin(a[i],min);

21. s = s + a[i];

}

22. i = i + k;

}

23. cout<max< ’ ’< min< ’ ’< s;

}

Program slices are useful for testing, find dynamic slice for max at position 23 and for the input values n=3, a= (1, 2,-and 3), k=1 and than allocate defects if exits.

7. cin>n;

8. cin>k;

9. i := 1;

10. while (i <=n) {

11. cin>a[i];

12. i = i + 1;

}

13. max = a[1];

23. cout<max< min< ’ ’< s;