Advertisement
kone4

169026

Sep 25th, 2016
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.73 KB | None | 0 0
  1. #include <iostream>
  2. #include <stdlib.h>
  3. #include <conio.h>
  4. #include <Windows.h>
  5.  
  6. using namespace std;
  7.  
  8. class Number{
  9. private:
  10.     char string[10][10];
  11.     int x;
  12.     int y;
  13.     char num;
  14. public:
  15.     void Init_String();
  16.     void Set_String(int i, char j);
  17.     void Control_String();
  18.     void Print_String();
  19. };
  20.  
  21. void Number::Init_String(){
  22.     for (int i = 0; i < 10; i++){
  23.         for (int j = 0; j < 10;j++)
  24.         string[i][j] = ' ';
  25.     }
  26. }
  27.  
  28. void Number::Set_String(int i, char j){
  29.     int x = i / 10;
  30.     int y = i % 10;
  31.     num = j;
  32.     string[x][y] = num;
  33. }
  34.  
  35. void Number::Control_String(){
  36.     char ch;
  37.  
  38.     ch = _getch();
  39.     while (ch != 27) {
  40.         switch (ch) {
  41.         case 75:
  42.             if (x == 0){
  43.                 break;
  44.             }
  45.             else if (x != 0){
  46.                 x -= 1;
  47.                 num -= 1;
  48.                 break;
  49.             }
  50.  
  51.         case 77:
  52.             if (x == 9){
  53.                 x = 9;
  54.                 string[x][y] = num;
  55.             }
  56.             else if (x <= 8){
  57.                 string[x][y] = 0;
  58.                 ++x;
  59.                 string[x][y] = num;
  60.             }
  61.             Print_String();
  62.             break;
  63.  
  64.         case 72:
  65.             if (y == 0){
  66.                 y = 0;
  67.                 string[x][y] = num;
  68.             }
  69.             else if (y > 0){
  70.                 string[x][y] = 0;
  71.                 --y;
  72.                 string[x][y] = num;
  73.             }
  74.             Print_String();
  75.             break;
  76.  
  77.         case 80:
  78.             if (y == 9){
  79.                 y = 9;
  80.                 string[x][y] = num;
  81.             }
  82.             else if (y < 0){
  83.                 string[x][y] = 0;
  84.                 ++y;
  85.                 string[x][y] = num;
  86.             }
  87.             Print_String();
  88.             break;
  89.         }
  90.         ch = _getch();
  91.     }  
  92.  
  93. }
  94.  
  95. void Number::Print_String(){
  96.     system("cls");
  97.     for (int i = 0; i < 10; i++){
  98.         for (int j = 0; j < 10; j++)
  99.             cout << string[i][j];
  100.         cout << endl;
  101.     }
  102. }
  103.  
  104. int main() {
  105.     int i;
  106.     char num;
  107.     Number nm;
  108.  
  109.     cout << "Input Location: ";
  110.     cin >> i;
  111.     cout << "Input Alpha: ";
  112.     cin >> num;
  113.  
  114.     nm.Init_String();
  115.     nm.Set_String(i, num);
  116.     nm.Print_String();
  117.     nm.Control_String();
  118.  
  119.     return 0;
  120. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement