Exercise 2-1
authorwatkinsr <ryanwatkins54@gmail.com>
Tue, 2 Jun 2020 17:00:22 +0000 (18:00 +0100)
committerwatkinsr <ryanwatkins54@gmail.com>
Tue, 2 Jun 2020 17:00:22 +0000 (18:00 +0100)
goproglang [new file with mode: 0755]
main.go
tempconv/conv.go [new file with mode: 0644]
tempconv/tempconv.go [new file with mode: 0644]

diff --git a/goproglang b/goproglang
new file mode 100755 (executable)
index 0000000..b1c6903
Binary files /dev/null and b/goproglang differ
diff --git a/main.go b/main.go
index 30b3892db7855b7075e071af3b3f84fc783aa8e1..0d36f5a17f450d77b8d16ec8a50be40e340a42ff 100644 (file)
--- a/main.go
+++ b/main.go
@@ -1,9 +1,14 @@
 package main
 
 import (
-  "git.ryanwatkins.me/goproglang/httpserve"
+  // "git.ryanwatkins.me/goproglang/httpserve"
+  "fmt"
+  "git.ryanwatkins.me/goproglang/tempconv"
 )
 
 func main() {
-  httpserve.Serve()
+  // httpserve.Serve()
+  fmt.Println(tempconv.CToF(tempconv.BoilingC))
+  fmt.Println(tempconv.CToK(tempconv.AbsoluteZeroC))
+  fmt.Println(tempconv.FToK(tempconv.CToF(tempconv.FreezingC)))
 }
diff --git a/tempconv/conv.go b/tempconv/conv.go
new file mode 100644 (file)
index 0000000..b502492
--- /dev/null
@@ -0,0 +1,10 @@
+package tempconv
+
+// CToF converts a Celsius temperature to Fahrenheit.
+func CToF(c Celsius) Fahrenheit { return Fahrenheit(c*9/5 + 32) }
+
+// FToC converts a Fahrenheit temperature to Celsius.
+func FToC(f Fahrenheit) Celsius { return Celsius((f - 32) * 5 / 9) }
+
+func CToK(c Celsius) Kelvin { return Kelvin(c+273.15) }
+func FToK(f Fahrenheit) Kelvin { return Kelvin(FToC(f) + 273.15) }
diff --git a/tempconv/tempconv.go b/tempconv/tempconv.go
new file mode 100644 (file)
index 0000000..c5196e1
--- /dev/null
@@ -0,0 +1,20 @@
+package tempconv
+
+import (
+  "fmt"
+)
+
+type Celsius float64
+type Fahrenheit float64
+type Kelvin float64
+
+const (
+  AbsoluteZeroC Celsius = -273.15
+  FreezingC Celsius = 0
+  BoilingC Celsius = 100
+  zeroK Celsius = -273.15
+)
+
+func (c Celsius) String() string { return fmt.Sprintf("%gC", c) }
+func (f Fahrenheit) String() string { return fmt.Sprintf("%gF", f) }
+func (k Kelvin) String() string { return fmt.Sprintf("%gK", k) }