Build on our PBM image creator from (code shown below) to create a fully functional image editor (in C++), using 2D arrays to store our changes. To make it more interesting by switching to the Portable Gray Map standard. 8 bit PGM files have color values ranging from 0 (black) to 255 (white), with the values in-between being shades of gray. The header is very similar to PBM, and looks like this: P2 WIDTH HEIGHT 255 IMAGE_DATA The P2 tells image readers that it is a PGM file, and the 255 indicates the largest possible color value is 255. You will first prompt the user to enter a width, height, and initial color value to fill the image. You should then create a 2D array with those dimensions and initialize each cell with that color value. You will then use a loop to create a menu that repeatedly prompts the user to make one of the following choices: Fill in a pixel with a new color ◦ Prompt the user to enter a row and column value and a new color value. If the array has that row and column index AND the color value is between 0 – 255, change the color at the index. Otherwise, inform the user that it’s an invalid command. Fill in a line with a new color ◦ Prompt the user to enter a starting row and column value, a new color value, a length value, and a direction (left, right, up, or down, case sensitive). If all those values are valid, fill in each index in the line with those values in the 2D array (you can open up a program like Excel if you need help visualizing this) If the row, column, color, and/or direction are not correct, inform the user that it’s an invalid command. If the length is correct but would go outside the array (e.g. a length of 20 but the array only has 10 columns), fill in values up to the edge of the array and then stop. Do not cause an ArrayOutOfBounds error. Print the PGM file ◦ This should print out the contents of a valid PGM image. Quit
Build on our PBM image creator from (code shown below) to create a fully functional image editor (in C++), using 2D arrays to store our changes. To make it more interesting by switching to the Portable Gray Map standard. 8 bit PGM files have color values ranging from 0 (black) to 255 (white), with the values in-between being shades of gray. The header is very similar to PBM, and looks like this:
P2
WIDTH HEIGHT
255 IMAGE_DATA
The P2 tells image readers that it is a PGM file, and the 255 indicates the largest possible color value is 255.
You will first prompt the user to enter a width, height, and initial color value to fill the image. You should then create a 2D array with those dimensions and initialize each cell with that color value.
You will then use a loop to create a menu that repeatedly prompts the user to make one of the following choices:
- Fill in a pixel with a new color
◦ Prompt the user to enter a row and column value and a new color value. If the array has that row and column index AND the color value is between 0 – 255, change the color at the index.
Otherwise, inform the user that it’s an invalid command.
- Fill in a line with a new color
◦ Prompt the user to enter a starting row and column value, a new color value, a length value, and a direction (left, right, up, or down, case sensitive). If all those values are valid, fill in each index in the line with those values in the 2D array (you can open up a program like Excel if you need help visualizing this) If the row, column, color, and/or direction are not correct, inform the user that it’s an invalid command.
If the length is correct but would go outside the array (e.g. a length of 20 but the array only has 10 columns), fill in values up to the edge of the array and then stop. Do not cause an ArrayOutOfBounds error.
- Print the PGM file
◦ This should print out the contents of a valid PGM image.
- Quit



Trending now
This is a popular solution!
Step by step
Solved in 2 steps with 9 images









