The following is part a of a free response question from 2012. It was question 4 on the exam. You can see all the free response questions from past exams at https://apstudents.collegeboard.org/courses/ap-computer-science-a/free-response-questions-by-year. Question
4. A grayscale image is represented by a 2-dimensional rectangular array of pixels (picture elements). A pixel is an integer value that represents a shade of gray. In this question, pixel values can be in the range from 0 through 255, inclusive. A black pixel is represented by 0, and a white pixel is represented by 255. The declaration of the Part a. Write the method Figure 1: Example 2D array¶ A call to public class GrayImage { public static final int BLACK = 0; public static final int WHITE = 255; /** The 2-dimensional representation of this image. * Guaranteed not to be null. * All values in the array are within the range * [BLACK, WHITE], inclusive. */ private int[][] pixelValues; /** @return the total number of white pixels in * this image. * Postcondition: this image has not been changed. */ public int countWhitePixels() { /* to be implemented in part (a) */ } } 8.7.1.1. How to solve this problem¶To solve this problem, we will need to loop through the entire 2D array, looking for instances of a
9-10-1: What kind of loop could you use to solve this problem?
9-10-2: What is another kind of loop you could use to solve this problem? Looping through a 2D array is more complicated than the simple arrays we usually see, requiring nested for loops. Check out the questions and code below, which displays how nested for loops work to display a block of numbers. 8.7.1.2. Algorithm¶When approaching this problem, it can be helpful to look for keywords or hints that maybe be in the problem statement. This section contains a plain English explanation of one way to solve this problem as well as problems that test your understanding of how to write the code to do those things. Click on the buttons to reveal the questions. 9-10-5: Explain in plain English what your code will have to do to answer this question. Use the variable names given above.
9-10-6: Which class is
9-10-7: What array will you be modifying in this method? There are many ways to solve this question, but we will only cover two in this section. Although it is a good exercise to be able to write the solution in multiple ways, you do not need to write both for the AP exam and you can just look at the problems below which relate to the method that is more intuitive to you. If you want to solve this problem using nested for loops, complete the three questions below.
9-10-8: What could you write for the outer for loop so that it iterates through the rows of the array?
9-10-9: What could you write for the inner for loop so that it iterates through the columns of the array?
9-10-10: how could you check if the current value is white? Alternatively, if you want to solve this problem using nested for each loops, complete the three questions below.
9-10-11: What could you write for the outer for loop so that it iterates through the rows of the array?
9-10-12: What could you write for the inner for loop so that it iterates through the columns of the array?
9-10-13: How will you check if pv is white? 8.7.1.3. Try and Solve It¶FRQ Gray Image A: write the code for the method 8.7.1.4. Video - One way to code the solution¶The following video is also on YouTube at https://youtu.be/Rx4bPs0wkxU. It walks through coding a solution. You have attempted of activities on this page What percent is a 5 on AP Computer Science A?The score distribution tables on this page show the percentages of 1s, 2s, 3s, 4s, and 5s for each AP subject.
...
AP Score Distributions.. Is AP Computer Science A hard?Is AP Computer Science A Easy Or Hard? AP Computer Science A is considered quite easy, with class alumnae rating it 4.2/10 for overall difficulty (the 24th-most-difficult out of the 28 large AP classes surveyed). The pass rate is about average vs other AP classes, with 67% graduating with a 3 or higher.
How many FRQS are on the AP Computer Science A exam?This curriculum is arranged to follow the AP CS A units and provides many interactive exercises in each unit. The 4 free response questions allow students to write code to answer a problem and cover the following areas.
How long is the Apcsa exam?Know the format of the exam.
The AP® Computer Science A exam is 3 hours long and consists of two sections: multiple-choice and free-response. On the multiple-choice section, you have 1 hour and 30 minutes to answer 40 questions. For the free-response section, you have 1 hour and 30 minutes to answer 4 questions.
|