#include #include // for ifstream #include "CPstring.h" #include "prompt.h" #include "matrix.h" // file: charplot.cc // author Dietolf Ramm; date: 11/7/96 // Plot in a char matrix const int ROWS = 25; const int COLS = 50; const char PCHAR = '*'; void PlotData(Matrix & plot, int rows, int cols) // postcondition: plot contains a graphical representation of // the data read { int x, y; string filename; ifstream pin; cout << "Name of file with data to plot: "; cin >> filename; pin.open(filename); while (pin >> x >> y) { plot[y][x] = PCHAR; } } void PrintPlot(Matrix & plot, int rows, int cols) { int r, c; cout << '+' ; for ( c = 0; c < cols; c++) { cout << '-'; } cout << '+' << endl; for (r = rows - 1; r >= 0; r--) { cout << '|'; for ( c = 0; c < cols; c++) { cout << plot[r][c]; } cout << '|' << endl; } cout << '+' ; for ( c = 0; c < cols; c++) { cout << '-'; } cout << '+' << endl; } int main() { Matrix plot(ROWS, COLS, ' '); PlotData(plot, ROWS, COLS); PrintPlot(plot, ROWS, COLS); return 0; } charplot Name of file with data to plot: PlotData +--------------------------------------------------+ | | | | | | | | | | | | | * * | | * * | | * * * * | | * * | | ***** * * | | * * * * * * | | * * * *** * | | ***** * * | | * * | | | | | | | | | | * | | * | | * | | * | | * | |* | +--------------------------------------------------+ cat PlotData 12 12 12 13 12 14 13 14 14 14 15 14 16 11 16 12 16 13 16 14 12 11 13 11 14 11 15 11 0 0 2 1 4 2 6 3 8 4 10 5 22 12 24 11 27 10 29 10 32 11 34 12 35 13 35 14 35 15 34 16 32 17 29 18 27 18 24 17 22 16 21 15 21 14 21 13 25 16 31 16 25 13 27 12 28 12 29 12 31 13