March R. Smith - University of St Thomas - Minnesota QMCS 130: Today’s Class Revised Lab 14/15Revised Lab 14/15 Counting WordsCounting Words Moving Words/TextMoving Words/Text
March R. Smith - University of St Thomas - Minnesota Labs 14 and 15 Lab 14 is Pig Latin for vowels onlyLab 14 is Pig Latin for vowels only –add ‘way’ to end of words that start with vowels Lab 15 is ‘full’ Pig LatinLab 15 is ‘full’ Pig Latin –The original Lab
March R. Smith - University of St Thomas - Minnesota Preliminary Tasks Use ‘word count’ as a way to develop and test functions we will need for Pig LatinUse ‘word count’ as a way to develop and test functions we will need for Pig Latin Phase 1: Count WordsPhase 1: Count Words Phase 2: Count and copy wordsPhase 2: Count and copy words
March R. Smith - University of St Thomas - Minnesota Counting Words Useful FunctionsUseful Functions –readline – our old friend –wordstart – find start of next word –wordend – find end of current word –countwords – count the words –main – our ‘skeleton’ Solving the problem: countwords()Solving the problem: countwords() –#include –#include –isalpha() –Others on page 473
March R. Smith - University of St Thomas - Minnesota Solving the problem: countwords() –Read a line of text –A loop to find words Find start of a wordFind start of a word Count itCount it Find end of wordFind end of word RepeatRepeat
March R. Smith - University of St Thomas - Minnesota Moving Words Going back to our ‘movewords’ functionGoing back to our ‘movewords’ function The process for handling a line of textThe process for handling a line of text –Start at the beginning of the line –Find start of next word –If there is text before the word, copy it to the output –Find end of the word –Count a word –Copy the word to the output –Repeat the loop Use our ‘movetext’ functionUse our ‘movetext’ function
March R. Smith - University of St Thomas - Minnesota Creative Commons License This work is licensed under the Creative Commons Attribution-Share Alike 3.0 United States License. To view a copy of this license, visit sa/3.0/us/ or send a letter to Creative Commons, 171 Second Street, Suite 300, San Francisco, California, 94105, USA.