Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function sentence_filter(sentence){
- GET sentence;
- GLOBAL sentenceLoop;
- UPPERCASE sentence;
- for (SET punctuation;punctuation in sentence?;REMOVE punctuation in sentence) // FOR
- SET checkSentence = (REMOVE spaces in sentence);
- if(checkSentence is empty?) // IF
- /OUTPUT "ERROR! You did not enter in a sentence."/;
- else // ELSE
- SET sentenceLoop to False;
- return sentence; // RETURN
- }
- function word_filter(word, sentence){
- GET sentence;
- GLOBAL wordLoop;
- UPPERCASE sentence;
- for (SET punctuation;punctuation in word?;REMOVE punctuation in word) // FOR
- SET wordLength to (COUNT how many words are in word);
- REMOVE spaces in word;
- if (word equal to ""?) // IF
- /OUTPUT "ERROR! You did not enter in a word."/;
- else if (wordLength more than 1?) // ELSE IF
- /OUTPUT ("ERROR! You entered in more than one word.")/;
- else if (word not in sentence?) // ELSE IF
- /OUTPUT "ERROR! The word is not in the sentence."/;
- else // ELSE
- SET wordLoop to False;
- return word; // RETURN
- }
- function word_locate(sentence, word){
- GET sentence and word;
- SPLIT sentence;
- SET wordPositions to “”;
- SET loopCounter to 0;
- SET wordCount to (COUNT the times the word is in the sentence);
- while (loopCounter < wordCount){ // WHILE
- SET position to (INDEX the first occurrence of the word in the sentence);
- REPLACE first occurrence of the word in sentence with any punctuation ;
- ADD 1 to position;
- CAST string to position;
- APPEND (position with a space after it) to wordPositions;
- ADD 1 to loopCounter;
- }
- return wordPositions; // RETURN
- }
- function restart(decision){
- GET decision;
- GLOBAL mainLoop;
- GLOBAL decisionLoop;
- UPPERCASE decision;
- if (decision equal "Y"?) // IF
- decision = "The program has restarted.";
- else if (decision equal "N"?) // ELSE IF
- SET decision = "The program has ended.";
- SET decisionLoop to False;
- SET mainLoop to False;
- else // ELSE
- SET decision = "ERROR! You did not enter in a decision.";
- return decision; // RETURN
- }
- START;
- SET mainLoop to True;
- while (mainLoop equals to True){ // WHILE
- /OUTPUT "A453 - Programming Project - Task 1"/;
- SET sentenceLoop to True;
- while (sentenceLoop equals to True){ // WHILE
- /OUTPUT "Enter in a sentence."/;
- /INPUT sentence/;
- call sentence_filter(sentence); // FUNCTION
- }
- /OUTPUT sentence/;
- SET wordLoop to True;
- while (wordLoop equals to True){ // WHILE
- /OUTPUT "Enter in a word."/;
- /INPUT word/;
- call word_filter(word, sentence); FUNCTION
- }
- /OUTPUT word/;
- call word_locate(sentence, word); // FUNCTION
- /OUTPUT wordPositions/;
- SET decisionLoop to True;
- while (decisionLoop equals True){ // WHILE
- /OUTPUT "Would you like to restart the program? (Y/N)"/;
- /INPUT decision/;
- call restart(decision); // FUNCTION
- }
- /OUTPUT decision/;
- }
- END;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement