Commit aeec71fc authored by Michael's avatar Michael

exercise_07_35v3

parent fb595546
......@@ -6,20 +6,21 @@ template <typename T>
void
printArray(const T array[], const size_t sizeOfArray, const size_t firstIdx = 0)
{
std::cout << array[firstIdx];
if (firstIdx == sizeOfArray - 1) {
if (1 == sizeof(T) && firstIdx == sizeOfArray - 1) {
std::cout << std::endl;
return;
}
if (sizeof(T) > 1) {
std::cout << ", ";
if (firstIdx < sizeOfArray) {
std::cout << array[firstIdx];
std::cout << (sizeof(T) > 1 ? " " : "");
return printArray(array, sizeOfArray, firstIdx + 1);
}
return printArray(array, sizeOfArray, firstIdx + 1);
std::cout << std::endl;
}
template <typename T>
void
numericArrayInitialization(T array[], const size_t sizeOfArray)
inputNumericArray(T array[], const size_t sizeOfArray)
{
for (size_t index = 0; index < sizeOfArray; ++index) {
if (::isatty(STDIN_FILENO)) {
......@@ -30,7 +31,7 @@ numericArrayInitialization(T array[], const size_t sizeOfArray)
}
void
charsArrayInitialization(char array[], const size_t sizeOfArray)
inputCharArray(char array[], const size_t sizeOfArray)
{
if (::isatty(STDIN_FILENO)) {
std::cout << "word: ";
......@@ -47,7 +48,7 @@ main()
size_t integersArraySize;
std::cin >> integersArraySize;
int integersArray[integersArraySize];
numericArrayInitialization(integersArray, integersArraySize);
inputNumericArray(integersArray, integersArraySize);
printArray(integersArray, integersArraySize);
if (::isatty(STDIN_FILENO)) {
std::cout << "Insert floating numbers array size and elements.\n" << "size: ";
......@@ -55,7 +56,7 @@ main()
size_t floatingArraySize;
std::cin >> floatingArraySize;
double floatingArray[floatingArraySize];
numericArrayInitialization(floatingArray, floatingArraySize);
inputNumericArray(floatingArray, floatingArraySize);
printArray(floatingArray, floatingArraySize);
if (::isatty(STDIN_FILENO)) {
std::cout << "Insert characters array size and elements.\n" << "size: ";
......@@ -63,7 +64,7 @@ main()
size_t charactersArraySize;
std::cin >> charactersArraySize;
char charactersArray[charactersArraySize];
charsArrayInitialization(charactersArray, charactersArraySize);
inputCharArray(charactersArray, charactersArraySize);
printArray(charactersArray, charactersArraySize);
return 0;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment