Advertisement
Guest User

szub

a guest
Feb 25th, 2020
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.24 KB | None | 0 0
  1. var a:Double
  2. var b:Double
  3.  
  4. print("Liczenie pola i obwodu figur")
  5. print("1. Kwadrat")
  6. print("2. Prostakat")
  7. print("3. Trojkat")
  8. print("4. Zakoncz program")
  9. print("Twoj wybor:")
  10. let choice = readLine()
  11.  
  12. switch choice{
  13. case "1":
  14. print("Podaj bok a kwadratu")
  15. a = Double(readLine()!)
  16. print(square(sideA: a))
  17. case "2":
  18. print("Podaj bok a prostokata")
  19. a = Double(readLine()!)
  20. print("Podaj bok b prostokata")
  21. b = Double(readLine()!)
  22. print(rectangle(sideA: a, sideB: b))
  23. case "3":
  24. print("Podaj podstawe a trojkata")
  25. a = Double(readLine()!)
  26. print("Podaj wysokosc b trojkata")
  27. b = Double(readLine()!)
  28. print(triangle(sideA: a, sideB: b))
  29. default:
  30. print("Ta opcja nie istnieje!")
  31. }
  32. func square(sideA: Double) -> Double {
  33. let result = "Pole kwadratu = " + sideA*sideA + "Obwod kwadratu = " + sideA*4
  34. return result
  35. }
  36.  
  37. func rectangle(sideA: Double, sideB: Double) -> Double {
  38. let result = "Pole prostokata = " + sideA*sideB + "Obwod prostokata = " + sideA*2+sideB*2
  39. return result
  40. }
  41.  
  42. func triangle(sideA: Double, sideB: Double, sideC: Double) -> Double {
  43. let result = "Pole trojkata = " + (sideA*sideB)/2 + "Obwod trojkata = " + sideA+sideB+sideC
  44. return result
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement