0% found this document useful (0 votes)
416 views12 pages

Final IOS

The document describes three iOS app development practical assignments: 1) Writing Swift functions to check if a number is prime or a string is a palindrome. 2) Creating classes for Person, Student, and Employee with attributes and methods. 3) Developing a "Say Hello" app that displays a greeting with the user's name from a text field.

Uploaded by

wordsofheart500
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)
416 views12 pages

Final IOS

The document describes three iOS app development practical assignments: 1) Writing Swift functions to check if a number is prime or a string is a palindrome. 2) Creating classes for Person, Student, and Employee with attributes and methods. 3) Developing a "Say Hello" app that displays a greeting with the user's name from a text field.

Uploaded by

wordsofheart500
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/ 12

Enrollment no.

: 202203103520100

Practical 1
Aim: Introduction to Swift programming language and X Code IDE. Write
swift functions 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 C MOBILE APPLICATION DEVELOPMENT (IOS)(IT5019)


Enrollment no.: 202203103520100

a. Check whether number is prime or not.

Code:
import UIKit
var greeting = "Hello, playground"
var str = "202203103520100"
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)
}
}

Output:

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


Enrollment no.: 202203103520100

b. Check whether number is palindrome or not.

Code:
import UIKit

var greeting = "Hello, playground"


let s = "202203103520100"
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, 2, 1, 8]
let result1 = checkPalindrome(arr: mArr1)
if result1 == true{
print("Given array is palindrome")
}
else {
print("Given array is not a palindrome")
}
let mArr2 = [9, 1, 2, 3, 1]
let result2 = checkPalindrome(arr: mArr2)
if result2 == true{

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


Enrollment no.: 202203103520100

print("Given array is palindrome")


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

Output:

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


Enrollment no.: 202203103520100

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 C MOBILE APPLICATION DEVELOPMENT (IOS)(IT5019)


Enrollment no.: 202203103520100

class Student : Person


{
var id: Int = 202203103520100
var sem: Int = 6
var div: Character = "c"
var m1: Int = 60
var m2: Int = 55
var m3: Int = 65
init()
{
super.init(name1:"Soham", age1:21, gender1:"Male", city1:"Surat")
}
func result() -> Int
{
let res =
(m1+m2+m3)/3;
print("Result is "+"\(res)")
return res
}
}
print("Soham")
print("202203103520100")
class Employee :
Person
{
var id:Int = 2

var des: String = "Im an Employee"


var sal: Double = 15000

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


Enrollment no.: 202203103520100

var gsal:Double = 0
init()
{
super.init(name1:"Parimal", 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()

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


Enrollment no.: 202203103520100

Output:

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


Enrollment no.: 202203103520100

P
ractical 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:

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 C MOBILE APPLICATION DEVELOPMENT (IOS)(IT5019)


Enrollment no.: 202203103520100

}
}

Output:

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


Enrollment no.: 202203103520100

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"

else

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


Enrollment no.: 202203103520100

l2.text="Odd"

override func viewDidLoad() {

super.viewDidLoad()

// Do any additional setup after loading the view.

}
}

Output:

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

You might also like