Question 11
Statement
The following pseudocode is executed using the “Scores” dataset. At the end of the execution, count captures the number of pairs of students having either same gender or from the same city but not both. But the pseudocode may have mistakes. Identify all such mistakes (if any). Assume that all statements not listed in the options below are free of errors. [MSQ]
1 count = 0 2 while(Table 1 has more rows){ 3 Read the first row X in Table 1 4 Move X to Table 2 5 while(Table 1 has more rows){ 6 Read the first row Y in Table 1 7 Move Y to Table 3 8 count = count + findPair(X, Y) 9 }10 Move all rows from Table 3 to Table 111 }12 Procedure findPair(X, Y)13 A = False, B = True14 if(X.Gender == Y.Gender){15 A = True16 }17 if(X.CityTown == Y.CityTown){18 B = True19 }20 if((A and not B) and (not A and B)){21 return(1)22 }23 return(0)24 End findPairLine 13: Incorrect initialisation of B
Line 18: Incorrect update of B
Line 20: Incorrect condition
Line 21: It should return(0)