Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write the Pseudocode for the following algorithms: For example: Declare Integer

ID: 3771530 • Letter: W

Question

Write the Pseudocode for the following algorithms:

For example:

Declare Integer index

Declare Integer numDigits = 0

For index = 0 To length(str) - 1

   If isDigit( str[index] ) Then

Set numDigits = numDigits + 1

   End If

End For

Display "The number of digits is ", numDigits

4. Design a pseudocode algorithm that deletes the first and last characters in the String variable str.

5. Design a pseudocode algorithm that converts each occurrence of the character "t" in the String variable str to uppercase.

6. Design a pseudocode algorithm that replaces each occurrence of the character "x" in the String variable str with a space.

7. Assume that the following declaration exists in a program: Declare String str = "Mr. Bean" Design a pseudocode algorithm that replaces "Mr." with "Mister" in the variable.

Explanation / Answer

pseudocode algorithm that deletes the first and last characters in the String variable str.

Declare Integer

Declare Integer numDigits = 0
For index = 0 To length(str) - 1
If isDigit( str[index] ) Then
Set numDigits = numDigits + 1
End If
End For
Display "The number of digits is ", numDigits

Answer for Question 4)

// Comment To "remove" the 1st character point to the second character:
Declare String mystr = "Nmy stringP";
Declare char * p;
Assign *p = mystr;
p++;
// 'P' is not in 'p' (and it isn't in 'mystr either)
Assign p[strlen(p)-1] = 0;
Display "After Delete the First and Last Char from String is: ", p

Answer for Question 5)

Design a pseudocode algorithm that converts each occurrence of the character "t" in the String variable str to uppercase.

Declare String mystr = "Nmy stringP";
Declare Integer numDigits = 0
For index = 0 To length(str) - 1
   If ( mystr[index] == 't') Then
       mystr[index] = toupper(mystr[index]);
   End If
End For
Display "The String is after replacing of t to "T" is ", mystr

Answer for Question 6)

pseudocode algorithm that replaces each occurrence of the character "x" in the String variable str with a space.

Declare String mystr = "Nmx stxingP";
Declare Integer numDigits = 0
For index = 0 To length(str) - 1
   If ( mystr[index] == 'x') Then
       mystr[index] = " ";
   End If
End For
Display "The String is after replacing of x to space is ", mystr


Answer for Question 7)

Assume that the following declaration exists in a program: Declare String str = "Mr. Bean" Design a pseudocode algorithm that replaces "Mr." with "Mister" in the variable.

Declare String mystr = "Mr. Bean";
Declare String substr = "Mister";
Declare Integer numDigits = 0

mystr.replace(numDigits, 3, "Mister");

Display "The String is after replacing of Mr. with Mister is ", mystr