In C++ how would I go about doing the following. here will be either two or thre
ID: 3710189 • Letter: I
Question
In C++ how would I go about doing the following.
here will be either two or three arguments: inputFilename outputFilename optionalModificationCode
You will be reading a PPM file specified by the user in the first user-supplied command line argument (the input file name).
You will be making some sort of modification to the PPM file, which will be provided in a possible third user-supplied argument (modification code) as either Y, X, F or G.
If the user specifies Y, then you will flip the PPM file around the Y axis
If the user specifies X, then you will flip the PPM file around the X axis.
If the user specifies F (for flatten), you will flatten the red value to 0 in all pixels of the PPM file.
If the user specifies G, then you will convert the picture to grey scale.
Finally, if the user doesn't specify anything, you will make no modifications to the PPM file.
You will then write to a separate PPM file specified by the user in the second user-supplied command line argument.
Explanation / Answer
-------Sample Code---------
#include <iostream>
#include <fstream>
using namespace std;
int main(int argc, char** argv){
// Reading arguments
string inputFilename = "", outputFilename = "", optionalModificationCode = "";
inputFilename = argv[1];
outputFilename = argv[2];
if(argc==4){
optionalModificationCode = argv[3];
}
// Opening file input and output streams from filenames passed in as command line arguments
ifstream cinn(inputFilename);
ofstream coutt(outputFilename);
cout << inputFilename << endl;
cout << outputFilename << endl;
cout << optionalModificationCode << endl;
}