Art Program. We’re going to build on our PBM image creator from (code shown below) to create a fully functional image editor, using 2D arrays to store our changes. We’ll also make it a little 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. You should be able to copy and paste the output into a file and load it in the same way as you did with the PBM file in Assignment 4 – the only difference is that the extension should be .pgm. Quit

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

Art Program.

We’re going to build on our PBM image creator from (code shown below) to create a fully functional image editor, using 2D arrays to store our changes. We’ll also make it a little 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. You should be able to copy and paste the output into a file and load it in the same way as you did with the PBM file in Assignment 4 – the only difference is that the extension should be .pgm.

  • Quit
1
include <iostream>
2 using namespace std;
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
int main ()
{
int size_square;
int size_border;
int color_square;
int color_border;
do{
cout << "Enter the size of the square:
cin >> size_square;
if (size_square < 0) {
}
cout << "Invalid input!" << endl;
}
while (size_square < 0);
do{
cout << "Enter the size of the border:
cin >> size_border;
if (size_border < 0) {
}
}
while (size_border < 0);
do{
cout << "Invalid input!" << endl;
cout << "Enter the color of the square:
cin >> color_square;
if (color_square < 0 || color_square > 1){
cout << "Invalid input!" << endl;
}
}
while (color_square < ℗ || color_square > 1);
do{
cout << "Enter the color of the border: ";
cin >> color_border;
if (color_border < 0 || color_border > 1){
cout << "Invalid input!" << endl;
}
}
while (color_border < 0 || color_border > 1);
cout << "PBM File Contents:" << endl;
cout << "P1" << endl;
int total_size;
total_size = size_square + 2 size_border;
int height_width;
height_width = total_size;
cout << total_size <<
for (int i = 0; i < size_border; i++)
<< total_size << endl;
Transcribed Image Text:1 include <iostream> 2 using namespace std; 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 int main () { int size_square; int size_border; int color_square; int color_border; do{ cout << "Enter the size of the square: cin >> size_square; if (size_square < 0) { } cout << "Invalid input!" << endl; } while (size_square < 0); do{ cout << "Enter the size of the border: cin >> size_border; if (size_border < 0) { } } while (size_border < 0); do{ cout << "Invalid input!" << endl; cout << "Enter the color of the square: cin >> color_square; if (color_square < 0 || color_square > 1){ cout << "Invalid input!" << endl; } } while (color_square < ℗ || color_square > 1); do{ cout << "Enter the color of the border: "; cin >> color_border; if (color_border < 0 || color_border > 1){ cout << "Invalid input!" << endl; } } while (color_border < 0 || color_border > 1); cout << "PBM File Contents:" << endl; cout << "P1" << endl; int total_size; total_size = size_square + 2 size_border; int height_width; height_width = total_size; cout << total_size << for (int i = 0; i < size_border; i++) << total_size << endl;
60
61
62
63
64
65
66
67
68
69
78172754557 78 79 88 81 82 88
70
73
76
80
83
84
85
86
87
00 00 00
780
88
89
90
91
92
નન
93
94
95
}
{
}
for (int j = 0; j < height_width; j++)
{
}
for (int i = 0; i < size_square; i++)
{
cout << color_border;
}cout << endl;
}
for (int j = 0; j < size_border; j++)
{
}
for (int k = 0; k < size_square; k++ )
cout << color_square;
(int j = 0; j < size_border; j++)
{
}
for
cout << color_border;
{
cout << color_border;
}cout << endl;
for (int i = 0; i < size_border; i++)
{
for (int j = 0; j < height_width; j++)|
{
cout << color_border;
}cout << endl;
cout << endl;
return 0;
Transcribed Image Text:60 61 62 63 64 65 66 67 68 69 78172754557 78 79 88 81 82 88 70 73 76 80 83 84 85 86 87 00 00 00 780 88 89 90 91 92 નન 93 94 95 } { } for (int j = 0; j < height_width; j++) { } for (int i = 0; i < size_square; i++) { cout << color_border; }cout << endl; } for (int j = 0; j < size_border; j++) { } for (int k = 0; k < size_square; k++ ) cout << color_square; (int j = 0; j < size_border; j++) { } for cout << color_border; { cout << color_border; }cout << endl; for (int i = 0; i < size_border; i++) { for (int j = 0; j < height_width; j++)| { cout << color_border; }cout << endl; cout << endl; return 0;
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps with 2 images

Blurred answer
Knowledge Booster
Image Element
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education