Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*#include <iostream>
- #include <fstream>
- #include <string.h>
- #include <stdio.h>
- #include <conio.h>
- #include <Windows.h>
- #include <ctime>
- #include <bitset>
- #include <string>
- #include <fstream>
- #include <Windows.h>*/
- #include <iostream>
- #include <fstream>
- #include <string>
- #include <string.h>
- #include <stdio.h>
- #include <conio.h>
- #include <Windows.h>
- #include <ctime>
- #include <bitset>
- #pragma
- using namespace std;
- HANDLE h = GetStdHandle(STD_OUTPUT_HANDLE);
- void readFromFile(string& nameCheck, string& passCheck,int& a)
- {
- ifstream fin;
- fin.open("data.txt");
- if (fin.is_open())
- {
- getline(fin, nameCheck);
- getline(fin, passCheck);
- }
- else
- {
- a = 0;
- }
- }
- void getword();
- void check(string name, string pass)
- {
- string nameCheck, passCheck;
- int a;
- readFromFile(nameCheck, passCheck, a);
- if (a != 0)
- {
- if (name != nameCheck)
- {
- cout << "Логин введён неправильно,попробуйте ещё раз\n" << endl;
- getword();
- }
- else if (pass != passCheck)
- {
- cout << "Пароль введён непрвильно,в наказание,введите логин заного\n" << endl;
- getword();
- }
- else
- {
- cout << "добро пожаловать в ад" << endl;
- }
- }
- else
- {
- cout << "Ошибка открытия файла,закройте программу,создайте файл <data.txt> и попробуйте снова" << endl;
- }
- }
- void getword()
- {
- string name, pass;
- cout << "Введите логин" << endl;
- cin >> name;
- cout << "Введите пароль" << endl;
- for (;;)
- {
- auto code = _getch();
- if (code == 13)
- {
- cout << endl;
- break;
- }
- if (code == 224)
- _getch(),
- code = 8;
- if (code == 8)
- {
- std::cout << "\b \b";
- if (!pass.empty())
- pass.pop_back();
- }
- else
- {
- const auto ch = static_cast<char>(code);
- pass += ch;
- std::cout << "*";
- }
- }
- check(name, pass);
- }
- int failcin()
- {
- while (true) {
- int userNumber;
- cin >> userNumber;
- if (cin.fail() || userNumber < 0) {
- cin.clear();
- cin.ignore(cin.rdbuf()->in_avail());
- cout << endl << "Попробуйте ввести корректное число: ";
- }
- else {
- cin.ignore(cin.rdbuf()->in_avail());
- return userNumber;
- }
- }
- }
- int failcinf()
- {
- while (true) {
- int userNumber;
- cin >> userNumber;
- if (cin.fail() || userNumber > 100) {
- cin.clear();
- cin.ignore(cin.rdbuf()->in_avail());
- cout << endl << "Попробуйте ввести корректное число: ";
- }
- else {
- cin.ignore(cin.rdbuf()->in_avail());
- return userNumber;
- }
- }
- }
- int failcinj()
- {
- while (true)
- {
- int userNumber;
- cin >> userNumber;
- if (cin.fail())
- {
- cin.clear();
- cin.ignore(cin.rdbuf()->in_avail());
- cout << endl << "Попробуйте ввести корректное число: ";
- }
- else if (userNumber == 0 || userNumber == 1 || userNumber == 2 || userNumber == 3 || userNumber == 4 || userNumber == 5 )
- {
- cin.ignore(cin.rdbuf()->in_avail());
- return userNumber;
- }
- else
- cout << endl << "Попробуйте ввести корректное число: ";
- }
- }
- int failcinw()
- {
- while (true) {
- int userNumber;
- cin >> userNumber;
- if (cin.fail()) {
- cin.clear();
- cin.ignore(cin.rdbuf()->in_avail());
- cout << endl << "Попробуйте ввести корректное число: ";
- }
- else {
- cin.ignore(cin.rdbuf()->in_avail());
- return userNumber;
- }
- }
- }
- void enter()
- {
- setlocale(LC_ALL, "");
- string userpass, username, Userpassword, name, pass;
- int option;
- cout << "0.регистрация пользователя\n";
- cout << "1.вход пользователя\n";
- option = failcin();
- switch (option)
- {
- case 0:
- {
- cout << "регистрация\n";
- cout << "имя пользователя:\n";
- cin >> userpass;
- cout << "пароль пользователя:\n";
- cin >> Userpassword;
- ofstream fout("data.txt"); // создаём объект класса ofstream для записи и связываем его с файлом cppstudio.txt
- fout << userpass << endl << Userpassword; // запись строки в файл
- fout.close(); // закрываем файл
- }
- break;
- default:
- {
- cout << "Авторизация: \n";
- getword();
- system("pause");
- }
- break;
- }
- }
- void groupnumber()
- {
- short int a = 9894;
- int i = 16;
- bool r2;
- r2 = a & (1U << --i);
- SetConsoleTextAttribute(h, 05);
- cout << r2 << " ";
- for (--i; i >= 0; --i)
- {
- r2 = a & (1U << i);
- if (i % 4 == 0)
- {
- SetConsoleTextAttribute(h, 02);
- cout << r2 << " ";
- }
- else
- {
- SetConsoleTextAttribute(h, 02);
- cout << r2;
- }
- }
- cout << " \n";
- }
- string scndname()
- {
- string scnd = "Шаронин";
- string binscnd;
- for (size_t i = 0; i < scnd.size(); ++i)
- {
- bitset<8> b(scnd.c_str()[i]);
- binscnd += b.to_string();
- }
- return binscnd;
- }
- void greetingN()
- {
- char name[9999] = "пользователь N";
- cout << "Приветствую, тебя," << name << ", На улице такая вьюга. Присаживайся у очага, здесь тебе всегда рады\n";
- cout << "Эту программу написал студент группы 9894, Шаронин Алексей.\nКстати, в памяти моего компьютера номер мой группы выглядит как: \n";
- groupnumber();
- SetConsoleTextAttribute(h, 07);
- cout << "\n";
- SetConsoleTextAttribute(h, 07);
- cout << "А Фамилия как \n";
- cout << scndname();
- cout << endl;
- system("pause");
- }
- void greeting()
- {
- char name[9999]; // буфер промежуточного хранения считываемого из файла текста
- ifstream fin("data.txt"); // открыли файл для чтения
- fin >> name; // считали первое слово из файла
- fin.close(); // закрываем файл
- cout << "Приветствую, тебя," << name << ", На улице такая вьюга. Присаживайся у очага, здесь тебе всегда рады\n";
- cout << "Эту программу написал студент группы 9894, Шаронин Алексей. Кстати, в памяти моего компьютера номер мой группы выглядит как: \n";
- groupnumber();
- SetConsoleTextAttribute(h, 07);
- cout << "А Фамилия как \n";
- cout << scndname();
- cout << endl;
- system("pause");
- }
- void showmas(int* A, int count) {
- if (count == 0)
- cout << "нет массива" << endl;
- else {
- for (int i = 0; i < count; ++i)
- cout << A[i] << " ";
- cout << endl;
- }
- }
- void inputARRFromFile(int*& A, int& elements)
- {
- ifstream in("arrtest.txt");
- if (in.is_open())
- {
- int temp;
- while (!in.eof())
- {
- in >> temp;
- ++elements;
- }
- in.seekg(0, ios::beg);
- in.clear();
- --elements;
- in.close();
- ifstream in("arrtest.txt");
- A = new int[elements];
- while (true)
- {
- for (int i = 0; i < elements; i++)
- {
- in >> A[i];
- }
- if (!in.eof())
- {
- for (int i = 0; i < elements; i++)
- {
- cout << A[i] << " ";
- }
- }
- else
- break;
- in.close();
- }
- }
- else
- {
- cout << "Файл с именем 'arrtest.txt' не найден." << endl << endl;
- }
- }
- void bubble(int* A, int count)
- {
- int t = 0;
- for (int i = 0; i < count; ++i)
- {
- for (int j = 0; j < count - 1; ++j)
- {
- if (A[j] > A[j + 1])
- {
- t = A[j];
- A[j] = A[j + 1];
- A[j + 1] = t;
- }
- }
- }
- }
- void swap(int* first, int* second)
- {
- *first = *first + *second;
- *second = *first - *second;
- *first = *first - *second;
- }
- void shaker(int* A, int count)
- {
- int left = 0, right = count - 1;
- bool motion = 1;
- int t = 0;
- while ((left < right) && motion == 1)
- {
- motion = 0;
- for (int i = left; i < right; ++i)
- {
- if (A[i] > A[i + 1])
- {
- t = A[i];
- A[i] = A[i + 1];
- A[i + 1] = t;
- motion = 1;
- }
- }
- --right;
- for (int i = right; i > left; --i)
- {
- if (A[i - 1] > A[i])
- {
- swap(&A[i - 1], &A[i]);
- motion = 1;
- }
- }
- ++left;
- }
- }
- void insert(int* A, int count)
- {
- int i, k, j;
- for (i = 1; i < count; ++i)
- {
- k = A[i];
- j = i - 1;
- while (j >= 0 && A[j] > k)
- {
- A[j + 1] = A[j];
- --j;
- }
- A[j + 1] = k;
- }
- }
- void quick(int* A, int start, int end)
- {
- int i = start, j = end, tmp;
- int separator = A[(start + end) / 2];
- while (i <= j)
- {
- while (A[i] < separator)
- ++i;
- while (A[j] > separator)
- --j;
- if (i <= j)
- {
- tmp = A[i];
- A[i] = A[j];
- A[j] = tmp;
- ++i;
- --j;
- }
- }
- if (start < j)
- quick(A, start, j);
- if (i < end)
- quick(A, i, end);
- }
- void comb(int* A, int count)
- {
- int gap = count;
- bool motion = 1;
- while (gap != 1 || motion == 1)
- {
- gap = (gap * 10) / 13;
- if (gap < 1)
- gap = 1;
- motion = 0;
- for (int i = 0; i < count - gap; ++i)
- {
- if (A[i] > A[i + gap])
- {
- int t = A[i];
- A[i] = A[i + 1];
- A[i + 1] = t;
- motion = 1;
- }
- }
- }
- }
- void sorts(int* ARR, int rows)
- {
- cout << "выберите метод сортировки:1-Bubble Sort,2-Shaker Sort,3-Insert Sort,4-Quick Sort,5-Comb Sort\n";
- cout << "Ваш выбор: ";
- int opt = failcinj();
- switch (opt)
- {
- case 1:
- {
- bubble(ARR, rows);
- }
- break;
- case 2:
- {
- shaker(ARR, rows);
- }
- break;
- case 3:
- {
- insert(ARR, rows);
- }
- break;
- case 4:
- {
- quick(ARR, 0, rows - 1);
- }
- break;
- case 5:
- {
- comb(ARR, rows);
- }
- break;
- }
- showmas(ARR, rows);
- }
- int f(int n)
- {
- if (n == 1 || n == 2)
- return 1;
- if (n == 0)
- return 0;
- return f(n - 1) + f(n - 2);
- }
- void mas()
- {
- srand(unsigned(time(NULL)));
- setlocale(0, "ru");
- cout << "метод заполнения\n";
- cout << "0.ручками\n";
- cout << "1.рандом\n";
- cout << "2.с файла\n";
- int option = failcin();
- switch (option)
- {
- case 0:
- {
- int h = 0, rows = 0;
- int el = 0;
- int* fib = new int[el];
- int* ARR = new int[rows];
- cout << "введите количевство элементов в массиве(не больше 100): ";
- rows = failcinf();
- for (int i = 0; i < rows; i++)
- {
- cout << "Введите значение элемента с индексом [" << i + 1 << "]";
- cin >> ARR[i];
- }
- showmas(ARR, rows);
- cout << "числа Фибоначчи: ";
- for (int i = 0; i < 15; ++i)
- cout << f(i) << " ";
- cout << endl;
- for (int i = 0; i < 15; i++)
- {
- fib[i] = f(i);
- }
- for (int i = 0; i < 15; i++)
- {
- if (ARR[i] == fib[i])
- ++h;
- else
- {
- break;
- }
- }
- if (h == 15)
- {
- cout << "первые 15 чисел явл Фибоначчи\n";
- }
- else
- {
- cout << "первые 15 чисел не явл Фибоначчи\n";
- }
- cout << h << " чисел Фибоначчи\n";
- sorts(ARR, rows);
- if (rows % 2 == 1)
- cout << "Медиана массива: " << ARR[rows / 2] << endl;
- else
- cout << "Медиана массива: " << (ARR[rows / 2 - 1] + ARR[rows / 2]) / 2 << endl;
- int arrayOfCount[100] = {};
- for (int i = 0; i < rows; ++i)
- ++arrayOfCount[ARR[i]];
- int maxElement = arrayOfCount[0];
- for (int i = 1; i < 100; ++i) {
- if (maxElement < arrayOfCount[i])
- maxElement = arrayOfCount[i];
- }
- int countSummary = 0;
- cout << "Мода(ы) массива: ";
- for (int i = 0; i < 100; ++i) {
- if (arrayOfCount[i] == maxElement) {
- cout << i << " ";
- ++countSummary;
- }
- }
- cout << endl;
- break;
- }
- case 1:
- {
- int h = 0;
- const int rows = 50;
- int* ARR = new int[rows];
- int el = 0;
- int* fib = new int[el];
- for (int i = 0; i < rows; i++)
- {
- ARR[i] = rand() % 100;
- }
- cout << endl;
- cout << "числа фибоначчи: ";
- for (int i = 0; i < 15; ++i)
- cout << f(i) << " ";
- cout << endl;
- for (int i = 0; i < rows; i++)
- {
- cout << ARR[i] << " ";
- }
- cout << endl;
- for (int i = 0; i < 15; i++)
- {
- fib[i] = f(i);
- }
- for (int i = 0; i < 15; i++)
- {
- if (ARR[i] == fib[i])
- ++h;
- else
- {
- h = 0;
- }
- }
- if (h==15)
- {
- cout << "первые 15 чисел явл фиб\n";
- }
- else
- {
- cout << "первые 15 чисел не явл фиб\n";
- }
- sorts(ARR, rows);
- if (rows % 2 == 1)
- cout << "Медиана массива: " << ARR[rows / 2] << endl;
- else
- cout << "Медиана массива: " <<(ARR[rows / 2 - 1] + ARR[rows / 2]) / 2 << endl;
- int arrayOfCount[100] = {};
- for (int i = 0; i < rows; ++i)
- ++arrayOfCount[ARR[i]];
- int maxElement = arrayOfCount[0];
- for (int i = 1; i < 100; ++i) {
- if (maxElement < arrayOfCount[i])
- maxElement = arrayOfCount[i];
- }
- int countSummary = 0;
- cout << "Мода(ы) массива: ";
- for (int i = 0; i < 100; ++i) {
- if (arrayOfCount[i] == maxElement) {
- cout << i << " ";
- ++countSummary;
- }
- }
- cout << endl;
- break;
- }
- case 2:
- {
- int h = 0, rows = 0;
- int el = 0;
- int* fib = new int[el];
- int* ARR = new int[rows];
- inputARRFromFile(ARR, rows);
- cout << "числа фибоначчи: ";
- for (int i = 0; i < 15; ++i)
- cout << f(i) << " ";
- cout << endl;
- for (int i = 0; i < 15; i++)
- {
- fib[i] = f(i);
- }
- for (int i = 0; i < 15; i++)
- {
- if (ARR[i] == fib[i])
- ++h;
- else
- {
- h = 0;
- }
- }
- if (h == 15)
- {
- cout << "первые 15 чисел явл фиб\n";
- }
- else
- {
- cout << "первые 15 чисел не явл фиб\n";
- }
- sorts(ARR, rows);
- if (rows % 2 == 1)
- cout << "Медиана массива: " << ARR[rows / 2] << endl;
- else
- cout << "Медиана массива: " << (ARR[rows / 2 - 1] + ARR[rows / 2]) / 2 << endl;
- int arrayOfCount[100] = {};
- for (int i = 0; i < rows; ++i)
- ++arrayOfCount[ARR[i]];
- int maxElement = arrayOfCount[0];
- for (int i = 1; i < 100; ++i) {
- if (maxElement < arrayOfCount[i])
- maxElement = arrayOfCount[i];
- }
- int countSummary = 0;
- cout << "Мода(ы) массива: ";
- for (int i = 0; i < 100; ++i) {
- if (arrayOfCount[i] == maxElement) {
- cout << i << " ";
- ++countSummary;
- }
- }
- delete[] ARR;
- cout << endl;
- break;
- }
- }
- system("pause");
- }
- void flagi()
- {
- HANDLE g = GetStdHandle(STD_OUTPUT_HANDLE);
- cout << "флаг России\n";
- SetConsoleTextAttribute(g, 240);
- cout << " \n";
- SetConsoleTextAttribute(g, 240);
- cout << " \n";
- SetConsoleTextAttribute(g, 240);
- cout << " \n";
- SetConsoleTextAttribute(g, 147);
- cout << " \n";
- SetConsoleTextAttribute(g, 147);
- cout << " \n";
- SetConsoleTextAttribute(g, 147);
- cout << " \n";
- SetConsoleTextAttribute(g, 200);
- cout << " \n";
- SetConsoleTextAttribute(g, 200);
- cout << " \n";
- SetConsoleTextAttribute(g, 200);
- cout << " \n\n\n";
- SetConsoleTextAttribute(g, 07);
- cout << "флаг Швеции\n";
- SetConsoleTextAttribute(g, 147);
- cout << " ";
- SetConsoleTextAttribute(g, 230);
- cout << " ";
- SetConsoleTextAttribute(g, 147);
- cout << " \n";
- SetConsoleTextAttribute(g, 147);
- cout << " ";
- SetConsoleTextAttribute(g, 230);
- cout << " ";
- SetConsoleTextAttribute(g, 147);
- cout << " \n";
- SetConsoleTextAttribute(g, 147);
- cout << " ";
- SetConsoleTextAttribute(g, 230);
- cout << " ";
- SetConsoleTextAttribute(g, 147);
- cout << " \n";
- SetConsoleTextAttribute(g, 230);
- cout << " \n";
- SetConsoleTextAttribute(g, 230);
- cout << " \n";
- SetConsoleTextAttribute(g, 230);
- cout << " \n";
- SetConsoleTextAttribute(g, 147);
- cout << " ";
- SetConsoleTextAttribute(g, 230);
- cout << " ";
- SetConsoleTextAttribute(g, 147);
- cout << " \n";
- SetConsoleTextAttribute(g, 147);
- cout << " ";
- SetConsoleTextAttribute(g, 230);
- cout << " ";
- SetConsoleTextAttribute(g, 147);
- cout << " \n";
- SetConsoleTextAttribute(g, 147);
- cout << " ";
- SetConsoleTextAttribute(g, 230);
- cout << " ";
- SetConsoleTextAttribute(g, 147);
- cout << " \n";
- _getch();
- }
- int meny()
- {
- while (true)
- {
- int opt = failcin();
- if (opt == 1 || opt == 2 || opt == 3 || opt == 4 || opt == 5)
- {
- return opt;
- }
- else
- {
- cout << "попробуйте ещё раз 1 -bubble,2-shaker,3-insert,4-quick,5-comb";
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement