University of Leicester
Nov 14th, 2003
Solve four of the following five questions (each question equals 2%). You can use your printed notes or the course web page and the links provided there. You cannot use any other resources or cooperate with other students in solving the quiz. Duration is 40 min.
1. System Dependence Graph
a.
Draw the program
dependence graph (PDG) for the given program below that counts the number of
words, characters, and lines in the input. Represent control dependence by
solid lines and data dependence by dashed lines. Draw data dependence edges
only for variables nl
and c (i.e., do not draw data dependence
edges for variables inword
and nw and nc.
main() {
1 inword = NO;
2 nl = 0;
3 nw = 0;
4 nc = 0;
5 c = getchar();
6 while (c != EOF) {
7 nc = nc + 1;
8 if (c == '\n')
9 nl = nl + 1;
10 if (c == ' ' || c == '\n' || c ==
'\t')
11 inword = NO;
12 else if (inword == NO) {
13 inword = YES;
14 nw = nw + 1;
}
15 c = getchar();
}
16 printf("%d \n", nl);
17 printf("%d \n", nw);
18 printf("%d \n", nc);
}
2. System Dependence Graph
a.
Deduce the backward
static slice of this program at statement 16 for variable nl. Do so by following statement 16 backward on the PDG to
the root through all possible control and dependence edges. You can write the
answer by writing the serial numbers of the statements in the slice. Is this an
executable slice??
b.
Calculate the Extended
Cyclomatic Complexity for the program given in 1. Assume that every binary branching
statement adds 1 to complexity and that every loop adds 2. Assume that every
multi-part condition in a conditional branching statement adds an additional n
to complexity where n is the
number of logical operators in the condition (this is plus the branching
statement’s contribution to complexity).
3. Complexity and Maintainabiliaty Metrics
Connect
every item in the list on the left hand side to the relevant items on the right
hand side (or write them in front of them). Note that an item from the LHS can
be connected to many RHS items and vice versa. Each item should be connected at
least once.
a.
Extended Cyclomatic
Complexity b.
Lines of Code c.
Halstead Difficulty d.
Maintainability Index e.
Cyclomatic Complexity f.
Fan in and Fan out |
1.
Is meant to balance
between logical complexity, vocabulary used, size and human insight of a
program. 2.
Is language dependent 3.
Gives more weight to
compound conditions 4.
Is Proportional to the
number of distinct keywords used in the program 5.
Has a 3 terms and a 4
terms formulas 6.
Does not consider the
code automatically generated by tools. 7.
Measures textual or
lexical complexity only 8.
Can be used in testing
by calculating the number of independent of test cases needed to cover all
paths 9.
Is used in calculating
Maintainability Index 10.
There is a wide
controversy about the value of this metric 11.
Used to measure coupling between modules |
4. Web Enabling.
A1
Motor Association (AMA) club offers a range of services to its members. This
includes emergency road assistance, towing, driver training, auto insurance,
etc. AMA has a mainframe-based system for membership and services management.
The system is used primarily by AMA employees. The management is considering
providing some services through AMA’s Web site to attract more customers and
reduce operation costs. In particular they like to offer self-registration and
calculating auto insurance quotes through the Web.
The
system provides a member registration function that the club staff use to
register new members. This function allows the staff personal to log in, add
the member details, verify its driver license information and check the
member’s status against the club’s database (new member, returning member, VIP
member, etc.). The management is thinking that this function cannot be opened
as it is to customer access. Instead, customers should be allowed to enter most
of the required data via a Web interface. Then, a staff will do the extra
needed verification before approving an application and notifying the customer
via email.
The
system provides an Auto insurance quotation function that is currently used by
the club staff to calculate quotes for customers. The same function can be used
by the customer.
As
a consultant, suggest a suitable Web-enabling solution(s) to AMA. Discuss
different options that can be used for this specific case, if any, and the
effort/technology that would be needed. Name the technologies and/or tools that
your solution would use.
5. Refactoring
In
the program
given in lab 6, identify 5 different bad smells in this code and at least
one location where each smell exists and one refactoring that you would apply
to clean it.