Facebook
From Wojciech, 6 Years ago, written in C++.
Embed
Download Paste or View Raw
Hits: 251
  1. #include "stdafx.h"
  2. #include <iostream>
  3. #include <string>
  4.  
  5. using std::cout;
  6. using std::endl;
  7.  
  8. class Window
  9. {
  10. private:
  11.         int x, y;
  12.         char *tab;
  13. public:
  14.         Window(int xx, int yy);
  15.         ~Window();
  16.         void display();
  17.         void write(int x1, int y1, char c);
  18. };
  19.  
  20. Window::Window(int xx, int yy) : x(xx), y(yy)
  21. {
  22.         tab = new char[x*y];
  23.         for (int i = 0; i < x*y; i++) tab[i] = ' ';
  24. }
  25.  
  26. Window::~Window()
  27. {
  28.         delete tab;
  29. }
  30. void Window::display()
  31. {
  32.         for (int i = 0; i < x*y; i++)
  33.         {
  34.                 cout << tab[i];
  35.                 if ((i%x) + 1 == x) cout << endl;
  36.         }
  37. }
  38.  
  39. void Window::write(int x1, int y1, char c)
  40. {
  41.         tab[x1 + (y1*x)] = c;
  42. }
  43.  
  44.  
  45. int main()
  46. {
  47.         Window w1(7, 6);
  48.         w1.write(0, 0, 'f');
  49.         w1.write(1, 1, 'h');
  50.         w1.write(0, 4, 'x');
  51.         w1.write(2, 2, 'e');
  52.         w1.write(3, 3, 'c');
  53.         w1.display();
  54.  
  55.         getchar();
  56.         return 0;
  57. }