Question: 1. Define a value-returning function countCaps(myString) that counts and returns the number of capital letters (letters between 'A' and Z) in the myString parameter (see


1. Define a value-returning function countCaps(myString) that counts and returns the number of capital letters (letters between 'A' and Z) in the myString parameter (see lecture slide 17 for an example) Call the function (in a print statement) three times to test it with different arguments 2. Define of a void function print AllNames. The function will accept a string as parameter. This string has the format firstname/blank)middlename/blank)lastname The function will print out the first name, the middle name and the last name for any name entered as argument) on a separate line How to solve the problem Use the string method find..) to find the indices of the blanks and then apply string slicing. The first name is the substring from Index 0 to the index of the first blank the middle name is the substring from index of the first blank+1 to index of the second blank the last name is the substring from Index of the second blank 1 until the end To find the Index of the second blank the find method needs to use the second parameter defining the start index for the search Call your function with your own name as argument If you do not have a middle name use your English name as your middle name Here is how the program runs for the string 'Rita Zhenzhu Ester" as argument of the function TRI thena 3. Dis a value-returning function replace All Blanks with two parameters The function will replace all blanks in any atting (glvenas parameter) by another character (glven as parameter) and return the changed string co the result string) Do not use the string method replace(...) A possible algorithm to solve the problern (you may find a better solution) Start with an empty result string o Use a string traversal algorithm on the string given as parameter . Check each character If it is a blank, concatenate the replacement character for a blank to the result Coquitlam College CSCI 120C - Spring 2021 Rito Ester Lob 9.1 String Handling 2 otherwise concatenate the original character to the result string Return the result string from the function Call your function in a print statement Here is how the function works when replacing all blank by comma OrLoina at Apples are my FAVOURITE Changedring my tour trust Here is now the function will work when taplacing all blank by a star otherwise concatenate the original character to the result string Return the result string from the function Call your function in a print statement Here is how the function works when replacing all blanks by a comma Original string: Apples are my favourite fruit. Changed string: Apples, are my favourite, fruit. Here is how the function will work when replacing all blanks by a star Original string Apples are my favourite truit. changed string: Apples are myCavourite ruit
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
