[golang]用Go语言写的课表

前端之家收集整理的这篇文章主要介绍了[golang]用Go语言写的课表前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

package main

import ( "fmt" "os" )

type tt struct { //定义数据结构 tt,用于存放每日的课程 One string //0 Two string //1 Three string //2 Four string //3 } type DAY struct { //定义数据结构 DAY,用于存放一周的,英文简写 week string }

func main() { //主函数 var weekday int //定义一个int 类型的值,weekday //fmt.Printf("Enter the weekday : ") //fmt.Scanf("%d",&weekday) weekday = getday() //从getday()函数中得返回值,(如,1,2,3,....7) print_tt(weekday) //把从getday()函数中得到的返回值,传送给print_tt()函数,用于显示一周中,特定的星期的课程 }

func print_tt(weekday int) { //用于显示每日的课程

DAYS := DAY{"Mon,Tus,Wed,Thu,Fri,Sat,Sun"}//初始化数据结构DAY,值为DAYS,内容为"Mon,..." Monday := tt{"1-2,1-604,English","5-6,3-303,MacroEco","7-8,1-501,Market"," "} //定义Monday为tt结构类型,并初始化,下面的理解一样 Tusday := tt{"3-4,Ground,Physical",1-508,Social Market",(11,15,19),3-308,Xingxi"," "} Wednesday := tt{"3-4,1-504,Tongjixue"," "," "} Thusday := tt{"1-2,English Lisen","3-4,5-201,Internation Theory"," "} Friday := tt{"3-4,3-209,MaoZheDong",TongjiXue"," "} var get_tt int get_tt = weekday //下面的如果为判断输入的数字为多少,并分开了两个部分进行比较 if get_tt > 3 && get_tt < 7 { //第一部分, 3-7 for i :=3 ;i <= get_tt ; i++ { if i == get_tt { switch i { case 4: fmt.Printf("%s\n%s\n \n",Thusday.One,Thusday.Two) case 5: fmt.Printf("%s\n%s\n \n",Friday.One,Friday.Two) case 6: fmt.Printf("Holiday Now") // case 7: fmt.Printf("Holiday now\n") } } } } else if get_tt <=3 && get_tt > 0 { //第二部分,0-3 for j := 0 ; j <= get_tt ; j++ { if j == get_tt { switch j { case 1: fmt.Printf("%s\n%s\n%s\n \n",Monday.One,Monday.Two,Monday.Three) case 2: fmt.Printf("%s\n%s\n%s\n \n",Tusday.One,Tusday.Two,Tusday.Three) case 3: fmt.Printf("%s\n%s\n \n",Wednesday.One,Wednesday.Two) } } } } else if get_tt == 8 { //第三部分是,当get_tt = 8,这个值是为getday()函数默认得到的 fmt.Printf("Please input the weekday name\n") fmt.Printf("Example: tiMetable Mon or tiMetable.exe Mon\n") fmt.Printf("weekday define as belows\n") fmt.Printf("%s\n",DAYS.week) } else { fmt.Printf("Input Error") } } func getday() int { //此函数是将程序运行时,输入的参数改为数字形式,再返回 //函数的原型为fnuc getday() int,其中getday()为函数,而这个int为返回值的类型。 if len(os.Args) > 1 { /*os.Args[0] is "tiMetable" or "tiMetable.exe" */ if os.Args[1] == "Mon" { return 1 } if os.Args[1] == "Tus" { return 2 } if os.Args[1] == "Wed" { return 3 } if os.Args[1] == "Thu" { return 4 } if os.Args[1] == "Fri" { return 5 } if os.Args[1] == "Sat" || os.Args[1] == "Sun" { return 6 } } return 8 //当没有输入参数或者输入的参数,与给出的值,不相同 //就会返回8,这就是在print_tt()函数中的 get_tt = 8,的原因了。 }

猜你在找的Go相关文章