Computer Science Engineering (CSE) Exam  >  Computer Science Engineering (CSE) 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”
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...
Here when the element of array A and oldc match , we replace that array element of A with array element of newc . For every element of A array update occurs maximum one time.
Similarly for (2) array element of A has updated with array element of newc less than or equal to one time,
Now, for (3) when i=0 , value of A match with oldc[2] i.e.'a' , and replace with newc[2] i.e. also 'a'. So, no changes
when i=1 value of array A[1]='b'
match with oldc[0]='b' and replace with newc[0]='c'.
Now, A[1]='c' which equal with next element of oldc[1]='c'.
So, replace again with newc[1]='d'.
Now, we can say here in array A[1] value replace with newc[0] value , and that newc[0] value replace with next newc[1]
value.
Similarly for (4) here 2 times replacement for A[0] with element newc[0] and newc[1]
Updating of newc value with another newc value is calling flaw here
So Ans B
 
View all questions of this test
Most Upvoted Answer
The procedure given below is required to find and replace certain char...
Explanation:

Flaw in the Procedure:
The flaw in the given procedure lies in the fact that it only checks the characters in the input string A against the characters in the oldc array one by one. This means that if a character in A matches the first character in oldc, it will be replaced regardless of whether it should be replaced or not according to the corresponding index in newc. This results in incorrect replacements.

Testing the Procedure:
- Test case (1): Since oldc = abc and newc = dab, this test case will be able to capture the flaw as the characters in oldc and newc are in the correct order to expose the flaw.
- Test case (2): This test case will also capture the flaw as the characters in oldc = cde and newc = bcd are in a different order, exposing the flaw in the procedure.
- Test case (3): Similar to test case (1), this test case with oldc = bca and newc = cda will capture the flaw.
- Test case (4): This test case will not capture the flaw as the characters in oldc = abc and newc = bac are in a different order, which does not expose the flaw in the procedure.
Therefore, only two out of the four test cases will be able to capture the flaw in the given procedure, making option 'B' the correct answer.
Explore Courses for Computer Science Engineering (CSE) exam

Similar Computer Science Engineering (CSE) Doubts

Top Courses for Computer Science Engineering (CSE)

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”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 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 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”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 oneb)Only twoc)Only threed)All fourCorrect answer is option 'B'. Can you explain this answer? for Computer Science Engineering (CSE) 2024 is part of Computer Science Engineering (CSE) preparation. The Question and answers have been prepared according to the Computer Science Engineering (CSE) exam syllabus. Information about 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”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 oneb)Only twoc)Only threed)All fourCorrect answer is option 'B'. Can you explain this answer? covers all topics & solutions for Computer Science Engineering (CSE) 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 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”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 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 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”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 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 Computer Science Engineering (CSE). Download more important topics, notes, lectures and mock test series for Computer Science Engineering (CSE) 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 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”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 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 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”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 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 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”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 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 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”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 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 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”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 oneb)Only twoc)Only threed)All fourCorrect answer is option 'B'. Can you explain this answer? tests, examples and also practice Computer Science Engineering (CSE) tests.
Explore Courses for Computer Science Engineering (CSE) exam

Top Courses for Computer Science Engineering (CSE)

Explore Courses
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