%--------------------------------------------------------------------- % Name: Aristotle of Stagira % Number: 00000000 % Course: CS104 % Instructor: Socrates % TA: Plato % Assignment Section: Part 6 - with graphics %--------------------------------------------------------------------- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % This is the same as part 6, but includes graphics for one of % the Chinese years (Hare). %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % The part of the code that does graphics for Hare Year is here % as a procedure. This was done here for the sake of clarity of % rest of the code. You were not expected to do in this way, and % could insert this portion of code in the if-then-elsif structure % right where the call for ShowHare is. % The program starts below, after the comment "Main Program". % When "ShowHare" is called in the main program, the procedure % Showhare is executed. After this execution is finished the % program continues right after the procedure's call. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% procedure ShowHare var old_colour, old_colourback : int % save previous color/colorback var back_colour:int := 7 old_colour := whatcolor % save current colour for restoring later old_colourback := whatcolorback % save backgroung colour as well setscreen("text") setscreen("nocursor") cls colorback(back_colour) % fill out the screen for i:1..25 locate(i,1) put repeat(" ",80).. end for color(0) % show a hare locate(1,1) put " * " put " ** " put " *** " put " **** " put " **** " put " ***** " put " ****** ****** " put " *********** ******* " put " ****** ******* ******** " put " ****** ******* ******** " put " ***** ******* ******* " put " *** *************** " put " ** ***************** " put " ******************* " put " ********************* " put " ***** ***** ***** " put " ********************* " put " ********************* " put " ******** ******** " put " ******** ******** " put " ************* " put " | | | " put " |_|_| " var row,col: int % row and column for word box var init_column:int :=53 % starting column for a cycle of word box var times: int :=14 % size of word box var counter:int % couter for cycles word box will to in screen col := init_column row := 0 color(4) counter := 0 loop exit when counter > 3 %performs 3 complete cycles % erases previous word box colorback(back_colour) locate(row,col) put repeat(" ",times) locate(row+1,col) put repeat(" ",times) locate(row+2,col) put repeat(" ",times) % display opened eyes color(12) locate(16,30) put "0" locate(16,38) put "0" % delay a bit delay(300) % update the row & column for word box row := row mod 20 + 5 % row=5,10,15,20,5,10,15,... col := col+3 if row = 5 then % when box on top counter :=counter + 1 % count one cycle col := init_column % update column to the leftmost one end if % display closed eyes color(12) locate(16,30) put "_" locate(16,38) put "_" % displays word box (with word "hare") color(4) colorback(3) locate(row,col) put repeat(" ",times) locate(row+1,col) put " H A R E " locate(row+2,col) put repeat(" ",times) % delays a bit delay(600) end loop % display opened eyes colorback(back_colour) color(12) locate(16,30) put "0" locate(16,38) put "0" % restore text and background colours color(old_colour) colorback(old_colourback) end ShowHare %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % Main Program Starts Here % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% var OriginalDate: string % holds the date var choice: int % choice for date format loop % display the menu in the screen setscreen ("text") setscreen ("cursor") 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 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 % 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 % example of graphics ShowHare % execute procedure ShowHare and come back here; % you were not expected to use a procedure, % the code in the procedure body could be % copied here. 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"