Coding Practice¶
How much does Bubba love shrimp? Probably a lot. But how many times does the word “shrimp” come
up in his monologue? Write a function countWord
that counts the number of times a given word
appears in a given string. countWord
should take two strings input
and word
as parameters and return an int
.
Feel free to use the stringToLower
function we wrote earlier. Select the Parsonsprob tab for hints for the construction of the code.
How much does Bubba love shrimp? Probably a lot. But how many times does the word “shrimp” come
up in his monologue? Write a function countWord
that counts the number of times a given word
appears in a given string. countWord
should take two strings input
and word
as parameters and return an int
.
Feel free to use the stringToLower
function we wrote earlier. Use the lines to construct the code, then go back to complete the Activecode tab.
Write a void function removeWord
that removes a given word from a given string and prints
out the new string. removeWord
should take two strings input
and word
as parameters
and prints out input
with every occurence of word
removed. Use string concatenation and the C++
string function substr
. substr
takes two parameters, a starting index and a length. For example,
if string greeting = "hello world"
, then greeting.substr(6, 5)
returns the string "world"
.
Test your function in main. Select the Parsonsprob tab for hints for the construction of the code.
The output should be:
Gucci , Gucci , Gucci , Gucci
Write a void function removeWord
that removes a given word from a given string and prints
out the new string. removeWord
should take two strings input
and word
as parameters
and prints out input
with every occurence of word
removed. Use string concatenation and the C++
string function substr
. substr
takes two parameters, a starting index and a length. For example,
if string greeting = "hello world"
, then greeting.substr(6, 5)
returns the string "world"
.
Test your function in main. Use the lines to construct the code, then go back to complete the Activecode tab.
The output should be:
Gucci , Gucci , Gucci , Gucci
Write the function reverseString
which takes a string input
, reverses it,
and returns the reversed string
. Run and test your code! Select the Parsonsprob
tab for hints for the construction of the code.
Write the function reverseString
which takes a string input
, reverses it,
and returns the reversed string
. Use the lines to construct
the code, then go back to complete the Activecode tab.
Write the function countVowels
which takes a string input
and returns
the number of vowels in the string
. Remember, ‘a’, ‘e’, ‘i’, ‘o’, and ‘u’
are vowels. Run and test your code! Select the Parsonsprob tab for hints for
the construction of the code.
Write the function countVowels
which takes a string input
and returns
the number of vowels in the string
. Remember, ‘a’, ‘e’, ‘i’, ‘o’, and ‘u’
are vowels. Use the lines to construct the code, then go back to complete the Activecode tab.
Camel case is the practice of writing phrases without spaces or punctuation,
indicating the separation of words using capital letter. For example, “camel case”
in camel case is “camelCase”. Snake case is the practice of writing phrases
where each space is replaced by an underscore. For example, “snake case”
in snake case is “snake_case”. Write the functions snakeToCamel
and camelToSnake
.
Each function takes a string input
and returns the input using the other stylization.
Feel free to use any string
functions you’d like. Run and test your code!
Select the Parsonsprob tab for hints for the construction of the code.
Camel case is the practice of writing phrases without spaces or punctuation,
indicating the separation of words using capital letter. For example, “camel case”
in camel case is “camelCase”. Snake case is the practice of writing phrases
where each space is replaced by an underscore. For example, “snake case”
in snake case is “snake_case”. Write the functions snakeToCamel
and camelToSnake
.
Each function takes a string input
and returns the input using the other stylization.
Feel free to use any string
functions you’d like. Use the lines to construct the code,
then go back to complete the Activecode tab.