%--------------------------------------------------------------------- % Name: Aristotle of Stagira % Number: 00000000 % Course: CS104 % Instructor: Socrates % TA: Plato % Assignment Section: Part 6 - without graphics %--------------------------------------------------------------------- var OriginalDate: string % holds the date var choice: int % choice for date format loop % display the menu in the screen %%%% setscreen ("text") put "" put " Menu " put "" put "Convert the date to:" put "" put " (1) Month Day, Year (February 5, 1997)" put "" put " (2) Month/Day/Year (2/5/1997)" put "" put " (3) Eight-digit zero-padded YearMonthDay (19970205)" put "" put " (4) Chinese Year (Ox)" put "" put " (0) Quit program" % loop until a valid choice is typed loop put "" put "Enter choice (0 to 4): ".. get choice put choice exit when choice >= 0 and choice <= 4 end loop % exit the loop if choice is to quit exit when choice = 0 % prompt the user for a date put "" put "Enter a date in international format: " put " with quotation marks around it: ".. get OriginalDate put OriginalDate % parse into day, month and year var space1, space2: int % hold the indices of spaces in string var MonthYear : string % holds the part of OriginalDate after the 1st space var day, month, year : string % hold day, month, year slices of string space1 := index(OriginalDate," ") % index for first space character % MonthYear gets the part of OriginalDate after the first space MonthYear:= OriginalDate(space1+1..length(OriginalDate)) % space2 is the index of first space in string MonthYear space2 := index(MonthYear," ") % move parts of the date to their corresponding variables day := OriginalDate(1..space1-1) month := MonthYear(1..space2-1) year := MonthYear(space2+1..length(MonthYear)) % set equivalent month number var monthnum: string if month = "January" or month = "january" or month = "Jan" or month ="jan" then monthnum := "1" elsif month = "February" or month = "february" or month = "Feb" or month = "feb" then monthnum := "2" elsif month = "March" or month = "march" or month = "Mar" or month ="mar" then monthnum := "3" elsif month = "April" or month = "april" or month = "Apr" or month ="apr" then monthnum := "4" elsif month = "May" or month = "may" then monthnum := "5" elsif month = "June" or month = "june" or month = "Jun" or month ="jun" then monthnum := "6" elsif month = "July" or month = "july" or month = "Jul" or month ="jul" then monthnum := "7" elsif month = "August" or month = "august" or month = "Aug" or month ="aug" then monthnum := "8" elsif month = "September" or month = "september" or month = "Sep" or month = "sep" then monthnum := "9" elsif month = "October" or month = "october" or month = "Oct" or month= "oct" then monthnum := "10" elsif month = "November" or month = "november" or month = "Nov" or month = "nov" then monthnum := "11" elsif month = "December" or month = "december" or month = "Dec" or month = "dec" then monthnum := "12" else % spelling for month is wrong put "The month was wrongly spelled !!!!" monthnum := "??" end if % display converted date put "The converted date: ".. if choice = 1 then if day(1)="0" then % user entered extra 0 before the day day := day(2..length(day)) % remove it end if put month, " ", day, ", ", year elsif choice = 2 then if day(1)="0" then % user entered extra 0 before the day day := day(2..length(day)) % remove it end if put monthnum,"/",day,"/",year elsif choice = 3 then if length (day) = 1 then day := "0" + day end if if length (monthnum) = 1 then monthnum := "0" + monthnum end if put year,monthnum,day elsif choice = 4 then % (obs: plain "else" would do the same) var input_year, equivalent_year : int % integer to hold years if strintok(year) then % if contents of year string is a integer input_year := strint(year) % convert string to integer % calculate year between 1912 and 1923, equivalent to given year equivalent_year := (input_year-1912) mod 12 + 1912 % print the corresponding Chinese Year if equivalent_year=1912 then put "Rat" elsif equivalent_year=1913 then put "Ox" elsif equivalent_year=1914 then put "Tiger" elsif equivalent_year=1915 then put "Hare" elsif equivalent_year=1916 then put "Dragon" elsif equivalent_year=1917 then put "Serpent" elsif equivalent_year=1918 then put "Horse" elsif equivalent_year=1919 then put "Ram" elsif equivalent_year=1920 then put "Monkey" elsif equivalent_year=1921 then put "Rooster" elsif equivalent_year=1922 then put "Dog" elsif equivalent_year=1923 then put "Boar" end if else put "Problems with your input of year!" end if end if % hold a few seconds so user can see output %%%%% delay(4000) end loop % termination message put "" put "Thank you for running the program"