Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <time.h>
- #include <iomanip>
- #include <windows.h>
- using namespace std;
- void setRed()
- {
- SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_RED);
- }
- void setGreen()
- {
- SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_GREEN);
- }
- void setWhite()
- {
- SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE);
- }
- int main()
- {
- int arrayIndexSize, arraySize, randRangeFrom, randRangeTo;
- bool isPositive = true;
- char v(0);
- cout << "Enter array\'s first index\' value: ";
- cin >> arrayIndexSize;
- cout << "Enter array\'s second index\' value: ";
- cin >> arraySize;
- if (arrayIndexSize < 1 || arraySize < 1) {
- cout << "\n\nBoth values must be posivive integers.\n\n";
- return 0;
- }
- int **arr = new int *[arrayIndexSize];
- for (int i = 0; i < arrayIndexSize; i++)
- {
- arr[i] = new int[arraySize];
- }
- cout << "\n\nHow would You like to fill in array, (M)anually or (A)utomatically? \n:";
- cin >> v;
- if (v == 'M') {
- cout << "\nnice =)\n\n";
- for (int i = 0; i < arrayIndexSize; i++)
- {
- cout << "Entering row " << i + 1 << ".\n\n";
- for (int j = 0; j < arraySize; j++)
- {
- cout << "Enter element " << j + 1 << ": ";
- cin >> arr[i][j];
- }
- cout << endl;
- }
- }
- else if (v == 'A') {
- cout << "\nYou\'re lazy =)\n\n";
- cout << "Enter initial range value: ";
- cin >> randRangeFrom;
- cout << "Enter end range value: ";
- cin >> randRangeTo;
- cout << endl;
- srand(time(NULL));
- for (int i = 0; i < arrayIndexSize; i++)
- {
- for (int j = 0; j < arraySize; j++)
- {
- arr[i][j] = rand() % (randRangeTo - randRangeFrom + 1) + randRangeFrom;
- }
- }
- }
- else {
- cout << "\nI expected \"M\" or \"A\".\nCome on, Cutie.\n\n";
- return 0;
- }
- cout << "Your array is ready and served:\n\n";
- for (int i = 0; i < arrayIndexSize; i++)
- {
- for (int j = 0; j < arraySize; j++)
- {
- if (i == j && arr[i][i] < 0)
- {
- setRed();
- cout << setw(5) << arr[i][j];
- setWhite();
- isPositive = false;
- }
- else if (i == j && arr[i][i] >= 0)
- {
- setGreen();
- cout << setw(5) << arr[i][j];
- setWhite();
- }
- else
- {
- cout << setw(5) << arr[i][j];
- }
- }
- cout << endl;
- }
- if (isPositive)
- {
- setGreen();
- cout << "\nAll main diagonal elements are posive. Hoorray!" << endl;
- setWhite();
- }
- else
- {
- setRed();
- cout << "\nNot all main diagonal elements are posive. Sorry to tell You that, Cutie." << endl;
- setWhite();
- }
- for (int i = 0; i < arrayIndexSize; i++)
- {
- delete[] arr[i];
- }
- delete[] arr;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement