-CoderOilStation   课程类别:计算机 课程名:CPSC110 系统程序设计环节 Systematic Program Design


 

-CoderOilStation


课程类别:计算机

课程名:CPSC110 系统程序设计环节SystematicProgram Design



mt2-p6-solution

;; The first three lines of this file were inserted by DrRacket.  They record metadata

;; about the language level of this file in a form that our tools can easily  process.

#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

;; The first three lines of this file were inserted by DrRacket.  They record metadata

;; about the language level of this file in a form that our tools can easily  process.

#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 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 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 +

                '}';

    }

}

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 这个不错分享给大家,从扣上看到的,就转过来了 《电脑专业英语》 file [fail] n. 文件;v. 保存文...
    麦子先生R阅读 6,610评论 5 24
  • 1. file n. 文件;v. 保存文件2. command n. 命令指令3. use v. 使用用途4. p...
    喵呜Yuri阅读 773评论 0 4
  • 概述 吸取platform app builder学习笔记的教训,在简书没有修改对于收费文章的准入门槛之前,直接用...
    柯小强阅读 807评论 0 0
  • 留此记录或供同好参考,中英混合,有些乱勿怪。 RSA算法:RSA算法是基于大数难于分解的原理。不但可以用于认证,也...
    陆满庭阅读 1,662评论 0 3
  • 1.file,n.文件;v.保存文件 [faɪl] 2.command,n.命令,指令 [kəˈmænd] 3.u...
    巢峰阅读 378评论 0 0