Question

In: Computer Science

Does anyone know how to do pseudocode on this topic? Write a program to perform the...

Does anyone know how to do pseudocode on this topic?
Write a program to perform the following two tasks:

1. The program will accept a string as input in which all of the words are run together, but the first character of each word is uppercase. Convert the string to a string in which the words are separated by spaces and only the first word starts with an uppercase letter. For example, the string "StopAndSmellTheRose" would be converted to "Stop and smell the rose". Display the result string.

2. Then the program will convert each word in the result string of task 1 into "Pig Latin" and display the result string. In one version of Pig Latin, you convert a word by removing the first letter, placing that letter at the end of the word, and then appending "ay" to the word.

For example, for the result string "Stop and smell the roses" in task 1, the Pig Latin string should be "topSay ndaay mellsay hetay osesray"


Hints:

1. In the first task, the first letter of a sentence should always be uppercase. Starting from the second letter to the last letter, if the letter is an uppercase (be cautious with I), that means it is the beginning of a new word. What you need to do is to insert a space before that uppercase letter, and change that uppercase letter to lowercase.

Python has isupper() function to check if a string or a character is uppercase, islower to check if a string or a character is lowercase

you may need a variable to remember the beginning index of a word and the ending index of a word. So you can use the two indexes to extract the word from the input phrase.

to add a space after a word, you can use the + operator as long as both operands are strings/characters

2. In the second task (pig Latin task), the result string of the first task should be passed as argument when you call the function you define for the second task.

You may need to use:

the index to access individual character (particularly the first character of each word in the sentence)

move the first character to the end of the word

add "ay" at the end of the word




Requirements:

Algorithm must be modularized
Pseudocode in .txt file or .docx file

Solutions

Expert Solution


Module Main
   declare String str
   declare String spaceSeparatedSentence
   declare String pigLatinSentence
  
   // input the run together string
   Input str
  
   // convert the input string to string with spaces
   stringWithSpace(str, spaceSeparatedSentence)
   // display the formatted string
   Display spaceSeparatedSentence
   // convert the space separated string to pigLatin
   toPigLatin(spaceSeparatedSentence, pigLatinSentence)
   // display the pigLatin string
   Display pigLatinSentence
  
End Module


// Module that takes as input a string in which all of the words are run together and returns a string where words are separated by spaces
Module stringWithSpace(String runTogetherSentence, String ref spaceSeparatedSentence)
  
   // declare integers for startIndex and endIndex
   declare integer startIndex
   declare integer endIndex
  
   // set output string to first character of input string
   Set spaceSeparatedSentence to runTogetherSentence[0]
  
   // set startIndex to 1
   Set startIndex to 1
   Set endIndex to startIndex
  
   // loop over the input string
   while endIndex < length of runTogetherSentence
   do
       // if character at endIndex is uppercase
       if runTogetherSentence[endIndex] is uppercase then
           // append the substring from startIndex to endIndex(exclusive) to spaceSeparatedSentence and then add a space and then append lowercase version of character at endIndex to spaceSeparatedSentence
           spaceSeparatedSentence = spaceSeparatedSentence + runTogetherSentence[startIndex:endIndex] + " " + runTogetherSentence[endIndex].lower()
          
           // update startIndex to endIndex + 1
           startIndex = endIndex + 1
       end if

       // increment endIndex by 1
       Set endIndex = endIndex + 1;
   end while
  
   // append the last word to spaceSeparatedSentence string
   spaceSeparatedSentence = spaceSeparatedSentence + runTogetherSentence[startIndex:endIndex]

End Module  

