Advertisement
TheWhiteFang

rabbit

Feb 4th, 2015
48
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.54 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. #include <string>
  4.  
  5. using namespace std;
  6.  
  7. class Screen{
  8.     char **m_ppScreen;
  9.     int m_Width;
  10.     int m_Height;
  11.  
  12. public:
  13.  
  14.     Screen(int inWidth, int inHeight)
  15.     {
  16.         m_Width = inWidth;
  17.         m_Height = inHeight;
  18.  
  19.         char **m_ppScreen = new char *[m_Height]; // pointer-to-pointer
  20.         for (int i = 0; i < m_Height; i++){
  21.             m_ppScreen[i] = new char[m_Width];
  22.         }
  23.     };
  24.  
  25.     ~Screen(){
  26.  
  27.         for (int i = 0; i < m_Height; i++){
  28.             delete[] m_ppScreen[i];
  29.         }
  30.         delete[] m_ppScreen;
  31.    
  32.     }
  33.  
  34.     void Set(int x, int y, char pixel)
  35.     {
  36.         /*for (int i = 0; i< m_Width; i++)
  37.             m_ppScreen[i] = new int[m_Height];*/
  38.  
  39.         /*for (int i = 0; i< x; i++){
  40.             for (int j = 0; j<y; j++)
  41.             {
  42.                 pixel >> m_ppScreen[i][j];
  43.             }
  44.         }*/
  45.  
  46.         m_ppScreen[x][y] = pixel;
  47.     };
  48.  
  49.     char Peek(int x, int y)
  50.     {
  51.         for (int i = 0; i< x; i++){
  52.             for (int j = 0; j<y; j++)
  53.             {
  54.                 return m_ppScreen[i][j];
  55.             }
  56.         }
  57.         /*return m_ppScreen[x][y];*/
  58.    
  59.     };
  60.  
  61.     void Display()
  62.     {
  63.         for (int i = 0; i < m_Height; i++){
  64.             for (int j = 0; j < m_Width; j++)
  65.             {
  66.                 cout << m_ppScreen[i][j] << "\t";
  67.             }
  68.             cout << endl;
  69.         }
  70.  
  71.  
  72.         /*for (int i = 0; i< m_Width; i++)
  73.             delete[] m_ppScreen[i];
  74.         delete[] m_ppScreen;*/
  75.     };
  76.  
  77. };
  78.  
  79. int main(){
  80.  
  81.     int row = 0;
  82.     int col = 0;
  83.     char v = 'v';
  84.  
  85.     fstream myFile("Data.txt", ios::in);
  86.     myFile >> row >> col;
  87.     cout << "ROW: " << row << ", COL: " << col << endl;
  88.  
  89.     Screen obj(row, col);
  90.     obj.Set(4, 3, 'v');
  91.     myFile << obj.Peek(4, 3);
  92.     obj.Display();
  93.  
  94.     myFile.close();
  95.  
  96.  
  97.  
  98.  
  99.  
  100.     return 0;
  101. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement