adding cs142 code
This commit is contained in:
@@ -0,0 +1,7 @@
|
||||
include $(GOROOT)/src/Make.inc
|
||||
|
||||
TARG=hello
|
||||
GOFILES=\
|
||||
hello.go
|
||||
|
||||
include $(GOROOT)/src/Make.cmd
|
||||
@@ -0,0 +1,7 @@
|
||||
package main
|
||||
|
||||
import "fmt"
|
||||
|
||||
func main() {
|
||||
fmt.Println("hello world! My name is Stephen McQuay.")
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
include $(GOROOT)/src/Make.inc
|
||||
|
||||
TARG=trivia
|
||||
GOFILES=\
|
||||
trivia.go
|
||||
|
||||
include $(GOROOT)/src/Make.cmd
|
||||
@@ -0,0 +1,29 @@
|
||||
package main
|
||||
|
||||
import "fmt"
|
||||
|
||||
type QA struct {
|
||||
question string
|
||||
answer string
|
||||
}
|
||||
|
||||
func main() {
|
||||
fmt.Printf("%48s\n", "Basic BYU Trivia")
|
||||
fmt.Printf("%25s %38s\n\n", "Questions", "Answers")
|
||||
|
||||
qas := []QA{
|
||||
{"What was the original name of BYU?", "Brigham Young Academy"},
|
||||
{"When was BYU established?", "1875"},
|
||||
{"Who was the first \"permanent\" principal of BYA?",
|
||||
"Karl G. Maeser"},
|
||||
{"When did BYA become BYU?", "1903"},
|
||||
{"To what sports conference do we belong?",
|
||||
"Mountain West Conference (MWC)"},
|
||||
{"WHen did BYU win the national football title?", "1984"},
|
||||
{"Who won the Heisman Trophy in 1990?", "Ty Detmer"},
|
||||
}
|
||||
|
||||
for _, v := range qas {
|
||||
fmt.Printf("%-48s %s\n", v.question, v.answer)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
include $(GOROOT)/src/Make.inc
|
||||
|
||||
TARG=binary
|
||||
GOFILES=\
|
||||
binary.go
|
||||
|
||||
include $(GOROOT)/src/Make.cmd
|
||||
@@ -0,0 +1,26 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
)
|
||||
|
||||
func itob(i int) string {
|
||||
var buf [64]byte
|
||||
j := len(buf)
|
||||
b := 2
|
||||
for i > 0 {
|
||||
j--
|
||||
buf[j] = "0123456789abcdefghipqrstuvwxyz"[i%b]
|
||||
i /= b
|
||||
}
|
||||
|
||||
return string(buf[j:])
|
||||
}
|
||||
|
||||
|
||||
func main() {
|
||||
var i int
|
||||
fmt.Print("please enter a number: ")
|
||||
fmt.Scan(&i)
|
||||
fmt.Printf("%d as a binary: %s\n", i, itob(i))
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
include $(GOROOT)/src/Make.inc
|
||||
|
||||
TARG=seconds
|
||||
GOFILES=\
|
||||
seconds.go
|
||||
|
||||
include $(GOROOT)/src/Make.cmd
|
||||
@@ -0,0 +1,36 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"math"
|
||||
)
|
||||
|
||||
const SECONDS_PER_HOUR = 3600
|
||||
const SECONDS_PER_MINUTE = 60
|
||||
|
||||
type time struct {
|
||||
hours int
|
||||
minutes int
|
||||
seconds int
|
||||
}
|
||||
|
||||
func (t time) String() string {
|
||||
return fmt.Sprintf("%dH:%dM:%dS", t.hours, t.minutes, t.seconds);
|
||||
}
|
||||
|
||||
func int2time(i int) time {
|
||||
var r_secs int
|
||||
hours := i / SECONDS_PER_HOUR
|
||||
r_secs = i % SECONDS_PER_HOUR
|
||||
mins := r_secs / SECONDS_PER_MINUTE
|
||||
r_secs = r_secs % SECONDS_PER_MINUTE
|
||||
return time{hours, mins, r_secs}
|
||||
}
|
||||
|
||||
func main() {
|
||||
var seconds int
|
||||
fmt.Print("please enter total seconds: ")
|
||||
fmt.Scan(&seconds)
|
||||
fmt.Printf("%v\n", int2time(seconds))
|
||||
fmt.Printf("%v\n", int2time(int(math.Sqrt(float64(seconds)))))
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
include $(GOROOT)/src/Make.inc
|
||||
|
||||
TARG=temp
|
||||
GOFILES=\
|
||||
temp.go
|
||||
|
||||
include $(GOROOT)/src/Make.cmd
|
||||
@@ -0,0 +1,21 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
)
|
||||
|
||||
func f2c(temp_F float32) float32 {
|
||||
return 5.0/9.0 * (temp_F-32);
|
||||
}
|
||||
|
||||
func main() {
|
||||
var temp_F float32
|
||||
fmt.Print("please enter a temperature: ")
|
||||
fmt.Scan(&temp_F)
|
||||
temp_C := f2c(temp_F)
|
||||
|
||||
fmt.Printf("%0.4fF as:\n", temp_F)
|
||||
fmt.Printf("an int: %dF\n", int(temp_F))
|
||||
fmt.Printf("a celsius float32: %0.4fC\n", temp_C)
|
||||
fmt.Printf("a celcius int: %dC\n", int(temp_C))
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
include $(GOROOT)/src/Make.inc
|
||||
|
||||
TARG=grades
|
||||
GOFILES=\
|
||||
grades.go
|
||||
|
||||
include $(GOROOT)/src/Make.cmd
|
||||
@@ -0,0 +1,10 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
)
|
||||
|
||||
|
||||
func main() {
|
||||
fmt.Println("hello")
|
||||
}
|
||||
Reference in New Issue
Block a user