plot_arr.cpp
Upload User: dq031136
Upload Date: 2022-08-08
Package Size: 802k
Code Size: 1k
Development Platform:

C++ Builder

  1. #include <iostream.h>
  2. #include <strstrea.h>
  3. const int size = 5;
  4. class plot 
  5. {
  6.    int x, y;
  7.  public:
  8.    plot(int i, int j)
  9.     {
  10.       if(i>size)
  11.          i = size;
  12.       if(i<0)
  13.          i = 0;
  14.       if(j>size)
  15.          j = size;
  16.       if(j<0)
  17.          j=0;
  18.       x=i;
  19.       y=j;
  20.     }
  21.    friend ostream &operator<<(ostream &stream, plot obj);
  22. };
  23. ostream &operator<<(ostream & stream, plot obj)
  24.  {
  25.    register int i, j;
  26.    for(j=size; j>=0; j--)
  27.     {
  28.       stream << j;
  29.       if(j==obj.y)
  30.        {
  31.          for(i=0; i<obj.x; i++)
  32.             stream << "  ";
  33.             stream << '*';
  34.        }
  35.       stream << endl;
  36.     }
  37.    for(i=0; i<=size; i++)
  38.       stream << " " << i;
  39.    stream << endl;
  40.    return stream;
  41.  }
  42. void main(void)
  43.  {
  44.    plot a(2,3), b(1,1);
  45.    char str[200];
  46.    cout << "Output using cout:" << endl;
  47.    cout << a << endl << b << endl << endl;
  48.    ostrstream outs(str, sizeof(str));
  49.    outs << a << b << ends;
  50.    cout << "output using in-RAM formatting:" << endl;
  51.    cout << str;
  52.  }