a1q5 - ;; above-80?: num -> boolean ;; returns...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
;; The first three lines of this file were inserted by DrScheme. They record metadata ;; about the language level of this file in a form that our tools can easily process. #reader(lib "htdp-intermediate-reader.ss" "lang")((modname a1q5) (read-case- sensitive #t) (teachpacks ()) (htdp-settings #(#t constructor repeating-decimal #f #t none #f ()))) ;; CS 116 ;; r46wang Ru Wang 20319247 ;; Assignment 1 Question 5 ;; bump-grades: (listof num)[0<=num<=100] num -> (listof num) ;; to produce a list of the marks that are above 80 with bonus marks(num) added, but cannot exceed 100. ;; example: ;; (bump-grades empty 10) => empty ;; (bump-grades (list 1 2 3 4 5 6) 5) => empty ;; (bump-grades (list 80) 5) => empty ;; (bump-grades (list 90 91 92 93) 10) => (list 100 100 100 100) ;; (bump-grades (list 81 91 98) 1) => (list 82 92 99) ;; (bump-grades (list 48 89 78 80 99 91) 4) => (list 93 100 95)
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: ;; above-80?: num -&gt; boolean ;; returns true if the number is above 80 and false if it is 80 or below. ;; bump: num -&gt; num ;; returns 100 if the (+ grade bonus) is above 100, else, it returns the number (+ grade bonus). (define (bump-grades g bonus) (local [(define (above-80? grade) (&gt; grade 80)) (define (bump grade) (cond [(&gt; grade (- 100 bonus)) 100] [else (+ grade bonus)]))] (map bump (filter above-80? g)))) ;; tests: (check-expect (bump-grades empty 10) empty) (check-expect (bump-grades (list 1 2 3 4 5 6) 5) empty) (check-expect (bump-grades (list 80) 5) empty) (check-expect (bump-grades (list 90 91 92 93) 10) (list 100 100 100 100)) (check-expect (bump-grades (list 81 91 98) 1) (list 82 92 99)) (check-expect (bump-grades (list 48 89 78 80 99 91) 4) (list 93 100 95))...
View Full Document

This note was uploaded on 10/21/2010 for the course CS 116 taught by Professor T.vasiga during the Fall '09 term at Waterloo.

Ask a homework question - tutors are online