To do this lab, you are to copy the program pgm_editor.cpp from /home/plank/cs140/Labs/Lab3. You'll note that there is a comment that says "DO NOT CHANGE ANYTHING BELOW THIS LINE". I feel that this comment is pretty self-explanatory. The gradescript will check to see if you have changed anything below the line, and if you do, it will flag it as an error. What you do is write code where it says "Write your code here". You compile this program and run it, and that is what you submit for grading.
Here is pgm_editor.cpp:
#include <cstdio> #include <cstdlib> #include <string> #include <sstream> #include <vector> #include <iostream> using namespace std; typedef vector <int> IVec; // Write your code here: // DO NOT CHANGE ANYTHING BELOW THIS LINE void bad_pgm(string s) { cerr << "Bad PGM file: " << s << endl; exit(1); } .... |
Your job is to write seven procedures. You can figure out their parameter types from how they are called within pgm_editor.cpp. They all revolve around PGM files, which are held in a vector of vectors of ints. Suppose that we have a PGM file p, declared as:
vector <IVec> p; |
Then p.size() is the number of rows of the PGM file. Each element p[i] will be a vector of the same size. p[i].size() is the number of columns in the PGM file. And p[i][j] contains the pixel value in row i column j. In the procedures that you write, you may assume that you get a valid PGM file as input. You do not have to error check.
The seven procedures are:
UNIX> pgm_editor usage: pgm_editor command.... CREATE rows cols pixvalue CW CCW PAD pixels pixvalue PANEL r c CROP r c rows cols UNIX>
UNIX> pgm_editor CREATE 50 200 0 | convert - example_create.jpg
UNIX> pgm_editor CW < Red.pgm | convert - example_cw.jpg
UNIX> pgm_editor CCW < Red.pgm | convert - example_ccw.jpg
UNIX> pgm_editor PAD 30 0 < Rodney.pgm | convert - example_pad_1.jpg
UNIX> pgm_editor PAD 30 0 < Rodney.pgm | pgm_editor PAD 30 255 | pgm_editor PAD 1 0 | convert - example_pad_2.jpg
UNIX> pgm_editor PANEL 2 4 < Red.pgm | convert - example_panel_1.jpg
UNIX> pgm_editor PAD 6 0 < Rodney.pgm | pgm_editor PAD 3 255 | pgm_editor PANEL 3 5 | convert - example_panel_2.jpg
UNIX> pgm_editor CROP 45 60 50 100 < Red.pgm | convert - example_crop.jpg
UNIX> pgm_editor CROP 45 60 50 100 < Red.pgm | pgm_editor PAD 2 0 | pgm_editor PAD 1 255 | pgm_editor PANEL 4 9 | convert - example_crop_panel.jpg
To start this lab -- and do this during lab, write dummy versions of these procedures that don't work, but that compile. That way you at least have the procedure declarations correct. Then work on pgm_create() and pgm_write(). Then the others. Think about when you should be using reference parameters.