Given a character and a string, determine whether the character appears in the string.
function ISIN (c in Char, s in SeqOfChar) return in Bool
pre true.
post The returned value is true if the character c appears in the sequence s at least once, and is false if c does not appear at all in s.
(If s is the empty string, then it contains no characters, and ISIN (c, s) will be false whatever the character c is.)
Activity 20
Suggest a description for a function ISEMPTY corresponding to the following process.
Determine whether or not a given sequence is empty.
Discussion
The function will input a sequence (which might contain elements from any set, say X). It can return true if the sequence is empty, and false if it is not empty. So we can use the following description of ISEMPTY.function ISEMPTY (s in SeqOfX ) return in Bool
pre true.
post The returned value is true if the sequence s contains no members, and is false if s contains one or more members.
No comments:
Post a Comment