// File: pix.cpp // Author: Dave Reed // Date: 9/20/04 // // Driver program for pixel-map manipulation. /////////////////////////////////////////////////////////////////// #include #include #include #include #include "Pixmap.h" using namespace std; char GetCommand(); int main() { Pixmap pic; char command = '?'; while (command != 'q') { command = GetCommand(); switch (command) { case 'r': { string filename; cout << "Enter input file name: "; cin >> filename; ifstream istr(filename.c_str()); pic.Read(istr); } break; case 'h': { pic.HorizReflect(); } break; case 'v': { pic.VertReflect(); } break; case 'i': { pic.Invert(); } break; case 'w': { string filename; cout << "Enter output (pixel-map) file name: "; cin >> filename; ofstream ostr(filename.c_str()); pic.Write(ostr); } break; case 'q': { cout << "Goodbye" << endl; } break; default : { cout << "Unknown command ignored." << endl; } break; } cout << endl; } return 0; } ///////////////////////////////////////////////////////////// char GetCommand() // precondition : none // postcondition: reads word and returns lower case first letter { cout << "Enter command: " << endl << " (R)ead a picture" << endl << " (H)orizontal reflection (along x-axis)" << endl << " (V)ertical reflection (along y-axis)" << endl << " (I)nvert a picture" << endl << " (W)rite a picture" << endl << " (Q)uit" << endl << endl; string command; cin >> command; return tolower(command[0]); }