Question: C++ question Hi, I am trying to create a program that will run like this. with output file showing #include #include #include #include using namespace

C++ question

Hi, I am trying to create a program that will run like this.

C++ question Hi, I am trying to create a program that will

with output file showing

run like this. with output file showing #include #include #include #include using

#include

#include

#include

#include

using namespace std;

typedef struct ppm {

string type;

int width;

int height;

int max;

int im[100][100][3];

}PPM;

void readImage(PPM &image, ifstream &ifs) {

ifs >> image.type;

if (image.type == "P1" || image.type == "P2" || image.type == "P3") {

ifs >> image.width >> image.height;

if (image.width > 1000 || image.height > 1000) {

cout

exit(-1);

}

ifs >> image.max;

for (int i = 0; i

for (int j = 0; j

ifs >> image.im[i][j][0] >> image.im[i][j][1] >> image.im[i][j][2];

}

}

}

else {

cout

exit(-1);

}

}

void convertGrayScale(PPM &image) {

if (image.type == "P2") {

return;

}

image.type = "P2";

int tot = 0;

for (int i = 0; i

for (int j = 0; j

tot = image.im[i][j][0] + image.im[i][j][1] + image.im[i][j][2];

image.im[i][j][0] = tot / 3;

image.im[i][j][1] = tot / 3;

image.im[i][j][2] = tot / 3;

}

}

}

void invertRed(PPM &image) {

for (int i = 0; i

for (int j = 0; j

image.im[i][j][0] = image.max - image.im[i][j][0];

}

}

}

void invertBlue(PPM &image) {

for (int i = 0; i

for (int j = 0; j

image.im[i][j][1] = image.max - image.im[i][j][1];

}

}

}

void invertGreen(PPM &image) {

for (int i = 0; i

for (int j = 0; j

image.im[i][j][2] = image.max - image.im[i][j][2];

}

}

}

void invertAll(PPM &image) {

for (int i = 0; i

for (int j = 0; j

image.im[i][j][0] = image.max - image.im[i][j][0];

image.im[i][j][1] = image.max - image.im[i][j][1];

image.im[i][j][2] = image.max - image.im[i][j][2];

}

}

}

void writeImage(PPM &image, ofstream &ofs) {

ofs

ofs

ofs

for (int i = 0; i

for (int j = 0; j

ofs

}

ofs

}

}

void menu() {

cout

cout

cout

cout

cout

}

int main() {

PPM image;

string ofile;

string ifile;

ifstream ifs;

ofstream ofs;

cout

cin >> ifile;

ifs.open(ifile.c_str());

if (!ifs.is_open()) {

cout

return -1;

}

cout

cin >> ofile;

ofs.open(ofile.c_str());

if (!ofs.is_open()) {

cout

return -1;

}

readImage(image, ifs);

ifs.close();

int choice;

menu();

cin >> choice;

switch (choice) {

case 1:convertGrayScale(image); break;

case 2:invertRed(image); break;

case 3:invertBlue(image); break;

case 4:invertGreen(image); break;

case 5:invertAll(image); break;

}

writeImage(image, ofs);

ofs.close();

}

Why am I and how to fix errors like this? I only get it working with bigger size pictures.

Plus pls help me format it better with it asking Enter choice at the end.

Thank you

namespace std; typedef struct ppm { string type; int width; int height;

.7 Select C:\UsersiChadDesktop\C++ progNew folderNmageModder-SampleProgram.exe Portable Pixmap (PPM) Image Modder Enter image file name (ppm):cake.ppm Enter output file name(ppm):cake Magic: P3 Width, Height: 720, 540 Number of Pixels: 388800 Max Color: 255 Image Processing Choices 1. Convert to grayscale 2. Invert Red 3. Invert Green 4. Invert Blue 5. Invert All Enter Choice: 1

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!