Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
129 changes: 129 additions & 0 deletions MyPlayground.playground/Contents.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
//Task1

import Darwin
import Foundation
class shape {
func area() -> Double {
return 0
}
func di() -> Double {
return 0
}

}
class circle : shape {
let pi : Double = 3.14
var r : Double = 3
override func area() -> Double {
return (pi * r * r)
}
override func di() -> Double {
return (2 * pi * r)
}
}
class tringle : shape {
var length : Double = 3
var width : Double = 2
var side : Double = 2
override func area() -> Double {
return (width * length)
}
override func di() -> Double {
return (side * side * 2)
}
}
class sequer : shape {
var side : Double = 2
override func area() -> Double {
return (side * side)
}
override func di() -> Double {
return (side * side * side)
}
}
var Circle: circle = circle()
print("area of Circle: ")
print(Circle.area())
print("di of Circle: ")
print(Circle.di())

var Tringle : tringle = tringle ()
print("area of Tringle : ")
print(Tringle .area())
print("di of Tringle : ")
print(Tringle .di())

var Squer: sequer = sequer()
print("area of Sequer:: ")
print(Squer.area())
print("di of quer:: ")
print(Squer.di())


//Task2
struct Book {
var title : String = ""
var auther : String = ""
var pages : Int = 0
var price : Double = 0.0
}
//Task 3
var favoriteBook = Book()
print(favoriteBook.title)
favoriteBook.title = "Math Book"
favoriteBook.auther = "John"
favoriteBook.pages = 66
favoriteBook.price = 99.9
print(favoriteBook.title)
print(favoriteBook.auther)
print(favoriteBook.pages)
print(favoriteBook.price)

//Task4
class sa {
let numbers: [Int] = [1,2,3,4,5,6]
var minn = 0
var maxx = 0
var sum = 0
func ssum() -> Int {
for number in numbers {
sum = sum + number
}
return sum
}
func maxi() -> Int{
return numbers.max()!
}
func mini() -> Int {
return numbers.min()!
}
}
var disb = sa()
print("the sum of all numbers is:")
print(disb.ssum())
print("min is:")
print(disb.mini())
print("max is:")
print(disb.maxi())

//Task 5
class Distance {
var feet : Int
var inches : Int

init() {
feet = 0
inches = 0
}
init (feet: Int , inches: Int){
self.feet = feet
self.inches = inches
}
func displayInInches() -> Int{
return inches
}
}
var distance = Distance()
print("Distance: \(distance.displayInInches())")
var distance2 = Distance(feet: 7 , inches: 8)
print("Distance2: \(distance2.displayInInches())")
4 changes: 4 additions & 0 deletions MyPlayground.playground/contents.xcplayground
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<playground version='5.0' target-platform='ios' buildActiveScheme='true' importAppTypes='true'>
<timeline fileName='timeline.xctimeline'/>
</playground>

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>SchemeUserState</key>
<dict>
<key>MyPlayground (Playground).xcscheme</key>
<dict>
<key>isShown</key>
<false/>
<key>orderHint</key>
<integer>0</integer>
</dict>
</dict>
</dict>
</plist>
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@ Create a variable instance of Book called favoriteBook without supplying any arg
Write a program to create a class that has array of 6 elements. Then, return the sum of the elements in the array, the maximum, minimum value of the array.

5. Task 5:
Create a class called distance that has a separate integer member data for feet and inches. One constructor should initilize this data to zero and another should initilize it to fixed values. A member function should display it in feet onches format.

Create a class called d that has a separate integer member data for feet and inches. One constructor should initilize this data to zero and another should initilize it to fixed values. A member function should display it in feet onches format.

## DeadLine
Wednesday 29 September