The program is:

! Write a function Pred$ that returns the predecessor (in the ASCII table)

! of a character parameter. If the parameter string is longer than one character,

! the function returns the predecessor of the first character.

 

!pseudocode:

!these string functions may be useful:

!ORD(A$)

!returns the ASCII value of the first character in A$

!CHR$(N)

!returns a character corresponding to the ASCII value N

!1. find N for a character A$

!2. the predecessor of A$ is chr$(N-1)

!3. print ord(A$) and ord(pred$)

!4. print A$ and pred$(A$)

!5. Necessary to remove all but first character in a string.

 

! check functioning of ord(A$), pred$ = chr$(ord(A$)-1)

!LET a$ = "A"

!PRINT a$ !gives A

!PRINT ord(a$) !gives 65

!PRINT chr$(64) !gives @

!PRINT chr$(ord(a$)-1) !gives @

!END

 

DECLARE FUNCTION pred$

DATA "A","ABCDE","a", "b", "/", "Halloween"

DO while more data

!INPUT prompt "Enter a string character or word...": a$

READ a$

SET COLOR "212"

PRINT "The string is ...";a$

SET COLOR "222"

PRINT "The preceding character is ..."; pred$(a$)

LOOP

SOUND 1000,.2

END

 

 

FUNCTION pred$(A$)

IF len(A$)>1 then

LET short$ = A$[1:1] !trims off first character of string

ELSE

LET short$ = A$

END IF

LET m = ord(short$) -1 !the ascii value previous to that of A$

LET pred$ = chr$(m)

END FUNCTION

The output is:

The string is ...A

The preceding character is ...@

The string is ...ABCDE

The preceding character is ...@

The string is ...a

The preceding character is ...`

The string is ...b

The preceding character is ...a

The string is .../

The preceding character is ....

The string is ...Halloween

The preceding character is ...G