Last active
May 30, 2017 20:00
-
-
Save gonaumov/b9c6bf623fecf8539a2c4ce4c84550f9 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <string> | |
#include <limits> | |
using namespace std; | |
#define MINIMUM_SIZE 2 | |
#define MAXIMUM_SIZE 125 | |
void dumpArray(double input[], int inputSize) | |
{ | |
for (int i = 0; i < inputSize; i++) | |
{ | |
cout << "position " << i << ": " << input[i] << endl; | |
} | |
} | |
int main() | |
{ | |
int arraySize, | |
currentPosition = 0, | |
i; | |
double *arrayFromDoubles, | |
*maximum, | |
*minimum, | |
tempSwap; | |
cout << "Please enter array size between " | |
<< MINIMUM_SIZE | |
<< " and " | |
<< MAXIMUM_SIZE | |
<< endl; | |
while (!(cin >> arraySize) || arraySize < MINIMUM_SIZE || arraySize > MAXIMUM_SIZE) | |
{ | |
cin.clear(); | |
cin.ignore(numeric_limits<streamsize>::max(),'\n'); | |
cout << "Please input a proper integer number between " | |
<< MINIMUM_SIZE | |
<< " and " | |
<< MAXIMUM_SIZE | |
<< ", thank you!: " | |
<< endl; | |
} | |
arrayFromDoubles = new double[arraySize]; | |
while (currentPosition < arraySize) | |
{ | |
cout << "Please enter element on position "; | |
cout << currentPosition | |
<< endl; | |
while(!(cin >> arrayFromDoubles[currentPosition])) | |
{ | |
cin.clear(); | |
cin.ignore(numeric_limits<streamsize>::max(),'\n'); | |
cout << "Please input a proper real number, thank you!: " | |
<< endl; | |
} | |
currentPosition++; | |
} | |
minimum = maximum = arrayFromDoubles; | |
for (i = 1; i < arraySize; i++) | |
{ | |
if (arrayFromDoubles[i] > *maximum) | |
{ | |
maximum = &arrayFromDoubles[i]; | |
} | |
else if(arrayFromDoubles[i] < *minimum) | |
{ | |
minimum = &arrayFromDoubles[i]; | |
} | |
} | |
cout << "The inputed array:" | |
<< endl; | |
dumpArray(arrayFromDoubles, arraySize); | |
tempSwap = *maximum; | |
*maximum = *minimum; | |
*minimum = tempSwap; | |
cout << "The inputed array after swapping:" | |
<< endl; | |
dumpArray(arrayFromDoubles, arraySize); | |
delete[] arrayFromDoubles; | |
arrayFromDoubles = 0; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment