Advertisement
stuxjkee

Untitled

Apr 29th, 2015
222
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.46 KB | None | 0 0
  1. #include "stdafx.h"
  2.  
  3. void gotoxy(int xpos, int ypos)
  4. {
  5.     COORD scrn;
  6.     HANDLE hOuput = GetStdHandle(STD_OUTPUT_HANDLE);
  7.     scrn.X = xpos; scrn.Y = ypos;
  8.     SetConsoleCursorPosition(hOuput, scrn);
  9. }
  10.  
  11. void printMatrix(int **d, int n) {
  12.     cout << "Ваш граф: " << endl;
  13.  
  14.     for (int i = 0; i < n; i++) {
  15.         for (int j = 0; j < n; j++) {
  16.             cout.width(5);
  17.             if (d[i][j] == INF) {
  18.                 cout << 0 << " ";
  19.             }
  20.             else {
  21.                 cout << d[i][j] << " ";
  22.             }
  23.             cout.width();
  24.         }
  25.         cout << endl;
  26.     }
  27. }
  28.  
  29. void getFromConsole(int **a, int&n, int &A, int &B, int& C, int &D) {
  30.     cls;
  31.  
  32.     bool error = false;
  33.     do {
  34.         error = false;
  35.         cout << "Введiть розряднiсть матрицi (n >= 4) >: ";
  36.         cin >> n;
  37.  
  38.         if (cin.fail() || n < 4) {
  39.             cin.clear();
  40.             cin.sync();
  41.             cout << "Некоректi даннi. Спробуйте ще раз" << endl;
  42.             error = true;
  43.         }
  44.     } while (error);
  45.     for (int i = 0; i < n; i++) {
  46.         a[i] = new int[n];
  47.         for (int j = 0; j < n; j++) {
  48.             do {
  49.                 error = false;
  50.                 cout << " Введiть елемент [" << i << "," << j << "] >: ";
  51.                 cin >> a[i][j];
  52.  
  53.                 if (i != j && (a[i][j] == 0 || a[i][j] == -1)) {
  54.                     a[i][j] = INF;
  55.                 }
  56.  
  57.                 if (cin.fail() || a[i][j] < 0) {
  58.                     cin.clear();
  59.                     cin.sync();
  60.                     cout << "Некоректi даннi. Спробуйте ще раз" << endl;
  61.                     error = true;
  62.                 }
  63.             } while (error);
  64.         }
  65.     }
  66.     do {
  67.         error = false;
  68.         cout << "Введiть вершини A,B,C,D >: ";
  69.         cin >> A >> B >> C >> D;
  70.  
  71.         if (cin.fail() || A <= 0 || B <= 0 || C <= 0 || D <= 0) {
  72.             cin.clear();
  73.             cin.sync();
  74.             cout << "Некоректi даннi. Спробуйте ще раз" << endl;
  75.             error = true;
  76.         }
  77.         if (A > n || B > n || C > n || D > n) {
  78.             cout << "Некоректi даннi. Спробуйте ще раз" << endl;
  79.             error = true;
  80.         }
  81.     } while (error);
  82. }
  83.  
  84. bool getFromFile(int**a, int &n, int &A, int &B, int& C, int &D) {
  85.     cls;
  86.     ifstream in("input.txt");
  87.     if (!in) {
  88.         return false;
  89.     }
  90.     in >> n;
  91.     if (in.fail() || n < 4) {
  92.         cout << "N=" << n << endl;
  93.         wait;
  94.         in.clear();
  95.         in.sync();
  96.         return false;
  97.     }
  98.     for (int i = 0; i < n; i++) {
  99.         a[i] = new int[n];
  100.         for (int j = 0; j < n; j++) {
  101.             in >> a[i][j];
  102.             if (i != j && (a[i][j] == 0 || a[i][j] == -1)) {
  103.                 a[i][j] = INF;
  104.             }
  105.             if (in.fail() || a[i][j] < 0) {
  106.                 in.clear();
  107.                 in.sync();
  108.                 return false;
  109.             }
  110.         }
  111.     }
  112.     in >> A >> B >> C >> D;
  113.     if (in.fail() || A <= 0 || B <= 0 || C <= 0 || D <= 0) {
  114.         in.clear();
  115.         in.sync();
  116.         return false;
  117.     }
  118.     if (A > n || B > n || C > n || D > n) {
  119.         return false;
  120.     }
  121.     return true;
  122.  
  123. }
  124.  
  125. int showMenu(const char* menu[], int itemsCount) {
  126.     int code = 0, p = 0;
  127.     do
  128.     {
  129.         cls;
  130.         puts("------------------------------- Зробiть вибiр: --------------------------------");
  131.         for (int i = 0; i < itemsCount; i++)
  132.         {
  133.             int k = (80 - strlen(menu[i])) / 2;
  134.             if (i == p)
  135.             {
  136.                 gotoxy(29, 8 + i * 2);
  137.                 putchar('>');
  138.             }
  139.             gotoxy(k, 8 + i * 2); puts(menu[i]);
  140.         }
  141.         code = _getch();
  142.         if (code == 80)
  143.             p > itemsCount - 2 ? p = 0 : ++p;
  144.         if (code == 72)
  145.             p < 1 ? p = itemsCount - 1 : --p;
  146.     } while (code != 13);
  147.     return p;
  148. }
  149.  
  150. void showAbout() {
  151.     cls;
  152.     ifstream fAbout("about.txt");
  153.     if (!fAbout) {
  154.         cout << "Файл справки не знайдено" << endl;
  155.         wait;
  156.         return;
  157.     }
  158.     while (!fAbout.eof()) {
  159.         string st;
  160.         getline(fAbout, st);
  161.         puts(st.c_str());
  162.     }
  163.     system("pause");
  164. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement