Question: 3. Consider the following code, where the operations in the #braced area# of the while loop have been omitted: mystring

3. Consider the following code, where the operations in the #braced area# of the while loop have been omitted: mystring <- "R fever" index <- 1 ecount <- 0 result <- mystring while(ecount<2 && index<=nchar(mystring)){ # several omitted operations # } result Your task is to complete the above code in the braced area so that it inspects mystring character by character until it reaches the second instance of the letter e or the end of the string, whichever comes first. The result object should be the entire character string if there is no second e or the character string made up of all the characters up to, but not including, the second e if there is one. For example, mystring <- "R fever" should provide result as "R fev". This may be achieved by following these operations in the braces (or you can devise your own strategy): a) Use substr ( ) to extract the single character of mystring at position index. b) Use a check for equality to determine whether this single character string is either "e" OR "E". If so, increase ecount by 1. c) Next, perform a separate check to see whether ecount is equal to 2. If so, use substr to set result equal to the characters between 1 and index-1 inclusive. d) Increment index by 1. e) Test your codeensure the previous result for mystring <- "R fever". Furthermore, confirm the following: Using mystring <- "beautiful" provides result as "beautiful" Using mystring <- "ECCENTRIC" provides result as "ECC" Using mystring <- "ElAbOrAte" provides result as "ElAbOrAt" Using mystring <- "eeeeek!" provides result as "e"

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!