Advertisement
mikolajmki

swift_lab02

Oct 10th, 2022
560
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Swift 2.59 KB | None | 0 0
  1. /**
  2.  
  3.                             Online Swift Compiler.
  4.                 Code, Compile, Run and Debug Swift script online.
  5. Write your code in this editor and press "Run" button to execute it.
  6.  
  7. */
  8.  
  9. func
  10. howOld ()->
  11.   String
  12. {
  13.   let currentYear = 2022;
  14.  
  15.   print ("Podaj rok swojego urodzenia: ")
  16. let birthDateString:String! = readLine ();
  17.   let yourAge:Int? = currentYear - Int (birthDateString)!;
  18.  
  19.   return "Masz \(yourAge!) lat.";
  20. }
  21.  
  22. func
  23. circleProps ()
  24. {
  25.   print ("Podaj promien kola: ");
  26.  
  27.   let pi = 3.14;
  28.   let radius:String! = readLine ();
  29.   let circumference:Double = 2 * pi * Double (radius)!;
  30.   let field = pi * Double (radius)! * Double (radius)!;
  31.  
  32. print( " Promien kola: \(radius!)\n", "Obwod kola: \(circumference)\n",
  33.     "Pole kola: \(field)")
  34. }
  35.  
  36. func cuboid() -> String {
  37.    
  38.     print("Podaj dlugosc boku szescianu: ");
  39.    
  40.     let cubeSide: String! = readLine();
  41.     let cubeSideFloat: Float = Float(cubeSide)!;
  42.     let volume: Float = cubeSideFloat * cubeSideFloat * cubeSideFloat;
  43.     let totalArea: Float = cubeSideFloat * cubeSideFloat * 6;
  44.    
  45.     return "Szescian ma objetosc \(volume) oraz pole calkowite \(totalArea)";
  46. }
  47.  
  48. func boardPrice() -> Float {
  49.    
  50.     print("Podaj dlugosc pokoju: ");
  51.     let a: String! = readLine();
  52.     print("Podaj szerokosc pokoju: ");
  53.     let b: String! = readLine();
  54.     print("Podaj dlugosc korytarza: ");
  55.     let z: String! = readLine();
  56.     print("Podaj szerokosc drzwi: ");
  57.     let s: String! = readLine()
  58.     print("Podaj cene listwy: ");
  59.     let boardMeterPrice: String! = readLine();
  60.    
  61.     let boardLength: Float = Float(a)! * 2 + Float(b)! * 3 + Float(z)! * 2 - Float(s)!;
  62.     let boardPrice = Float(boardMeterPrice)! * boardLength;
  63.    
  64.     return boardPrice;
  65. }
  66.  
  67. func aritAvg() -> Float {
  68.    
  69.     let aritAvg = (Float.random(in: 1...9) + Float.random(in: 1...9) + Float.random(in: 1...9)) / 3;
  70.     return aritAvg;
  71. }
  72.  
  73. func weigAvg() -> Float {
  74.  
  75.     print("Podaj ocene: ");
  76.     let gr1: String! = readLine();
  77.     print("Podaj jej wage: ");
  78.     let gr1w: String! = readLine();
  79.     print("Podaj ocene: ");
  80.     let gr2: String! = readLine();
  81.     print("Podaj jej wage: ");
  82.     let gr2w: String! = readLine();
  83.     print("Podaj ocene: ");
  84.     let gr3: String! = readLine();
  85.     print("Podaj jej wage: ");
  86.     let gr3w: String! = readLine();
  87.    
  88.     let result = (Float(gr1)! * Float(gr1w)! + Float(gr2)! * Float(gr2w)! +
  89.                   Float(gr3)! * Float(gr3w)!) / (Float(gr1w)! + Float(gr2w)! +
  90.                   Float(gr3w)!);
  91.                  
  92.     return result;
  93. }
  94.  
  95. print(weigAvg());
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement