zoukankan      html  css  js  c++  java
  • Overview of Programming Concepts

    总分:5

    1.
    第 1 个问题

    Consider the following image on the left, which has been modified into the image on the right with green by changing the red and blue values of some pixels to 0.

    Which one of the following is most likely the code that modifies the first image to look like the second image?

    Hint: be sure to review how image x and y coordinates work. You can review this on our documentation page.

    1 分
     
     
    for (var pixel of image.values()) {
    x = pixel.getX();
    y = pixel.getY();
    if (x > y) {
    pixel.setRed(0);
    pixel.setBlue(0);
    }
    }
     
     
    for (var pixel of image.values()) {
    x = pixel.getX();
    y = pixel.getY();
    if (x < y) {
    pixel.setRed(0);
    pixel.setBlue(0);
    }
    }
     
     
    w = image.getWidth();
    for (var pixel of image.values()) {
    x = pixel.getX();
    y = pixel.getY();
    if (x + y < w/2) {
    pixel.setRed(0);
    pixel.setBlue(0);
    }
    }
     
     
     
    w = image.getWidth();
    for (var pixel of image.values()) {
    x = pixel.getX();
    y = pixel.getY();
    if (x + y > w/2) {
    pixel.setRed(0);
    pixel.setBlue(0);
    }
    }
     

     
     
    2.
    第 2 个问题

    Consider the following code in which the starting image named image is all red (each pixel has red value 255, green value 0 and blue value 0) as shown below on the left and the resulting image shown on the right below is supposed to be all green, but is all yellow. The image is a 200 pixel by 200 pixel image.

     
     
    for (var pixel of image.values()) {
    if (pixel.getRed() > 250) {
    pixel.setGreen(255);
    }
    }
     
     
     

    Which one of the following correctly identifies a statement or statements that should be added to the body of the if statement so that the red square turns into a green square when the code executes?

    1 分
     
     

    var image=new SimpleImage("Snipaste_2020-11-11_18-28-23.png");
    for (var pixel of image.values()) {
    if (pixel.getRed() > 200) {
    pixel.setGreen(255);
    pixel.setRed(255);
    }
    }
    print(image);

     
     
     
    3.
    第 3 个问题

    Recall the function addBorder you wrote in a programming exercise that has a parameter image and another parameter thickness. This function returns image with an added black border around each side of the image that is thickness pixels wide.

    Which two of the following are correct implementations of addBorder?

    1 分
     
     
     
    function addBorder(image, thickness){
    for (var px of image.values()){
    var x = px.getX();
    var y = px.getY();
    if (x < thickness){
    px = setBlack(px);
    }
    if (x >= image.getWidth()-thickness){
    px = setBlack(px);
    }
    if (y < thickness){
    px = setBlack(px);
    }
    if (y >= image.getHeight()-thickness){
    px = setBlack(px);
    }
    }
    return image;
    }
     
     
     
    
    
    
     
    function addBorder(image, thickness){
    for (var pixel of image.values()){
    if (pixel.getX() < thickness){
    pixel = setBlack(pixel);
    }
    if (pixel.getX() >= image.getWidth()-thickness){
    pixel = setBlack(pixel);
    }
    if (pixel.getY() < thickness){
    pixel = setBlack(pixel);
    }
    if (pixel.getY() >= image.getHeight()-thickness){
    pixel = setBlack(pixel);
    }
    }
    return image;
    }
     
     
     
     
    
    
    
    
    
    
    
    
     
    
    
    
    addBorder(image, thickness){
    for (var px of image.values()){
    if (px.getX() < thickness){
    px = setBlack(px);
    }
    if (px.getX() > image.getWidth()-thickness){
    px = setBlack(px);
    }
    if (px.getY() < thickness){
    px = setBlack(px);
    }
    if (px.getY() > image.getHeight()-thickness){
    px = setBlack(px);
    }
    }
    return image;
    }
     
    Error:
    Unexpected token '{
    
    
    
     
    function addBorder(image, thickness){
    for (var px of image.values()){
    if (px.getX() < thickness){
    px = setBlack(px);
    }
    if (px.getX() > image.getWidth()-thickness){
    px = setBlack(px);
    }
    if (px.getY() < thickness){
    px = setBlack(px);
    }
    else{
    px = setBlack(px);
    }
    }
    return image;
    }
     
    
    
    
    
     
    function addBorder(image, thickness){
    for (var px of image.values()){
    if (px.getX() < width){
    px = setBlack(px);
    }
    if (px.getX() > image.getWidth()-width){
    px = setBlack(px);
    }
    if (px.getY() < height){
    px = setBlack(px);
    }
    if (px.getY() > image.getHeight()-height){
    px = setBlack(px);
    }
    }
    return image;
    }
    Error:
    Line 10
    width is not defined
     
    //在这里写你的代码
    function setBlack(pixl){
        pixl.setRed(0);
        pixl.setGreen(0);
        pixl.setBlue(0);
        return pixl;
    } 
    function addBorder(image, thickness){
        for (var pixel of image.values()){
         ...return image;
    }
    var image = new SimpleImage("smallpanda.png");
    print( addBorder(image, 10));
     
     
    4.
    第 4 个问题

    Consider the following program that uses the setBlack function you wrote in the Advanced Modifying Images programming exercise:


     
     
     
    function pixelOnEdge(image,pixel,horizontalThick, verticalThick){
    var x = pixel.getX();
    var y = pixel.getY();
    if (x < verticalThick || x > image.getWidth() - verticalThick){
    return true;
    }
    if (y < horizontalThick || y > image.getHeight() - horizontalThick){
    return true;
    }
    return false;
    }
     
    function addBorders(image,horizontalThick, verticalThick){
    for (var px of image.values()){
    if (pixelOnEdge(image,px,horizontalThick,verticalThick)){
    px = setBlack(px);
    }
    }
    return image;
    }
     
    var img = new SimpleImage("skyline.png");
    img = addBorders(img,40,20);
    print(img);
     
     
     

    What is the best description of the purpose of the pixelOnEdge function?

    1 分
     

    To identify pixels that are within the borders by returning true

    To identify pixels within the vertical borders

    To color pixels that are within the borders black

    To identify pixels within the horizontal borders

     
    5.
    第 5 个问题

    Which of the following could not be the output of running the program written in the previous question? Select all that apply.

    1 分
     
    1 分
     
     
  • 相关阅读:
    如何让百度网盘下载速度达60MB/s!
    记一次内存溢出问题的排查、分析过程及解决思路
    使用maven命令打包可执行jar方法
    java实现四则运算
    POI如何合并单元格
    我是如何从功能测试成功转型自动化测试人员的?
    Edgar:Netflix分布式系统的可视化问题诊断平台实践
    Uber的API生命周期管理平台边缘网关(Edge Gateway)的设计实践
    UBer面向领域的微服务体系架构实践
    技术团队:问题被过度的夸大小题大做,你该怎么办?
  • 原文地址:https://www.cnblogs.com/WLCYSYS/p/13960262.html
Copyright © 2011-2022 走看看