GATE Exam  >  GATE Questions  >  The procedure given below is required to find... Start Learning for Free
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"
Q.
The tester now tests the program on all input strings of length five consisting of characters
‘a’, ‘b’, ‘c’, ‘d’ and ‘e’ with duplicates allowed. If the tester carries out this testing with the
four test cases given above, how many test cases will be able to capture the flaw?
  • a)
    Only one
  • b)
    Only two
  • c)
    Only three
  • d)
    All four
Correct answer is option 'B'. Can you explain this answer?
Verified Answer
The procedure given below is required to find and replace certain char...
Flaw in this given procedure is that one character of Array ‘A’ can be replaced by more than one character of newc array, which should not be so.Test case (3) and (4) identifies this flaw as they are containing ‘oldc’ and ‘newc’ array characters arranged in specific manner.
Following string can reflect flaw, if tested by test case (3). initially i = j = 0
 
c = c so replaced by d
Likewise single character ‘b’ in A is replaced by ‘c’ and then by ‘d’.
Same way test case (4) can also catch the flaw
View all questions of this test
Most Upvoted Answer
The procedure given below is required to find and replace certain char...
Analysis of the Flaw in the Procedure:
- The given procedure has a nested loop that iterates over each character in the input string A and each character in the oldc array.
- If a character in A matches a character in oldc, it is replaced with the corresponding character from newc.
- However, the flaw in the procedure is that it only considers the first occurrence of a character in oldc for replacement in A. This means that if a character in A matches multiple characters in oldc, only the first match will be replaced.

Testing the Procedure:
- When testing the procedure using the four provided test cases, the flaw can be captured as follows:
- Test case 1: The procedure will successfully replace 'a' with 'd', but it will not replace the subsequent 'b' with 'a' as 'b' is not considered after 'a' in the replacement process.
- Test case 2: The procedure will successfully replace 'c' with 'b', but it will not replace 'd' and 'e' as they are not considered after 'c'.
- Test case 3: The procedure will successfully replace 'b' with 'c', but it will not replace 'a' as 'a' is not considered after 'b'.
- Test case 4: The procedure will successfully replace 'a' with 'b', but it will not replace 'b' and 'c' as they are not considered after 'a'.
Therefore, out of the four test cases, only two test cases will be able to capture the flaw in the procedure.
Explore Courses for GATE exam

Similar GATE Doubts

