Starting from:

$25

CS21214-Homework 6 Solved

You have a friend who loves singing karaoke with a big group of people. The karaoke singers add songs they’d like to sing to a list and the karaoke host calls out the songs one by one.  Your friend and has asked you to write software to help manage the song list.

•   Create an empty array to hold song titles as strings, and use the append method to add three or four songs one at a time.

•   One enthusiastic singer wants to add three songs at once. Create an array holding this one singer's song list and use the += operator to append their whole list to the end of the group's song list.

•   Write a for…in loop and, for every song title in the array, print an encouraging announcement to let the next singer know that it's their turn.

•   After the loop has called everyone up to sing, use the removeAll method on the song list to clear out all the past songs.

2) Think of a goal of yours that can be measured in progress every day, whether it’s minutes spent exercising, number of photos sent to friends, hours spent sleeping, or number words written for your novel.

•   Make a class that will track your activity!

•   Give it a description or name

•   Give it a goal

•   Give it an array to keep track of daily entries.  Hint: Make sure to choose the right kind of array for your data, whether [Double] or [Int].

•   Write a function that adds a new data point to the array.

•   Write a function that takes the daily number as an argument and returns true if the goal was met, or false if it was not.

•   Write a function that takes the daily number as an argument and returns a message as a string. It should return a different message based on how close the number comes to your goal. You can be as ambitious and creative as you'd like with your responses, but make sure to return at least two different messages depending on your daily progress!

•   Write a function that takes two numbers (Ints or Doubles depending on your data) and adds them together.

•   Write a function that will print out a summary of your activity.  This function should:

•   Use filter to decide how many times you met or passed your goal this week.

•   Use a map to generate an Array of messages based on your activity data.

•   Join these messages together into one long string, with each message ending with "\n" (new line character) Hint: Reduce or .joined(seperator: String) should work

•   Use reduce to calculate the sum of your activity data.

•   Use the sum and .count to calculate the average of the data.

Create an instance of your class and populate it with at least 7 data points.  Feel free to make up or embellish the numbers, but make sure you have entries that are above, below and exactly at the goal you've thought of. Finally, print the summary of your activity.

Here is my example of how to use this class!

 

3)  Write a function that will return the largest number stored in an array of integers.  (This should sound super familiar!).  Don't use max().

BONUS:  Do it two different ways.  Once as a for...in loop, and once with map/filter/ reduce.  Which solution do you like better and why? func findMax(numbers : [Int]) - Int 

4)  What does the following print?  Don't type this up.  Just follow along with paper.

 

 

More products