-CoderOilStation 课程类别:计算机 课程名:CPSC110 系统程序设计环节
-CoderOilStation
课程类别:计算机
课程名:CPSC110 系统程序设计环节 Systematic Program Design
mt2-p6-solution
#reader(lib "htdp-intermediate-lambda-reader.ss" "lang")((modname mt2-p5-solution) (read-case-sensitive #t) (teachpacks ()) (htdp-settings #(#t constructor repeating-decimal #f #t none #f () #t))) (require spd/tags) (require 2htdp/image) (@assignment exams/2022w2-mt2/mt2-p6) (@cwl ???) ;fill in your CWL here (same as for problem sets) (@problem 1) ;do not edit or delete this line (@problem 2) ;do not edit or delete this line (@problem 3) ;do not edit or delete this line (@problem 4) ;do not edit or delete this line (@problem 5) ;do not edit or delete this line (@problem 6) ;do not edit or delete this line #| In this problem you must complete the design of the function with an appropriate @template-origin and function definition. You should consult the mt2-p5-figure.pdf file which provides some additional help designing the function. YOU ARE NOT PERMITTED TO USE THE STEPPER AT ANY POINT IN THIS EXAM. In this problem you must complete the design of a function by writing the template origin tag and the function definition. This problem will be autograded. NOTE that all of the following are required. Violating one or more will cause your solution to receive 0 marks. - The file MUST NOT have any errors when the Check Syntax button is pressed. Press Check Syntax and Run often, and correct any errors early. - The function definition MUST call one or more built-in abstract functions. - The function definition MUST NOT be recursive. - The function definition MUST NOT use any part of the recursive Natural template or the (listof X) template. For instance, - it must not include (cond [(empty? ... anywhere - it must not include (cond [(zero? ... anywhere - it must not include (first loc) anywhere - You MUST NOT change or comment out any check-expects, and you must not change the order of the existing check-expects, but you are free to add new check-expects AFTER the existing check-expects. - The result of the function must directly be the result of one of the built-in abstract functions. So, for example, the following would not be valid function body: (define (foo x) (empty? (filter ...))) - For maximum credit your answer should be a composition of foldr and build-list. |# (define SIZE 10) (define COLOR "blue") (define PEN "solid") (@htdf pyramid) (@signature Natural -> Image) ;; produce a pyramid with n-1 visible steps on each side (steps are 10x10) (check-expect (pyramid 0) empty-image) (check-expect (pyramid 1) (beside/align "bottom" (rectangle SIZE (* SIZE 1) PEN COLOR) empty-image (rectangle SIZE (* SIZE 1) PEN COLOR))) (check-expect (pyramid 2) (beside/align "bottom" (rectangle SIZE (* SIZE 1) PEN COLOR) (rectangle SIZE (* SIZE 2) PEN COLOR) empty-image (rectangle SIZE (* SIZE 2) PEN COLOR) (rectangle SIZE (* SIZE 1) PEN COLOR))) (check-expect (pyramid 3) (beside/align "bottom" (rectangle SIZE (* SIZE 1) PEN COLOR) (rectangle SIZE (* SIZE 2) PEN COLOR) (rectangle SIZE (* SIZE 3) PEN COLOR) empty-image (rectangle SIZE (* SIZE 3) PEN COLOR) (rectangle SIZE (* SIZE 2) PEN COLOR) (rectangle SIZE (* SIZE 1) PEN COLOR))) (@template-origin fn-composition use-abstract-fn) (define (pyramid n) (foldr (lambda (r rnr) (beside/align "bottom" r rnr r)) empty-image (build-list n (lambda (n) (rectangle SIZE (* (+ n 1) SIZE) PEN COLOR)))))
|
mt2-p5-solution
#reader(lib "htdp-intermediate-lambda-reader.ss" "lang")((modname mt2-p5-starter) (read-case-sensitive #t) (teachpacks ()) (htdp-settings #(#t constructor repeating-decimal #f #t none #f () #t))) (require spd/tags) (require 2htdp/image) (@assignment exams/2022w2-mt2/mt2-p5) (@cwl ???) ;fill in your CWL here (same as for problem sets) (@problem 1) ;do not edit or delete this line (@problem 2) ;do not edit or delete this line (@problem 3) ;do not edit or delete this line (@problem 4) ;do not edit or delete this line (@problem 5) ;do not edit or delete this line (@htdf largest) (@signature (listof (listof Natural)) -> (listof Natural)) ;; produce list of largest numbers in each sublist ;; CONSTRAINT: ;; Every sublist will contain at least one number, and all ;; numbers are >= 0. (check-expect (largest empty) empty) (check-expect (largest (list (list 1) (list 2))) (list 1 2)) (check-expect (largest (list (list 1 3 7) (list 5 2 4) (list 4 2 5 9 1 5))) (list 7 5 9)) ;; *** As a reminder, you must not edit anything above this line!!! *** ;; *** You may add tests below here. *** (@template-origin fn-composition use-abstract-fn) (define (largest lolon) (map (lambda (lon) (foldr max 0 lon)) lolon))
|
Java-solution
public static Boolean drawRectanguleIntervalByBottomBlank(int stepInts,BottomBlank bottomBlank){ if (stepInts<0 || stepInts>9){ return null; } if (bottomBlank==null){ return null; } ArrayList<Ractangle> ractangleArrayList = new ArrayList<>(); for (int i = 0; i < stepInts; i++) { Ractangle ractangle = new Ractangle(); ractangle.setId(UUID.randomUUID().toString()); ractangle.setName("blueRactangle"+i); ractangle.setWidth(1); ractangle.setHeight(i+1); ractangleArrayList.add(ractangle); } ArrayList<BottomBlank> bottomBlankArrayList = new ArrayList<>(); for (int i = 0; i < stepInts; i++) { BottomBlank bottomBlank1 = new BottomBlank(); bottomBlank1.setId(UUID.randomUUID().toString()); bottomBlankArrayList.add(bottomBlank1); } for (int i = 0; i < stepInts; i++) { System.out.println(ractangleArrayList.get(i).toString()); System.out.println(bottomBlankArrayList.get(i).toString()); } return true; }
enum Color{ BLUE("0001","blue") ,WHITE("0002","white"); private String key; private String val; Color(String key, String val){ this.key = key; this.val = val; } public String getKey() { return key; } public String getVal() { return val; } } class Ractangle{ private String id; private String name; private Integer width; private Integer height; private String ractangleColor=Color.BLUE.getVal(); public String getId() { return id; } public void setId(String id) { this.id = id; } public String getName() { return name; } public void setName(String name) { this.name = name; } public Integer getWidth() { return width; } public void setWidth(Integer width) { this.width = width; } public Integer getHeight() { return height; } public void setHeight(Integer height) { this.height = height; } public String getRactangleColor() { return ractangleColor; } public void setRactangleColor(String ractangleColor) { this.ractangleColor = ractangleColor; } @Override public String toString() { return "Ractangle{" + "id='" + id + '\'' + ", name='" + name + '\'' + ", width=" + width + ", height=" + height + ", ractangleColor='" + ractangleColor + '\'' + '}'; } } class BottomBlank{ private String id; private final String BottomBlankColor=Color.WHITE.getVal(); private Integer BottomBlankWidth=1; private Integer BottomBlankHeight=10; private final Integer BootomBlankDemesion=2; public String getId() { return id; } public void setId(String id) { this.id = id; } public String getBottomBlankColor() { return BottomBlankColor; } public Integer getBottomBlankWidth() { return BottomBlankWidth; } public void setBottomBlankWidth(Integer bottomBlankWidth) { BottomBlankWidth = bottomBlankWidth; } public Integer getBottomBlankHeight() { return BottomBlankHeight; } public void setBottomBlankHeight(Integer bottomBlankHeight) { BottomBlankHeight = bottomBlankHeight; } public Integer getBootomBlankDemesion() { return BootomBlankDemesion; } @Override public String toString() { return "BottomBlank{" + "id='" + id + '\'' + ", BottomBlankColor='" + BottomBlankColor + '\'' + ", BottomBlankWidth=" + BottomBlankWidth + ", BottomBlankHeight=" + BottomBlankHeight + ", BootomBlankDemesion=" + BootomBlankDemesion + '}'; } }
|
#考研对你找工作产生了哪些影响?##打杂的实习你会去吗?##牛客创作赏金赛##机械只有读研才有出路吗?##面试被问第一学历差时该怎么回答#
JavaEE技术 编程开发经验 企业通用技术