0% found this document useful (0 votes)
25 views

Final IOS

The document describes three iOS programming practical assignments. The first involves writing Swift functions to check if a number is prime or a palindrome. The second creates a parent Person class with derived Student and Employee classes. The third develops a "Say Hello" app that displays a user's name from a text field when a button is tapped. An extra practical is also included to determine if a number entered in a text field is even or odd.

Uploaded by

rguy5866
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
25 views

Final IOS

The document describes three iOS programming practical assignments. The first involves writing Swift functions to check if a number is prime or a palindrome. The second creates a parent Person class with derived Student and Employee classes. The third develops a "Say Hello" app that displays a user's name from a text field when a button is tapped. An extra practical is also included to determine if a number entered in a text field is even or odd.

Uploaded by

rguy5866
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 13

Enrollment no:202203103520099

Practical 1
Aim: Introduction to Swift programming language and X Code IDE. Write
swiftfunctions for following functionality.

Introduction to Swift:
Swift is a general-purpose programming language developed by Apple. It's used for
developing native iOS and macOS apps, as well as mobile and desktop apps, and cloud
services. Swift is also used for systems programming.

It was introduced in 2014 as a replacement for Objective-C, aiming to provide a more


modern, safe, and efficient language for Apple ecosystem development.

Swift is a multi-paradigm language, meaning it's object-oriented, functional, imperative,


and block-structured. It's also a type-safe language, which means it can help you understand
the types of values your code works with.

Key features of Swift:


• Safety
• Performance
• Expressiveness
• Interoperability
• Open Source

Introduction to Xcode:
Xcode is a free, integrated development environment (IDE) created by Apple for
developing software applications for Apple platforms like iPhones, iPad, MacBooks, etc. It
includes tools for writing, debugging, and testing software, as well as tools for managing
project files and resources. Every IDE consists of three parts: the editor, the debugger, and the
interface builder. The editor is the part where a programmer writes code. The debugger is the
part that informs a programmer of an error and helps him to rectify it. The interface builder is
the part where a programmer works on the visual elements of the app and integrates them with
the code.

Key features of Xcode:


• Interface Builder:
• Code Editor
• Simulator
• Debugger
• Integrated Documentation

CGPIT/CE/SEM-6/A/B/C MOBILE APPLICATION DEVELOPMENT (IOS)


Enrollment no:202203103520099

a. Check whether number is prime or


