Question: Using Swift - Xcode Please post your code Programming Challenge Read the comments in front of each section of code. They will give the specific

Using Swift - Xcode Please post your code

Programming Challenge

Read the comments in front of each section of code. They will give the specific directions for each problem so read carefully. Follow the directions for each. Include your name and Section on this playground page or you will receive a 0 for the Challenge.

//Complete this string analysis method using a Switch statement

Take note of a correction to our notes on the Range operators. In the slides it originally said that Ranges do not work with types other than Int. That is not exactly accurate.

Ranges can also be defined with Character values that correspond to single Unicode Scalars similar to the ASCII values we already know. However these kinds of ranges are not iterable (Because of Swift's dependence on Extended Grapheme Clusters) and we cannot loop through them as we can with countable whole numbers.

/keeping the above information in mind, complete the methods below

/***

Swift's for-in loop can be used to loop over characters in a String value natively. The following method has a for-in skeleton set up for

you to iterate through all the Characters in a String. Inside the body of the for-in loop, use a Switch to analyze the String and keep

track and count the total number of capital Letters, lower case letters, digits, spaces (including tabs), and lines that appear in any

String value. If the String is empty, print a message to the user and exit the loop early using a guard Statement.

input: """

Hi this is a test string for the exam

1 and you will need to check everything

against it, maybe 10000_00 times.

"""

output: Numbers: 8 Letters: 79 Spaces 19 Lines: 3

input: "I am working on this exam, when I should probably be Sleeping, it is 3 AM"

output: Numbers: 1 Letters: 55 Spaces 15 Lines: 1

input: "12343qwzdfsrt43 Oh no, I just woke up at the keyboard"

output: Numbers: 7 Letters: 36 Spaces 9 Lines: 1

**EXTRA CREDIT: Track all of the punctuation as well. +3 pts

***/

//: remember to use control transfer statement `continue` to skip a single iteration of a loop and the keyword `break` to exit a loop early

func analyze(this sentence: String){

var numCount: Int

var charCount: Int

var spaceCount: Int

var lineCount : Int

for c in sentence {

}

}

//for the following functions please only supply the one parameterName specified in the instructions

/* Word Counter

Write a function named *wordCounter* that will accept any given *String input named entryString* and

(using the for-in loop from the previous function as an example) write a function that counts how many words

are in the String and *returns the total number of words* (assume all words are bounded by spaces or commas

or periods.) You can use any method from the String Type to accomplish this.

input: "Hi, this is a test String."

output: 6

input: "Hello, World"

output: 2

input: "Hi, hey, hello"

output: 3

*/

/*

Consonants & Vowels

Write an algorithm which sorts a string into its consonants and vowels.

For any given *String input named entryString*, your output should be a tuple with one member being a string

containing all the consonants and another member being a string containing all

the vowels.

input: "Hello, World!"

output: (consonants: "HllWrld", vowels: "eoo")

input: "Reddit"

output: (consonants: "Rddt", vowels: "ei")

input: "sequoia"

output: (consonants: "sq", vowels: "euoia")

*/

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!