CSC 471/371 Programming Assignment 2 Swift Programming

$30.00

Category: Tags: , , , , You will Instantly receive a download link for .zip solution file upon Payment || To Order Original Work Click Custom Order?

Description

5/5 - (6 votes)

CSC 471/371 Mobile Application Development for iOS
Goals
• Explore the Swift programming language
• Write a simple function and a class in Swift
• Experiment with Playground
Assignments
1. Create a new Playground. Include all the code of this assignment in a single
Playground. Compress the Playground to a zipped archive file. Submit the zip file in
D2L
2. Write a function in Swift that performs the following tasks
a. Function rank performs a binary search of a key in a sorted integer array. If
the key appears in the array, the rank function returns the index of key in the
array. If the key does not appear in the array, the rank function returns -1. (A
Java implementation of the rank function can be found in Algorithm, 4th ed. by
R. Sedgewick and K. Wayne, the textbook of the data structures course.)
b. Create a sorted integer array to test the rank function. Make several calls o the
rank function. Verify that the results are correct.
3. Write a more complete version of the Fraction class we have discussed in the lecture.
Start from scratch and type in all the code yourself. (You will learn more from the
mistakes you make along the way.)
a. Add methods to the Fraction class, version 4 (Program 6.6 in the playground
Swift Part 01 – The Basics) to compute the subtraction, multiplication, and
division of two fractions in a similar way to the add method (for the formulae
to compute the subtraction, multiplication, and division of two fractions, see
http://en.wikipedia.org/wiki/Rational_number). Each method should take
another fraction object as the parameter and return the result as a new Fraction
object. The resulting fraction should not have common factors in its
numerator and denominator.
b. Write test code to test each of the new methods of the class with different
input values. Verify that your results are correct.