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??
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);
}
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).
Number of if statements = 3
Number of loops = 1 (weight = 1 * 2)
Number of compound condition
= 1 (weight = 2, i.e., 1 for each OR)
Complexity = 7 + 1 = 8
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 3, 9 b.
Lines of Code 2, 6, 9 c.
Halstead Difficulty 4, 7, 10 d.
Maintainability Index 1, 5 e.
Cyclomatic Complexity 8, f.
Fan in and Fan out 11 If you get 10
out of these 12 red numbers above right, you get full mark |
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 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.
One possible solution would be
·
Collecting
the customer’s data via a new Web interface for the Membership function and
store it in a temporary database. This may need a bridge to allow using the
legacy relational database. Then, extending the legacy Membership function to
be able to read pre-entered data for the club worker to augment with extra data
and approve.
·
Using
Screen Mapping to Web-enable Auto Insurance Quotation
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.
Some possible bad smells are
·
Long
Method (AddRecipe(),
AddInventory())à Extract
Method
·
Large
Class (AcmeVendingMachine) à Extract Class
·
Duplicate
Code (CheckItem())à Extract Method or Form Template Method
·
Switch Statement
(multi if statements in CheckItem()and main())
·
Data Clump
(units_sug, units_mil, units_cof,
units_cho, units_bou are
usually used together)à Extract Class or introduce parameter
object