The procedure given below is required to find and replace certain characters inside an inputcharacter 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 fixedlength of five characters, while arrays oldc and newc contain three characters each. However, theprocedure is flawedvoid 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"Q.The tester now tests the program on all input strings of length five consisting of characters‘a’, ‘b’, ‘c’, ‘d’ and ‘e’ with duplicates allowed. If the tester carries out this testing with thefour test cases given above, how many test cases will be able to capture the flaw?a)Only oneb)Only twoc)Only threed)All fourCorrect answer is option 'B'. Can you explain this answer?
Question Description
The procedure given below is required to find and replace certain characters inside an inputcharacter 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 fixedlength of five characters, while arrays oldc and newc contain three characters each. However, theprocedure is flawedvoid 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"Q.The tester now tests the program on all input strings of length five consisting of characters‘a’, ‘b’, ‘c’, ‘d’ and ‘e’ with duplicates allowed. If the tester carries out this testing with thefour test cases given above, how many test cases will be able to capture the flaw?a)Only oneb)Only twoc)Only threed)All fourCorrect answer is option 'B'. Can you explain this answer? for GATE 2024 is part of GATE preparation. The Question and answers have been prepared according to the GATE exam syllabus. Information about The procedure given below is required to find and replace certain characters inside an inputcharacter 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 fixedlength of five characters, while arrays oldc and newc contain three characters each. However, theprocedure is flawedvoid 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"Q.The tester now tests the program on all input strings of length five consisting of characters‘a’, ‘b’, ‘c’, ‘d’ and ‘e’ with duplicates allowed. If the tester carries out this testing with thefour test cases given above, how many test cases will be able to capture the flaw?a)Only oneb)Only twoc)Only threed)All fourCorrect answer is option 'B'. Can you explain this answer? covers all topics & solutions for GATE 2024 Exam. Find important definitions, questions, meanings, examples, exercises and tests below for The procedure given below is required to find and replace certain characters inside an inputcharacter 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 fixedlength of five characters, while arrays oldc and newc contain three characters each. However, theprocedure is flawedvoid 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"Q.The tester now tests the program on all input strings of length five consisting of characters‘a’, ‘b’, ‘c’, ‘d’ and ‘e’ with duplicates allowed. If the tester carries out this testing with thefour test cases given above, how many test cases will be able to capture the flaw?a)Only oneb)Only twoc)Only threed)All fourCorrect answer is option 'B'. Can you explain this answer?.
Solutions for The procedure given below is required to find and replace certain characters inside an inputcharacter 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 fixedlength of five characters, while arrays oldc and newc contain three characters each. However, theprocedure is flawedvoid 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"Q.The tester now tests the program on all input strings of length five consisting of characters‘a’, ‘b’, ‘c’, ‘d’ and ‘e’ with duplicates allowed. If the tester carries out this testing with thefour test cases given above, how many test cases will be able to capture the flaw?a)Only oneb)Only twoc)Only threed)All fourCorrect answer is option 'B'. Can you explain this answer? in English & in Hindi are available as part of our courses for GATE. Download more important topics, notes, lectures and mock test series for GATE Exam by signing up for free.
Here you can find the meaning of The procedure given below is required to find and replace certain characters inside an inputcharacter 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 fixedlength of five characters, while arrays oldc and newc contain three characters each. However, theprocedure is flawedvoid 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"Q.The tester now tests the program on all input strings of length five consisting of characters‘a’, ‘b’, ‘c’, ‘d’ and ‘e’ with duplicates allowed. If the tester carries out this testing with thefour test cases given above, how many test cases will be able to capture the flaw?a)Only oneb)Only twoc)Only threed)All fourCorrect answer is option 'B'. Can you explain this answer? defined & explained in the simplest way possible. Besides giving the explanation of The procedure given below is required to find and replace certain characters inside an inputcharacter 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 fixedlength of five characters, while arrays oldc and newc contain three characters each. However, theprocedure is flawedvoid 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"Q.The tester now tests the program on all input strings of length five consisting of characters‘a’, ‘b’, ‘c’, ‘d’ and ‘e’ with duplicates allowed. If the tester carries out this testing with thefour test cases given above, how many test cases will be able to capture the flaw?a)Only oneb)Only twoc)Only threed)All fourCorrect answer is option 'B'. Can you explain this answer?, a detailed solution for The procedure given below is required to find and replace certain characters inside an inputcharacter 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 fixedlength of five characters, while arrays oldc and newc contain three characters each. However, theprocedure is flawedvoid 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"Q.The tester now tests the program on all input strings of length five consisting of characters‘a’, ‘b’, ‘c’, ‘d’ and ‘e’ with duplicates allowed. If the tester carries out this testing with thefour test cases given above, how many test cases will be able to capture the flaw?a)Only oneb)Only twoc)Only threed)All fourCorrect answer is option 'B'. Can you explain this answer? has been provided alongside types of The procedure given below is required to find and replace certain characters inside an inputcharacter 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 fixedlength of five characters, while arrays oldc and newc contain three characters each. However, theprocedure is flawedvoid 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"Q.The tester now tests the program on all input strings of length five consisting of characters‘a’, ‘b’, ‘c’, ‘d’ and ‘e’ with duplicates allowed. If the tester carries out this testing with thefour test cases given above, how many test cases will be able to capture the flaw?a)Only oneb)Only twoc)Only threed)All fourCorrect answer is option 'B'. Can you explain this answer? theory, EduRev gives you an ample number of questions to practice The procedure given below is required to find and replace certain characters inside an inputcharacter 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 fixedlength of five characters, while arrays oldc and newc contain three characters each. However, theprocedure is flawedvoid 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"Q.The tester now tests the program on all input strings of length five consisting of characters‘a’, ‘b’, ‘c’, ‘d’ and ‘e’ with duplicates allowed. If the tester carries out this testing with thefour test cases given above, how many test cases will be able to capture the flaw?a)Only oneb)Only twoc)Only threed)All fourCorrect answer is option 'B'. Can you explain this answer? tests, examples and also practice GATE tests.
Explore Courses for GATE exam
Signup for Free!
Signup to see your scores go up within 7 days! Learn & Practice with 1000+ FREE Notes, Videos & Tests.
10M+ students study on EduRev