[golang]用Go語言寫的課表

來源:互聯網
上載者:User
這是一個建立於 的文章,其中的資訊可能已經有所發展或是發生改變。
 

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,Tus,..."   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" , "5-6,1-508,Social Market" ,"7-8,(11,15,19),3-308,Xingxi" ," "}Wednesday := tt{"3-4,1-604,English" , "5-6,1-504,Tongjixue" ," " , " "}Thusday := tt{"1-2,English Lisen" , "3-4,5-201,Internation Theory" ," " , " "}Friday := tt{"3-4,3-209,MaoZheDong" , "5-6,1-504,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,的原因了。}                             

  

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.