Advertisement
sabdas4869

parameter

Nov 27th, 2019
141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.84 KB | None | 0 0
  1. package main
  2.  
  3. import (
  4. "fmt"
  5. "os"
  6. "os/exec"
  7. "runtime"
  8. )
  9.  
  10. const N = 99999
  11.  
  12. type data struct {
  13. id int
  14. sekul string
  15. kls int
  16. pel string
  17. smt int
  18. silb string
  19. mat string
  20. }
  21. type arr[N] data
  22.  
  23. var T arr
  24. var tot int
  25.  
  26. var clear map[string]func() //create a map for storing clear funcs
  27.  
  28. func init() {
  29. clear = make(map[string]func()) //Initialize it
  30. clear["linux"] = func() {
  31. cmd := exec.Command("clear") //Linux example, its tested
  32. cmd.Stdout = os.Stdout
  33. cmd.Run()
  34. }
  35. clear["windows"] = func() {
  36. cmd := exec.Command("cmd", "/c", "cls") //Windows example, its tested
  37. cmd.Stdout = os.Stdout
  38. cmd.Run()
  39. }
  40. }
  41.  
  42. func CallClear() {
  43. value, ok := clear[runtime.GOOS] //runtime.GOOS -> linux, windows, darwin etc.
  44. if ok { //if we defined a clear func for that platform:
  45. value() //we execute it
  46. } else { //unsupported platform
  47. panic("Your platform is unsupported! I can't clear terminal screen :(")
  48. }
  49. }
  50.  
  51. var key string
  52.  
  53. // PROGRAM UTAMA
  54. func main() {
  55. var c string
  56. var x int
  57.  
  58. CallClear()
  59. fmt.Println(".::Selamat Datang di aplikasi DARING 1::.")
  60. fmt.Println("==========================================\n")
  61. fmt.Print("Ketik 'yes' jika ingin lanjut : ")
  62. fmt.Scan(&c)
  63. if c == "yes" {
  64. CallClear()
  65. menuUtama(x)
  66. } else {
  67. fmt.Println()
  68. fmt.Println("==========================================\n")
  69. fmt.Print("Terima Kasih :)")
  70.  
  71. }
  72. }
  73. // End
  74. //MENU UTAMA
  75. func menuUtama(x int) {
  76.  
  77. fmt.Println(".::::::::::::::::::::::::::::::::::::::::::.")
  78. fmt.Print("(1. Insert) (2. View) (0. Exit)\n")
  79. fmt.Print("::::::::::::::::::::::::::::::::::::::::::::\nPilih : ")
  80. fmt.Scan(&x)
  81. CallClear()
  82.  
  83. if x == 1 {
  84. fmt.Print("insert")
  85. insert(&T,&tot)
  86. }else if x == 2 {
  87. menuView(x)
  88. }else if x==3{
  89. main()
  90. }
  91.  
  92. }
  93. //MENU VIEW
  94. func menuView(x int){
  95. fmt.Print(".::::::::::::::::::::::::::::::::::::::::::::::::::::::::.\n")
  96. fmt.Print("(1. Edit) (2. Delete) (3. Cari) (4. Sorting) (0. Exit)\n")
  97. fmt.Print("::::::::::::::::::::::::::::::::::::::::::::::::::::::::::\nPilih : ")
  98. fmt.Scan(&x)
  99. CallClear()
  100. if x == 1 {
  101. fmt.Print("EDIT")
  102. menuEdit(&T)
  103. menuUtama(x)
  104. } else if x == 2 {
  105. fmt.Print("DELETE")
  106. menuDelete(&T)
  107. menuUtama(x)
  108. } else if x == 3 {
  109. fmt.Print("CARI")
  110. menuCari(&T)
  111. menuUtama(x)
  112. } else if x == 4 {
  113. fmt.Print("SORTING")
  114. menuSort(&T)
  115. //}else if x==0{
  116. // menuUtama(x)
  117. } else if x == 0 {
  118. menuUtama(x)
  119.  
  120. }
  121.  
  122. }
  123. //MENU INSERT
  124. func insert(T *arr, tot *int) {
  125. var confirm string
  126. var i,x int
  127. var id int
  128. i=0
  129. *tot = 0
  130. fmt.Print("::::::::::::::::::::::::::::::::::::::::::::\n")
  131. fmt.Print("Apakah Ingin Input : ")
  132. fmt.Scan(&confirm)
  133. fmt.Print("::::::::::::::::::::::::::::::::::::::::::::\n")
  134. for (confirm != "no") && (i < N) {
  135. id++
  136.  
  137. T[i].id = id
  138. fmt.Print("Sekolah : ")
  139. fmt.Scan(&T[i].sekul)
  140. fmt.Print("Kelas : ")
  141. fmt.Scan(&T[i].kls)
  142. fmt.Print("Pelajaran : ")
  143. fmt.Scan(&T[i].pel)
  144. fmt.Print("Semester : ")
  145. fmt.Scan(&T[i].smt)
  146. fmt.Print("Silabus : ")
  147. fmt.Scan(&T[i].silb)
  148. fmt.Print("Materi : ")
  149. fmt.Scan(&T[i].mat)
  150. CallClear()
  151. i++
  152. *tot++
  153. fmt.Print("::::::::::::::::::::::::::::::::::::::::::::\n")
  154. fmt.Print("Apakah anda ingin input lagi : ")
  155. fmt.Scan(&confirm)
  156. fmt.Print("::::::::::::::::::::::::::::::::::::::::::::\n")
  157. }
  158. CallClear()
  159. menuUtama(x)
  160. }
  161.  
  162. func menuCari( T *arr) data {
  163. var x,sum, i, klas int
  164. var s string
  165.  
  166. i = 0
  167. fmt.Println(".::::::::::::::::::::::::::::::::::.")
  168. fmt.Print("(1. Pelajaran) (2. Kelas) (0. Exit)\n")
  169. fmt.Print("====================================\nCari Berdasarkan : ")
  170. fmt.Scan(&x)
  171. if (x == 1) {
  172. fmt.Print("Pelajaran : ")
  173. fmt.Scan(&s)
  174. } else if (x == 2) {
  175. fmt.Print("Kelas : ")
  176. fmt.Scan(&klas)
  177. } else if (x == 0) {
  178. CallClear()
  179. menuUtama(x)
  180. } else {
  181. menuCari(&*T)
  182. }
  183.  
  184. for (i < tot) {
  185. if (s == T[i].pel && klas == T[i].kls) {
  186. fmt.Println(".::::::::::::::::::::::::::::::::::::.")
  187. fmt.Println("ID : ",T[i].id)
  188. fmt.Println("Sekolah : ",T[i].sekul)
  189. fmt.Println("Kelas : ",T[i].kls)
  190. fmt.Println("Pelajaran : ",T[i].pel)
  191. fmt.Println("Semester : ",T[i].smt)
  192. fmt.Println("Silabus : ",T[i].silb)
  193. fmt.Println("Materi : ",T[i].mat)
  194. fmt.Println("::::::::::::::::::::::::::::::::::::::")
  195. sum++
  196. }
  197. i++
  198. }
  199.  
  200. if sum <= 0 {
  201. fmt.Println("Data Tidak Ditemukan")
  202. }
  203. fmt.Print("Ketik '0' jika ingin Exit : ")
  204. fmt.Scan(&x)
  205. if x == 0 {
  206. CallClear()
  207. menuUtama(x)
  208. } else {
  209. menuCari(&*T)
  210. }
  211. return(T[i])
  212. }
  213. //MENU DELETE
  214. func menuDelete(T *arr) {
  215. var x,i int
  216. var found bool
  217.  
  218. i = 0
  219. found = false
  220. fmt.Print("Input ID data yang ingin di hapus : ")
  221. fmt.Scan(&x)
  222.  
  223. for (i < tot) && (found == false) {
  224. if T[i].id == x {
  225. found = true
  226. T[i].sekul = ""
  227. T[i].kls = -1
  228. T[i].pel = ""
  229. T[i].smt = -1
  230. T[i].silb = ""
  231. T[i].mat = ""
  232. }
  233. i++
  234. }
  235. if found == true {
  236. fmt.Println("Data Berhasil Dihapus")
  237. }
  238.  
  239. fmt.Print("Ketik '0' jika ingin Exit : ")
  240. fmt.Scan(&x)
  241. if x == 0 {
  242. CallClear()
  243. menuUtama(x)
  244. } else {
  245. menuDelete(&*T)
  246. }
  247. }
  248. //MENU EDIT
  249. func menuEdit(T *arr){
  250. var x, i, y int
  251. var c string
  252. var found bool
  253.  
  254. i = 0
  255. found = false
  256. c = "no"
  257.  
  258. for c != "yes" {
  259. fmt.Print("Input ID data yang ingin di Edit : ")
  260. fmt.Scan(&x)
  261.  
  262. for (i < tot) && (found == false) {
  263.  
  264. if T[i].id == x {
  265. found = true
  266. fmt.Println(".::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::.")
  267. fmt.Print("(1. Sekolah) (2. Kelas) (3. Pelajaran) (4. Semester) (5. Silabus) (6. Materi) (0. Exit)\n")
  268. fmt.Print("Pilih yang akan di Edit : ")
  269. fmt.Scan(&x)
  270.  
  271. switch x {
  272. case 1:
  273. fmt.Print("Input Sekolah : ")
  274. fmt.Scan(&T[i].sekul)
  275. case 2:
  276. fmt.Print("Input Kelas : ")
  277. fmt.Scan(&T[i].kls)
  278. case 3:
  279. fmt.Print("Input Pelajaran : ")
  280. fmt.Scan(&T[i].pel)
  281. case 4:
  282. fmt.Print("Input Semester : ")
  283. fmt.Scan(&T[i].smt)
  284. case 5:
  285. fmt.Print("Input Silabus : ")
  286. fmt.Scan(&T[i].silb)
  287. case 6:
  288. fmt.Print("Input Materi : ")
  289. fmt.Scan(&T[i].mat)
  290. default :
  291. menuUtama(y)
  292. }
  293.  
  294. }
  295.  
  296. i++
  297. }
  298.  
  299. fmt.Println("Sudah Selesai Edit ")
  300. fmt.Scan(&c)
  301. }
  302.  
  303. if found == true {
  304. fmt.Println("Data Berhasil Diedit")
  305. }
  306.  
  307. fmt.Print("Ketik '0' jika ingin Exit : ")
  308. fmt.Scan(&x)
  309. if x == 0 {
  310. CallClear()
  311. menuUtama(y)
  312. } else {
  313. menuEdit(&*T)
  314. }
  315. }
  316. func menuSort(T *arr){
  317.  
  318. var a,b,x int
  319.  
  320.  
  321.  
  322. fmt.Println("Sorting \n1.Ascending \n2.Descending")
  323. fmt.Scan(&a)
  324. if a==1{
  325. fmt.Println("Berdasarkan : \n1.Sekolah \n2.Materi")
  326. fmt.Scan(&b)
  327. if b==1{
  328.  
  329. //SELECTION SORT ASCENDING
  330.  
  331. for i := 1; i < tot; i++ {
  332. j := i
  333. for j > 0 && T[j].sekul < T[j-1].sekul && T[j].id!=0 && T[j-1].id!=0{
  334. T[j], T[j-1] = T[j-1], T[j]
  335. j -= 1
  336. }
  337.  
  338. }
  339. hasilSort()
  340. }else if b==2{
  341.  
  342. //SELECTION SORT DESCENDING
  343.  
  344. for i := 1; i < tot; i++ {
  345. j := i
  346. for j > 0 && T[j].mat <T[j-1].mat && T[j].id!=0 && T[j-1].id!=0{
  347. T[j], T[j-1] = T[j-1], T[j]
  348. j -= 1
  349. }
  350.  
  351. }
  352. hasilSort()
  353. }
  354. }else if a==2{
  355. fmt.Println("Berdasarkan : \n1.Sekolah \n2.Materi")
  356. fmt.Scan(&b)
  357. if b==1{
  358.  
  359. //INSERTION SORT DESCENDING
  360.  
  361. for j := 0; j < tot; j++ {
  362. minPos := j
  363. for i := j + 1; i < tot; i++ {
  364. if T[i].sekul > T[minPos].sekul && T[i].id!=0 && T[minPos].id!=0{
  365. minPos = i
  366. }
  367. }
  368. T[j], T[minPos] = T[minPos], T[j]
  369. }
  370. hasilSort()
  371. }else if b==2{
  372.  
  373. for j := 0; j < tot; j++ {
  374. minPos := j
  375. for i := j + 1; i < tot; i++ {
  376. if T[i].mat > T[minPos].mat && T[i].id!=0 && T[minPos].id!=0 {
  377. minPos = i
  378. }
  379. }
  380. T[j], T[minPos] = T[minPos], T[j]
  381. }
  382. hasilSort()
  383. }
  384. }
  385. menuUtama(x)
  386. }
  387. func hasilSort(){
  388. for i:=0; i<tot; i++{
  389. fmt.Print(T[i], " ")
  390.  
  391. }
  392.  
  393. fmt.Print("\n")
  394. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement