Menu

Htdf Lab Problem 4 Problem Design Function Called Nth Char Equal Consumes Two Strings Natu Q43871274

;; HtDF Lab, Problem 4

;; PROBLEM:
;;
;; Design a function called nth-char-equal? that consumes twostrings
;; and a natural and produces true if the strings both have lengthgreater
;; than n and have the same character at position n.
;;
;;
;; Note, the signature for such a function is:
;;
;; (@signature String String Natural -> Boolean)
;;
;;
;; The tag and template for such a function are:
;;
;; (@template String)
;;
;; (define (nth-char-equal? s1 s2 n)
;; (… s1 s2 n))

——————————————————–

I wrote the answer like this

(@problem 4)
(@htdf nth-char-equal?)

(@signature String String Natural -> Boolean)
;;If there are two strings and a natural
;;and produces true if either of them length if greater thann
(check-expect (nth-char-equal? “rat” “cat” 2) true)
(check-expect (nth-char-equal? “domain” “haha” 5) false)
(check-expect (nth-char-equal? “signature” “template” 3)false)
(check-expect (nth-char-equal? “fat” “skin” 5) false)

;(define (nth-char-equal? s1 s2 n) false) ;stub

(@template String String Natural)
(define (nth-char-equal? s1 s2 n)
(and (> (string-length s1) n)
(> (string-length s2) n)
(string=? (substring s1 (- n 1) n)
(substring s2 (- n 1) n))))

———————————————————–

and then I test it.

it says

AUTOGRADING GRADE: 92%.

In (@Problem 4), in (@htdf nth-char-equal?), in (@template StringString Natural): includes incorrect types
In (@Problem 4), in (@htdf nth-char-equal?), in (@template StringString Natural): should not have duplicate options
In (@Problem 4), in (@htdf nth-char-equal?), Error running test(check-expect (nth-char-equal? “sa” “s” 0) true): substring:contract violation
expected: exact-nonnegative-integer?
given: -1
argument position: 2nd
other arguments…:
“sa”
0

————————————-

what is the correct answer?

Expert Answer


Answer to ;; HtDF Lab, Problem 4 ;; PROBLEM: ;; ;; Design a function called nth-char-equal? that consumes two strings ;; and a nat…

OR