Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package main
- import (
- "fmt"
- "os"
- "os/exec"
- "runtime"
- )
- const N = 99999
- type data struct {
- id int
- sekul string
- kls int
- pel string
- smt int
- silb string
- mat string
- }
- type arr[N] data
- var T arr
- var tot int
- var clear map[string]func() //create a map for storing clear funcs
- func init() {
- clear = make(map[string]func()) //Initialize it
- clear["linux"] = func() {
- cmd := exec.Command("clear") //Linux example, its tested
- cmd.Stdout = os.Stdout
- cmd.Run()
- }
- clear["windows"] = func() {
- cmd := exec.Command("cmd", "/c", "cls") //Windows example, its tested
- cmd.Stdout = os.Stdout
- cmd.Run()
- }
- }
- func CallClear() {
- value, ok := clear[runtime.GOOS] //runtime.GOOS -> linux, windows, darwin etc.
- if ok { //if we defined a clear func for that platform:
- value() //we execute it
- } else { //unsupported platform
- panic("Your platform is unsupported! I can't clear terminal screen :(")
- }
- }
- var key string
- // PROGRAM UTAMA
- func main() {
- var c string
- var x int
- CallClear()
- fmt.Println(".::Selamat Datang di aplikasi DARING 1::.")
- fmt.Println("==========================================\n")
- fmt.Print("Ketik 'yes' jika ingin lanjut : ")
- fmt.Scan(&c)
- if c == "yes" {
- CallClear()
- menuUtama(x)
- } else {
- fmt.Println()
- fmt.Println("==========================================\n")
- fmt.Print("Terima Kasih :)")
- }
- }
- // End
- //MENU UTAMA
- func menuUtama(x int) {
- fmt.Println(".::::::::::::::::::::::::::::::::::::::::::.")
- fmt.Print("(1. Insert) (2. View) (0. Exit)\n")
- fmt.Print("::::::::::::::::::::::::::::::::::::::::::::\nPilih : ")
- fmt.Scan(&x)
- CallClear()
- if x == 1 {
- fmt.Print("insert")
- insert(&T,&tot)
- }else if x == 2 {
- menuView(x)
- }else if x==3{
- main()
- }
- }
- //MENU VIEW
- func menuView(x int){
- fmt.Print(".::::::::::::::::::::::::::::::::::::::::::::::::::::::::.\n")
- fmt.Print("(1. Edit) (2. Delete) (3. Cari) (4. Sorting) (0. Exit)\n")
- fmt.Print("::::::::::::::::::::::::::::::::::::::::::::::::::::::::::\nPilih : ")
- fmt.Scan(&x)
- CallClear()
- if x == 1 {
- fmt.Print("EDIT")
- menuEdit(&T)
- menuUtama(x)
- } else if x == 2 {
- fmt.Print("DELETE")
- menuDelete(&T)
- menuUtama(x)
- } else if x == 3 {
- fmt.Print("CARI")
- menuCari(&T)
- menuUtama(x)
- } else if x == 4 {
- fmt.Print("SORTING")
- menuSort(&T)
- //}else if x==0{
- // menuUtama(x)
- } else if x == 0 {
- menuUtama(x)
- }
- }
- //MENU INSERT
- func insert(T *arr, tot *int) {
- var confirm string
- var i,x int
- var id int
- i=*tot
- id=*tot
- fmt.Print("::::::::::::::::::::::::::::::::::::::::::::\n")
- fmt.Print("Apakah Ingin Input : ")
- fmt.Scan(&confirm)
- fmt.Print("::::::::::::::::::::::::::::::::::::::::::::\n")
- for (confirm != "no") && (i < N) {
- id++
- T[i].id = id
- fmt.Print("Sekolah : ")
- fmt.Scan(&T[i].sekul)
- fmt.Print("Kelas : ")
- fmt.Scan(&T[i].kls)
- fmt.Print("Pelajaran : ")
- fmt.Scan(&T[i].pel)
- fmt.Print("Semester : ")
- fmt.Scan(&T[i].smt)
- fmt.Print("Silabus : ")
- fmt.Scan(&T[i].silb)
- fmt.Print("Materi : ")
- fmt.Scan(&T[i].mat)
- CallClear()
- i++
- *tot++
- fmt.Print("::::::::::::::::::::::::::::::::::::::::::::\n")
- fmt.Print("Apakah anda ingin input lagi : ")
- fmt.Scan(&confirm)
- fmt.Print("::::::::::::::::::::::::::::::::::::::::::::\n")
- }
- CallClear()
- menuUtama(x)
- }
- func menuCari( T *arr) data {
- var x,sum, i, klas int
- var s string
- i = 0
- fmt.Println(".::::::::::::::::::::::::::::::::::.")
- fmt.Print("(1. Pelajaran) (2. Kelas) (0. Exit)\n")
- fmt.Print("====================================\nCari Berdasarkan : ")
- fmt.Scan(&x)
- if (x == 1) {
- fmt.Print("Pelajaran : ")
- fmt.Scan(&s)
- } else if (x == 2) {
- fmt.Print("Kelas : ")
- fmt.Scan(&klas)
- } else if (x == 0) {
- CallClear()
- menuUtama(x)
- } else {
- menuCari(&*T)
- }
- for (i < tot) {
- if (s == T[i].pel || klas == T[i].kls) {
- fmt.Println(".::::::::::::::::::::::::::::::::::::.")
- fmt.Println("ID : ",T[i].id)
- fmt.Println("Sekolah : ",T[i].sekul)
- fmt.Println("Kelas : ",T[i].kls)
- fmt.Println("Pelajaran : ",T[i].pel)
- fmt.Println("Semester : ",T[i].smt)
- fmt.Println("Silabus : ",T[i].silb)
- fmt.Println("Materi : ",T[i].mat)
- fmt.Println("::::::::::::::::::::::::::::::::::::::")
- sum++
- }
- i++
- }
- if sum <= 0 {
- fmt.Println("Data Tidak Ditemukan")
- }
- fmt.Print("Ketik '0' jika ingin Exit : ")
- fmt.Scan(&x)
- if x == 0 {
- CallClear()
- menuUtama(x)
- } else {
- menuCari(&*T)
- }
- return(T[i])
- }
- //MENU DELETE
- func menuDelete(T *arr) {
- var x,i int
- var found bool
- i = 0
- found = false
- fmt.Print("Input ID data yang ingin di hapus : ")
- fmt.Scan(&x)
- for (i < tot) && (found == false) {
- if T[i].id == x {
- found = true
- T[i].sekul = ""
- T[i].kls = -1
- T[i].pel = ""
- T[i].smt = -1
- T[i].silb = ""
- T[i].mat = ""
- }
- i++
- }
- if found == true {
- fmt.Println("Data Berhasil Dihapus")
- }
- fmt.Print("Ketik '0' jika ingin Exit : ")
- fmt.Scan(&x)
- if x == 0 {
- CallClear()
- menuUtama(x)
- } else {
- menuDelete(&*T)
- }
- }
- //MENU EDIT
- func menuEdit(T *arr){
- var x, i, y int
- var c string
- var found bool
- i = 0
- found = false
- c = "no"
- for c != "yes" {
- fmt.Print("Input ID data yang ingin di Edit : ")
- fmt.Scan(&x)
- for (i < tot) && (found == false) {
- if T[i].id == x {
- found = true
- fmt.Println(".::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::.")
- fmt.Print("(1. Sekolah) (2. Kelas) (3. Pelajaran) (4. Semester) (5. Silabus) (6. Materi) (0. Exit)\n")
- fmt.Print("Pilih yang akan di Edit : ")
- fmt.Scan(&x)
- switch x {
- case 1:
- fmt.Print("Input Sekolah : ")
- fmt.Scan(&T[i].sekul)
- case 2:
- fmt.Print("Input Kelas : ")
- fmt.Scan(&T[i].kls)
- case 3:
- fmt.Print("Input Pelajaran : ")
- fmt.Scan(&T[i].pel)
- case 4:
- fmt.Print("Input Semester : ")
- fmt.Scan(&T[i].smt)
- case 5:
- fmt.Print("Input Silabus : ")
- fmt.Scan(&T[i].silb)
- case 6:
- fmt.Print("Input Materi : ")
- fmt.Scan(&T[i].mat)
- default :
- menuUtama(y)
- }
- }
- i++
- }
- fmt.Println("Sudah Selesai Edit ")
- fmt.Scan(&c)
- }
- if found == true {
- fmt.Println("Data Berhasil Diedit")
- }
- fmt.Print("Ketik '0' jika ingin Exit : ")
- fmt.Scan(&x)
- if x == 0 {
- CallClear()
- menuUtama(y)
- } else {
- menuEdit(&*T)
- }
- }
- func menuSort(T *arr){
- var a,b,x int
- fmt.Println("Sorting \n1.Ascending \n2.Descending")
- fmt.Scan(&a)
- if a==1{
- fmt.Println("Berdasarkan : \n1.Sekolah \n2.Materi")
- fmt.Scan(&b)
- if b==1{
- //SELECTION SORT ASCENDING
- for i := 1; i < tot; i++ {
- j := i
- for j > 0 && T[j].sekul < T[j-1].sekul && T[j].id!=0 && T[j-1].id!=0{
- T[j], T[j-1] = T[j-1], T[j]
- j -= 1
- }
- }
- hasilSort()
- }else if b==2{
- //SELECTION SORT DESCENDING
- for i := 1; i < tot; i++ {
- j := i
- for j > 0 && T[j].mat <T[j-1].mat && T[j].id!=0 && T[j-1].id!=0{
- T[j], T[j-1] = T[j-1], T[j]
- j -= 1
- }
- }
- hasilSort()
- }
- }else if a==2{
- fmt.Println("Berdasarkan : \n1.Sekolah \n2.Materi")
- fmt.Scan(&b)
- if b==1{
- //INSERTION SORT DESCENDING
- for j := 0; j < tot; j++ {
- minPos := j
- for i := j + 1; i < tot; i++ {
- if T[i].sekul > T[minPos].sekul && T[i].id!=0 && T[minPos].id!=0{
- minPos = i
- }
- }
- T[j], T[minPos] = T[minPos], T[j]
- }
- hasilSort()
- }else if b==2{
- for j := 0; j < tot; j++ {
- minPos := j
- for i := j + 1; i < tot; i++ {
- if T[i].mat > T[minPos].mat && T[i].id!=0 && T[minPos].id!=0 {
- minPos = i
- }
- }
- T[j], T[minPos] = T[minPos], T[j]
- }
- hasilSort()
- }
- }
- menuUtama(x)
- }
- func hasilSort(){
- for i:=0; i<tot; i++{
- fmt.Print(T[i], " ")
- }
- fmt.Print("\n")
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement