Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Danny_Test4.cpp : Defines the entry point for the console application.
- //
- #include "stdafx.h"
- auto setcolor(unsigned short , unsigned short &) -> void;
- auto generate_numbers(int **, size_t const &) -> void;
- auto happy_numbers(int **, size_t const) -> void;
- int main()
- {
- size_t choice, array_size;
- int **lottery = nullptr;
- unsigned short val;
- do {
- system("cls");
- setcolor(15, val);
- cout << "Menu: \n\n";
- cout << "[1] Generate numbers\n";
- cout << "[2] Happy numbers\n\n";
- cout << "[0] Exit\n";
- do {
- cout << "\nYour choice: ";
- cin >> choice;
- } while (choice < 0 || choice > 9 || !cin);
- switch (choice) {
- case 1:
- system("cls");
- do {
- cout << "Enter size of lottery numbers: ";
- cin >> array_size;
- } while (!cin || array_size < 50 || array_size > 100);
- lottery = new int*[array_size];
- for (size_t i = 0; i < array_size; i++)
- lottery[i] = new int[6];
- generate_numbers(lottery, array_size);
- cout << "\n\nPress any key to get back to the menu...";
- _getch();
- break;
- case 2:
- system("cls");
- if (lottery == nullptr) {
- cout << "First input the array!";
- cout << "\n\nPress any key to get back to the menu...";
- _getch();
- break;
- }
- happy_numbers(lottery, array_size);
- cout << "\n\nPress any key to get back to the menu...";
- _getch();
- break;
- }
- } while (choice != 0);
- return 0;
- }
- auto generate_numbers(int **array, size_t const &array_size) -> void {
- random_device rd;
- mt19937 gen(rd());
- uniform_int_distribution<> dist(0, 9);
- unsigned short val;
- auto setTimeout([=](size_t ms) { Sleep(ms); });
- cout << endl;
- for (size_t i = 0; i < array_size; i++)
- for (size_t j = 0; j < 6; j++)
- array[i][j] = dist(gen);
- for (size_t i = 0; i < array_size; i++) {
- cout << setw(5) << "[" << i << "] ";
- for (size_t j = 0; j < 6; j++)
- cout << array[i][j];
- setcolor(i, val);
- if (i % 4 == 0)
- cout << endl;
- setTimeout(250);
- }
- }
- auto happy_numbers(int **array, size_t const array_size) -> void {
- size_t counter = 0;
- unsigned short val;
- auto setTimeout([=](size_t ms) { Sleep(ms); });
- for (size_t i = 0; i < array_size; i++) {
- int sum1(0), sum2(0);
- setcolor(i, val);
- for (size_t j = 0; j < 6; j++)
- if (j > 2)
- sum1 += array[i][j];
- else
- sum2 += array[i][j];
- if (sum1 == sum2) {
- counter++;
- cout << "\n\nThe number ";
- for (size_t j = 0; j < 6; j++)
- cout << array[i][j];
- cout << " is a happy number!\n";
- cout << "The sum of the first three numbers is " << sum2 << " and the sum of the last three numbers is " << sum1;
- }
- setTimeout(250);
- }
- setcolor(15, val);
- if (counter > 0)
- cout << "\n\nThere are " << counter << " happy numbers!";
- else
- cout << "There are no happy numbers!";
- }
- auto sets(int **array, size_t const array_size) {
- unsigned short val;
- auto setTimeout([=](size_t ms) { Sleep(ms); });
- size_t counter1(0), counter2(0);
- for (size_t i = 0; i < array_size; i++) {
- string number;
- for (size_t j = 0; j < 6; j++)
- number += array[i][j];
- if (stoi(number) % 2 == 0)
- counter1++;
- else if (stoi(number) % 4 == 0)
- counter2++;
- }
- }
- auto setcolor(unsigned short color, unsigned short &predishen) -> void // функция за задаване на цвят чрез число и допълнителна променлива за проверка
- {
- random_device rd; // Сийдър за генератора
- mt19937 gen(rd()); // Генератор на случайни числа
- uniform_int_distribution<> dist(9, 15); // Генериране на случайни числа в зададен интервал
- if (color < 9 || color > 15) { // Избира само ярки цветове
- color = dist(gen); // Цвета става случайно число в интервала от 9 до 15 включително
- while (color == predishen) { // проверяваме предишният цвят дали съвпада с текущият
- color = dist(gen); // Ако съвпада, го генерираме наново, докато стане различен
- }
- }
- predishen = color; // текущият цвят става предишен и продължаваме напред
- HANDLE hcon = GetStdHandle(STD_OUTPUT_HANDLE);
- SetConsoleTextAttribute(hcon, color);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement