Advertisement
mikolajmki

swift_lab04

Oct 24th, 2022
595
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Swift 2.78 KB | None | 0 0
  1. //
  2. //  main.swift
  3. //  lab04
  4. //
  5. //  Created by student on 24/10/2022.
  6. //
  7.  
  8. import Foundation
  9.  
  10. func isLeap() {
  11.     guard let year = Int(readLine()!) else {
  12.         fatalError("Not a number!")
  13.     }
  14.     if ((year % 4 == 0 && year % 100 != 0) || year % 400 == 0) {
  15.         print("Podany rok jest przestepny.")
  16.     } else {
  17.         print("Podany rok nie jest przestepny.")
  18.     }
  19. }
  20.  
  21. func century() {
  22.     print("Podaj rok: ")
  23.     guard let cent = Int(readLine()!) else {
  24.         fatalError("Not a number!")
  25.     }
  26.     if (cent >= 2 && cent <= 3010) {
  27.         if (cent % 100 != 0) {
  28.             print("Jest wiek \(cent / 100 + 1)")
  29.         } else {
  30.             print("Jest wiek \(cent / 100)")
  31.         }
  32.     } else {
  33.         print("Podano bledna liczbe!")
  34.     }
  35. }
  36.  
  37. func scholarship() {
  38.     print("Podaj srednia: ")
  39.     guard let avg = Float(readLine()!) else {
  40.         fatalError("Not a number!")
  41.     }
  42.     switch (avg) {
  43.     case 0..<3:
  44.         print("0")
  45.     case 3..<4:
  46.         print("100")
  47.     case 4..<4.51:
  48.         print("150")
  49.     case 4.51..<5.01:
  50.         print("200")
  51.     default:
  52.         print("Podano bledna srednia.")
  53.     }
  54. }
  55.  
  56. func getFloat() -> Float {
  57.     guard let x = Float(readLine()!) else {
  58.         fatalError("Not a number!")
  59.     }
  60.     return x
  61. }
  62.  
  63. func calc() {
  64.     print("Podaj pierwsza liczbe: ")
  65.     let a = getFloat()
  66.     print("Podaj druga liczbe: ")
  67.     let b = getFloat()
  68.     print("1 - dodawnanie, 2 - odejmowanie, 3 - mnozenie, 4 - dzielenie.")
  69.     let c = getFloat()
  70.     var result: Float = 0
  71.     switch (c) {
  72.     case 1:
  73.         result = a + b
  74.     case 2:
  75.         result = a - b
  76.     case 3:
  77.         result = a * b
  78.     case 4:
  79.         if (b != 0) {
  80.             result = a / b
  81.         } else {
  82.             print("Podano 0.")
  83.         }
  84.     default:
  85.         print("Nie podano poprawnego dzialania.")
  86.     }
  87.     print("Wynik: \(result)")
  88. }
  89.  
  90. func zipCode() {
  91.     print("Podaj kod pocztowy: ")
  92.     guard let zc = readLine() else {
  93.         fatalError("Not a string!")
  94.     }
  95.     guard let zcTwo = Int(zc.prefix(2)) else {
  96.         fatalError("Not a number!")
  97.     }
  98.     print(zcTwo)
  99.     switch (zcTwo) {
  100.     case 20..<25:
  101.         print("Kod nalezy do wojewodztwa lubelskiego.")
  102.     default:
  103.         print("Kod nie nalezy do wojewodztwa lubelskiego.")
  104.     }
  105. }
  106.  
  107. func isVowel() {
  108.     print("Podaj litere: ")
  109.     guard let letter = readLine() else {
  110.         fatalError("Not a string!")
  111.     }
  112.     switch (letter) {
  113.     case "a", "e", "i", "o", "u", "y":
  114.         print("Jest to samogloska.")
  115.     case "1", "2", "3", "4", "5", "6", "7", "8", "9":
  116.         print("Jest to liczba.")
  117.     default:
  118.         print("Jest to spolgloska.")
  119.     }
  120.    
  121. }
  122.  
  123. //isLeap()
  124. //century()
  125. //scholarship()
  126. //calc()
  127. //zipCode()
  128. isVowel()
  129.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement