Design a function pretty-print that consumes a string and an integer and that pr
ID: 3780937 • Letter: D
Question
Design a function pretty-print that consumes a string and an integer and that produces an image of the text that results from appending the integer to the end of the string. The resulting text must be drawn in 18 point, magenta coloured font. However, you should assume that the font size and colour may need to be changed in the future and you must design your solution in such a way that only one line of code needs to be changed for each of these two values that is changed. Examples: (pretty-print "Number of accounts: " 2) Number of accounts: 2 (pretty-print "Width of room (metres): " 4) Width of room (metres): 4 You must use the How to Design Functions (HtDF) recipe, and your complete design must include signature, purpose, commented out stub, examples/tests, commented out template, and the completed function.Explanation / Answer
The five design recipe components
Purpose: Describes what the function is to compute.
Contract: Describes what type of arguments the function consumes and what type of value it produces.
Examples: Illustrating the typical use of the function.
Definition: The Racket definition (header and body) of the function.
Tests: A representative set of function arguments and expected function values.
----------------
; ; (pretty-print "a " : b) produces an image of the text that results by appending the integar b to the end of the string a.
; ; (pretty-print "a " : b) String Int -> String
; ; Examples :
(check-expect (pretty-print "Number Of accounts : " 2) Number of accounts : 2
(check-expect (pretty-print "Width of room (metres): " 4) Width of room (metres) : 4
(define my-content my-num)
(list (append (cons my-content empty) (cons my-num ()))) //we have appended int and string to a list
(text list 18 "magenta")
; ; Tests :
//here let us test for the image height which should be of 18 points, note that image-height returns it in pixels, and
//1 pixel = 1.25 points
(check-expect (image-height (pretty-print "Number Of accounts : " 2) ) 22.5)
----------------------------------
that will be the required code
--------
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.