not. Code:
import UIKit
var greeting = "Hello,
playground" var str =
"202203103520099"
print(str)
func checkingPrimeNumber(num: Int) ->
Bool{ if(num == 1 || num == 0){
return false
}
for j in 2..<num{
if (num % j == 0)
{ return false
}
}
return true
}
var lowerLimit = 1
var upperLimit =
20
print("Range-\(lowerLimit) to \(upperLimit)")
print("Prime numbers are :")
for k in lowerLimit...upperLimit{
if (checkingPrimeNumber(num: k)){
print(k)
}

CGPIT/CE/SEM-6/A/B/C MOBILE APPLICATION DEVELOPMENT (IOS)


Enrollment no:202203103520099

Output:

CGPIT/CE/SEM-6/A/B/C MOBILE APPLICATION DEVELOPMENT (IOS)


Enrollment no:202203103520099

b. Check whether number is palindrome or not.


Code:
import UIKit

var greeting = "Hello,


playground" let s =
"202203103520099"
print(s)

func checkPalindrome(arr: [Int]) -> Bool {


var start = 0
var end = arr.count - 1

while start < end {


if arr[start] != arr[end]
{ return false
}
start += 1
end -= 1
}
return true
}
let mArr1 = [8, 1, 2, 4, 8, 1, 9]
let result1 = checkPalindrome(arr:
mArr1) if result1 == true{
print("Given array is palindrome")
}

CGPIT/CE/SEM-6/A/B/C MOBILE APPLICATION DEVELOPMENT (IOS)


Enrollment no:202203103520099

else {
print("Given array is not a palindrome")
}

let mArr2 = [8, 1, 8, 6, 2]


let result2 = checkPalindrome(arr:
mArr2) if result2 == true{
print("Given array is palindrome")
}
else {
print("Given array is not a palindrome")
}

Output:

CGPIT/CE/SEM-6/A/B/C MOBILE APPLICATION DEVELOPMENT (IOS)


Enrollment no:202203103520099

Practical 2
Aim: Write a program to create parent class Person and derive two classes
from it namely Student and Employee. Classes shall have following
attributes and methods:
a. Person -> name, age, gender, city, get(), set()
b. Student -> id, sem, div, sub1marks, sub2marks, sub3marks, result()
c. Employee-> id, designation, salary, gross_salary()
d. for gross_salary() consider following value: i. if salary < 10000 then
HRA=10%, DA=5%, PF=200 ii. if salary > 10000 then HRA=15%,
DA=7%, PF=10%.
Code:
class Person
{
var name:String
var age:Int
var gender:String
var city:String
init(name1:String, age1:Int, gender1:String, city1:String)
{
name=name1
age=age1
gender=gender1
city=city1
}
func get()
{

print("Name:\(name), Age:\(age), Gender:\(gender), City:\(city)")


}

CGPIT/CE/SEM-6/A/B/C MOBILE APPLICATION DEVELOPMENT (IOS)


Enrollment no:202203103520099

}
class Student : Person
{
var id: Int = 202203103520099
var sem: Int = 6
var div: Character = "c"
var m1: Int = 58
var m2: Int = 70
var m3: Int = 79
init()
{
super.init(name1:"Suhelkhan", age1:20, gender1:"Male", city1:"Surat")
}
func result() -> Int
{
let res = (m1+m2+m3)/3;
print("Result is "+"\(res)")
return res
}
}
print("Suhelkhan")
print("202203103520099")
class Employee : Person
{
var id:Int = 2
var des: String = "Im an
Employee" var sal: Double =
12000
var gsal:Double = 0
init()
{
CGPIT/CE/SEM-6/A/B/C MOBILE APPLICATION DEVELOPMENT (IOS)
Enrollment no:202203103520099

super.init(name1:"Soham", age1:20, gender1:"Male", city1:"Surat")


}
func grossalary() -> Double
{
if(sal<10000)
{
gsal = sal + (sal*0.15) + (sal*0.7) - 200
}
else
{
gsal = sal + (sal*0.15) + (sal*0.7) - (sal*0.10)
}
print("Salary:\(gsal)")
return gsal
}
}
var marko = Student()
marko.get()
marko.result()
var emp = Employee()
emp.get()
emp.grossalary()

Output:

CGPIT/CE/SEM-6/A/B/C MOBILE APPLICATION DEVELOPMENT (IOS)


Enrollment no:202203103520099

Practical 3
Aim: Create an iOS application to develop “Say Hello App”. Use TextField
to get user name as input. On tap of button, display user name with
hello in Label.
Code:
//
// ViewController.swift
// PR_3
//
// Created by bmiit on 05/01/24.
//
import UIKit

class ViewController: UIViewController {

@IBOutlet var name: UITextField!

@IBOutlet var print: UILabel!

@IBAction func submit(_ sender: Any) {

print.text = name.text

override func viewDidLoad() {

super.viewDidLoad()

// Do any additional setup after loading the view.

CGPIT/CE/SEM-6/A/B/C MOBILE APPLICATION DEVELOPMENT (IOS)


Enrollment no:202203103520099

}
}

Output:

CGPIT/CE/SEM-6/A/B/C MOBILE APPLICATION DEVELOPMENT (IOS)


Enrollment no:202203103520099

Extra Practical 3
Code:
//
// ViewController.swift
// odd
//
// Created by bmiit on 12/01/24.
//
import UIKit
class ViewController: UIViewController

@IBOutlet var t1: UITextField!


@IBOutlet var l1: UILabel!
@IBOutlet var l2: UILabel!
@IBAction func btn(_ sender: Any)
{

let t=Int(t1.text!)!

if(t%2==0)

l2.text="Even"

CGPIT/CE/SEM-6/A/B/C MOBILE APPLICATION DEVELOPMENT (IOS)


Enrollment no:202203103520099

else

CGPIT/CE/SEM-6/A/B/C MOBILE APPLICATION DEVELOPMENT (IOS)


Enrollment no:202203103520099

l2.text="Odd"

override func viewDidLoad() {

super.viewDidLoad()

// Do any additional setup after loading the view.

}
}

Output:

CGPIT/CE/SEM-6/A/B/C MOBILE APPLICATION DEVELOPMENT (IOS)

You might also like