// Module to convert the input string separated by space to pigLatin
Module toPigLatin(String spaceSeparatedSentence, String ref pigLatinSentence)

   // declare an empty list of words
   declare List words
   declare String word
   declare integer i // loop variable
  
   // split the input string where words are separated by spaces to list of strings using space as the delimiter
   words = spaceSeparatedSentence.split(" ")
  
   // set output string to empty string
   pigLatinSentence = ""
  
   // loop over the list of words from index 0 to end
   for i = 0 to length of words-1
   do
       // get the ith word from list
       word = words[i]
       // append the word from second character to end to pigLatinSentence and then append the first character followed by ay and a space
       pigLatinSentence = pigLatinSentence + word[1:] + word[0] + "ay "
      
   end for  
      
   // remove the trailing space from pigLatinSentence
   pigLatinSentence = pigLatinSentence.strip()
  
End Module


Related Solutions

Does anyone know how to do it on EXCEL? Does anyone know how to do it...
Does anyone know how to do it on EXCEL? Does anyone know how to do it on EXCEL? Does anyone know how to do it on EXCEL? Does anyone know how to do it on EXCEL? Anyone know how to do it on EXCEL? The Statistical Abstract of the United States published by the U.S. Census Bureau reports that the average annual consumption of fresh fruit per person is 99.9 pounds. The standard deviation of fresh fruit consumption is about...
Who knows to do this topic with python code? Write a program to perform the following...
Who knows to do this topic with python code? Write a program to perform the following two tasks: 1. The program will accept a string as input in which all of the words are run together, but the first character of each word is uppercase. Convert the string to a string in which the words are separated by spaces and only the first word starts with an uppercase letter. For example, the string "StopAndSmellTheRose" would be converted to "Stop and...
write pseudocode for the following problems not c code Pseudocode only Write a C program to...
write pseudocode for the following problems not c code Pseudocode only Write a C program to print all natural numbers from 1 to n. - using while loop Write a C program to print all natural numbers in reverse (from n to 1). - using while loop Write a C program to print all alphabets from a to z. - using while loop Write a C program to print all even numbers between 1 to 100. - using while loop...
1. Write pseudocode for the following program. You do not have to write actual C++ code....
1. Write pseudocode for the following program. You do not have to write actual C++ code. Assume you have a text file, that has been encrypted by adding 10 to the ASCII value of each character in the message. Design a decryption program that would reverse this process, and display the original message to the console.to the new array. 2.Write the code for the specified program. Use proper style and naming. Test and upload your code as a CPP file....
Does anyone know how to access altitude and azimuth for different objects on Stellarium?
Does anyone know how to access altitude and azimuth for different objects on Stellarium?
Write program logic or pseudocode to create 3 small programs that do the following: The first...
Write program logic or pseudocode to create 3 small programs that do the following: The first should compute the sum of 2 given integers. The second should multiply the 2 integers. The third should triple the sum of the 2 integers.
C Program and pseudocode for this problem. Write a C program that plays the game of...
C Program and pseudocode for this problem. Write a C program that plays the game of "Guess the number" as the following: Your program choose the number to be guessed by selecting an integer at random in the rang of 1 to 1000. The program then asks the use to guess the number. If the player's guess is incorrect, your program should loop until the player finally gets the number right. Your program keeps telling the player "Too High" or...
Who knows how to do pseudocode on this topic? The local driver's license office has asked...
Who knows how to do pseudocode on this topic? The local driver's license office has asked you to design a program that grades the written portion of the driver's license exam. The exam has 20 multiple choice questions. Here are the correct answers: 1. B 2. D 3. A 4. A 5. C 6. A 7. B 8. A 9. C 10. D 11. B 12. C 13. D 14. A 15. D 16. C 17. C 18. B 19....
With the Taft-Hartley act how does anyone know how much is too much relative to union...
With the Taft-Hartley act how does anyone know how much is too much relative to union dues? What is featherbedding and why is that a problem?
write pseudocode not c program If- else programming exercises 1.    Write a C program to find...
write pseudocode not c program If- else programming exercises 1.    Write a C program to find maximum between two numbers. 2.    Write a C program to find maximum between three numbers. 3.    Write a C program to check whether a number is negative, positive or zero. 4.    Write a C program to check whether a number is divisible by 5 and 11 or not. 5.    Write a C program to check whether a number is even or odd. 6.    Write...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT