0% found this document useful (0 votes)
9 views7 pages

Lab#5 - Tagged

The document describes exercises for an iOS development lab. It includes exercises to write functions that generate random numbers, perform basic math operations, return multiple values from functions, and manipulate string values using inout parameters.

Uploaded by

monera ALmousa
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views7 pages

Lab#5 - Tagged

The document describes exercises for an iOS development lab. It includes exercises to write functions that generate random numbers, perform basic math operations, return multiple values from functions, and manipulate string values using inout parameters.

Uploaded by

monera ALmousa
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

Ministry of Education

‫لتعليم‬$ ‫وزارة ا‬
Imam Abdulrahman Bin ‫ة‬$‫ع‬$‫ام‬$‫ج‬ ‫يصل‬$$‫نف‬$$$‫ب‬
‫من‬$‫لرح‬$$‫المام عبدا‬$$‫ا‬
Faisal University
Applied College ‫لكلية‬$$‫ا‬
‫لتطبيقية‬$ ‫ا‬

IOS DEVELOPMENT-1
COMP224

Lab (5)
EXERCISE (1)

• Write a function called magicEightBall that generates a


random number.
• Use a switch statement to print different responses based on
the random number generated.
Note: use the following line of code to generate a random
number from 0 to 4
let randomNum = Int.random(in: 0...4)
• Call the function multiple times and observe the different
output.
EXERCISE (2)

• Write a function called almostAddition that takes two Int


arguments.
• The first argument should not require an argument label.
• The function should add the two arguments together, subtract
2, then print the result.
• Call the function and observe the printout.
• Rewrite the function with default value = 10 for the first
argument.
EXERCISE (3)

• Write a function called multiply that takes two Double


arguments.
• The function should multiply the two arguments and print the
result.
• The first argument should not require a label, and the second
argument should have an external label, "by", that differs from
the internal label. Call the function and observe the printout.
EXERCISE (4)

• Write a function called AvgOf that takes three Double


arguments.
• The function returns the average of three numbers and the
smallest number.
• Call the function with different arguments.
• Rewrite the function with optional tuple return type.
• Rewrite the function using variadic parameters.
EXERCISE (5)

• Write a function called square with variadic parameters that


can square many numbers and print the result.
• For example, if the input parameter is 2, the function should
prints:
“The square of 2 is 4 “.
• Call the function with this parameters: square (2, 8, 5, 4)
EXERCISE (6)

• Write a function called addString that accepts two string


arguments: str1 and str2.
• Concatenate both strings into str1.
• Insert * in the beginning and * in the end of the str1 string.
• Call the function and Print str1 and str2.
• Hints: use inout parameters.

You might also like