0% found this document useful (0 votes)
47 views2 pages

Sample Example

The document defines a function called Find_Grade that takes in a student's name and list of marks as well as a pass mark. It returns true if the average of the student's marks is greater than the pass mark, and false otherwise. It includes examples and validates that the inputs are in the correct format, returning -1 if not. Auxiliary functions not_number? and Pass are also defined to check if the marks are numbers and calculate the pass status.
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
47 views2 pages

Sample Example

The document defines a function called Find_Grade that takes in a student's name and list of marks as well as a pass mark. It returns true if the average of the student's marks is greater than the pass mark, and false otherwise. It includes examples and validates that the inputs are in the correct format, returning -1 if not. Auxiliary functions not_number? and Pass are also defined to check if the marks are numbers and calculate the pass status.
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 2

Develop a function "Find_Grade" which takes student details i.e.

student name
and a list of marks and a pass mark. It returns Boolean true (#t) if the student
marks are more than the input pass mark else returns Boolean false (#f).

Example1 : (Find_Grade (list “student1” (list 40 50 60 70) ) 30) -> #t


Example2 : (Find_Grade (list “student1” (list 40 50 60 70) ) 50) -> #f

Please handle following validations :

(i) If the input list is empty, then return -1


(ii) If the input is not a list then return -1
(iii) If the student name is not string then return -1
(iv) If the marks are not numbers then return -1

Code -

Specification missing for Auxillary function. Pls add that

;;Contract:Find_Grade:list,number->boolean
;;Purpose :Program to check whether a student has passed in all subjects or not
given a pass mark.
;;Header :(define Find_Grade(list passmark).....)
;;Examples:
;;(Find_Grade (list "sagar" (list 50 60 70 80) ) 40)
;;O/P:- #t
;;(Find_Grade (list "Shyam" (list 40 23 60 70) ) 24)
;;O/P:- #f
;;Body
(define Find_Grade(lambda(lst pm)
(cond
[(not (list? lst)) -1]
[(null? lst) -1]
[(null? (list-ref lst 1)) -1]
[(not (string? (list-ref lst 0))) -1]
[(not-number? (list-ref lst 1)) -1]
[else (Pass (list-ref lst 1) pm)]
)))
(define not-number?(lambda(lst)
(if(null? lst)
#f
(begin
(if(number? (car lst))
(not-number? (cdr lst))
#t
)
)
)))

(define Pass(lambda(lst pm)


(if(null? lst)
#t
(if(> (car lst) pm)
(Pass (cdr lst) pm)
#f
)
)
)
)

;;Test cases
(Find_Grade (list "sagar" (list 50 60 70 80) ) 40)
(Find_Grade (list "student1" (list 40 50 60 70) ) 50)

;;Error Test Case 1


(Find_Grade (list ) 50)
(Find_Grade () 50)
(Find_Grade (list "kumar" (list ) ) 24)
;;Error Test Case 2
(Find_Grade "sagar" 12)
(Find_Grade #\b 12)
;;Error Test Case 3
(Find_Grade (list 'sagar (list 40 50 60 70) ) 50)
(Find_Grade (list 122 (list 40 50 60 70) ) 50)
;;Error Test Case 4
(Find_Grade (list "sagar" (list 40 #\a 60 70) ) 50)
(Find_Grade (list "ITER" (list 40 'SAS 60 70) ) 50)

You might also like