10 likes | 119 Views
Homework 2 (simple loops in TL) : DEADLINE Friday, Nov. 18, 6PM Write and test the following function: % Return the number of occurrences of character c in string s . func count_chars ( c : char , ref const s : string ) : int ... your code here …
E N D
Homework 2 (simple loops in TL) : DEADLINE Friday, Nov. 18, 6PM Write and test the following function: % Return the number of occurrences of character c in string s . funccount_chars ( c : char, ref const s : string ) : int ... your code here … NOTE: Proper comments, including the loop invariant and the termination argument, are an essential part of a complete solution! HINT: Read and understand the second example in the lecture “Arrays and quantifiers”. Also: recall the counting quantifier N . EXAMPLE: The statement TRACE count_chars( ‘a’, “Able was I ere I saw Elba” ) should print out the value 3 . NOTE: 1. Please do it just by yourself, don’t show your solution to, or discuss it with others. 2. Run your program and check that it does what you expect. 3. Please hand in your submission on paper, not via e-mail.