Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "stdafx.h"
- void gotoxy(int xpos, int ypos)
- {
- COORD scrn;
- HANDLE hOuput = GetStdHandle(STD_OUTPUT_HANDLE);
- scrn.X = xpos; scrn.Y = ypos;
- SetConsoleCursorPosition(hOuput, scrn);
- }
- void printMatrix(int **d, int n) {
- cout << "Ваш граф: " << endl;
- for (int i = 0; i < n; i++) {
- for (int j = 0; j < n; j++) {
- cout.width(5);
- if (d[i][j] == INF) {
- cout << 0 << " ";
- }
- else {
- cout << d[i][j] << " ";
- }
- cout.width();
- }
- cout << endl;
- }
- }
- void getFromConsole(int **a, int&n, int &A, int &B, int& C, int &D) {
- cls;
- bool error = false;
- do {
- error = false;
- cout << "Введiть розряднiсть матрицi (n >= 4) >: ";
- cin >> n;
- if (cin.fail() || n < 4) {
- cin.clear();
- cin.sync();
- cout << "Некоректi даннi. Спробуйте ще раз" << endl;
- error = true;
- }
- } while (error);
- for (int i = 0; i < n; i++) {
- a[i] = new int[n];
- for (int j = 0; j < n; j++) {
- do {
- error = false;
- cout << " Введiть елемент [" << i << "," << j << "] >: ";
- cin >> a[i][j];
- if (i != j && (a[i][j] == 0 || a[i][j] == -1)) {
- a[i][j] = INF;
- }
- if (cin.fail() || a[i][j] < 0) {
- cin.clear();
- cin.sync();
- cout << "Некоректi даннi. Спробуйте ще раз" << endl;
- error = true;
- }
- } while (error);
- }
- }
- do {
- error = false;
- cout << "Введiть вершини A,B,C,D >: ";
- cin >> A >> B >> C >> D;
- if (cin.fail() || A <= 0 || B <= 0 || C <= 0 || D <= 0) {
- cin.clear();
- cin.sync();
- cout << "Некоректi даннi. Спробуйте ще раз" << endl;
- error = true;
- }
- if (A > n || B > n || C > n || D > n) {
- cout << "Некоректi даннi. Спробуйте ще раз" << endl;
- error = true;
- }
- } while (error);
- }
- bool getFromFile(int**a, int &n, int &A, int &B, int& C, int &D) {
- cls;
- ifstream in("input.txt");
- if (!in) {
- return false;
- }
- in >> n;
- if (in.fail() || n < 4) {
- cout << "N=" << n << endl;
- wait;
- in.clear();
- in.sync();
- return false;
- }
- for (int i = 0; i < n; i++) {
- a[i] = new int[n];
- for (int j = 0; j < n; j++) {
- in >> a[i][j];
- if (i != j && (a[i][j] == 0 || a[i][j] == -1)) {
- a[i][j] = INF;
- }
- if (in.fail() || a[i][j] < 0) {
- in.clear();
- in.sync();
- return false;
- }
- }
- }
- in >> A >> B >> C >> D;
- if (in.fail() || A <= 0 || B <= 0 || C <= 0 || D <= 0) {
- in.clear();
- in.sync();
- return false;
- }
- if (A > n || B > n || C > n || D > n) {
- return false;
- }
- return true;
- }
- int showMenu(const char* menu[], int itemsCount) {
- int code = 0, p = 0;
- do
- {
- cls;
- puts("------------------------------- Зробiть вибiр: --------------------------------");
- for (int i = 0; i < itemsCount; i++)
- {
- int k = (80 - strlen(menu[i])) / 2;
- if (i == p)
- {
- gotoxy(29, 8 + i * 2);
- putchar('>');
- }
- gotoxy(k, 8 + i * 2); puts(menu[i]);
- }
- code = _getch();
- if (code == 80)
- p > itemsCount - 2 ? p = 0 : ++p;
- if (code == 72)
- p < 1 ? p = itemsCount - 1 : --p;
- } while (code != 13);
- return p;
- }
- void showAbout() {
- cls;
- ifstream fAbout("about.txt");
- if (!fAbout) {
- cout << "Файл справки не знайдено" << endl;
- wait;
- return;
- }
- while (!fAbout.eof()) {
- string st;
- getline(fAbout, st);
- puts(st.c_str());
- }
- system("pause");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement