...
Programming
October 18, 2023
UGC NET CS 2010 June-Paper-2
October 18, 2023
Programming
October 18, 2023
UGC NET CS 2010 June-Paper-2
October 18, 2023

Programming

Question 47

The procedure given below is required to find and replace certain characters inside an input character string supplied in array A. The characters to be replaced are supplied in array oldc, while their respective replacement characters are supplied in array newc. Array A has a fixed length of five characters, while arrays oldc and newc contain three characters each. However, the procedure is flawed

void find_and_replace(char *A, char *oldc, char *newc) {
    for (int i = 0; i < 5; i++)
       for (int j = 0; j < 3; j++)
           if (A[i] == oldc[j]) A[i] = newc[j];
}

The procedure is tested with the following four test cases

(1) oldc = "abc", newc = "dab" 
(2) oldc = "cde", newc = "bcd" 
(3) oldc = "bca", newc = "cda" 
(4) oldc = "abc", newc = "bac" 

If array A is made to hold the string “abcde”, which of the above four sest cases will be successful in exposing the flaw in this procedure?

A
None
B
2 only
C
3 and 4 only
D
4 only
Question 47 Explanation: 
The test cases 3 & 4 captures the flaw. The code does not works fine when an old character is replaced by a new character & new character is again replaced by another new character.
1, 2 works fine, 3, 4 carries flaw.
Correct Answer: C
Question 47 Explanation: 
The test cases 3 & 4 captures the flaw. The code does not works fine when an old character is replaced by a new character & new character is again replaced by another new character.
1, 2 works fine, 3, 4 carries flaw.
0 0 votes
Article Rating
Subscribe
Notify of
0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x
error: Alert: Content selection is disabled!!