Какая проблема в этом коде? [требует правки]

206
06 марта 2018, 04:16
#include <iostream>
#include <cmath>
using namespace std;
int * input(int iN);
void shift(int * a, int iN);
void output(int * a, int iN);
int main() {
    int iN;
    int * a;
    cout << "Введіть величину масиву: ";
    cin >> iN;
    a = input(iN);
    shift(a, iN);
    output(a, iN);
    return 0;
}
int * input(int iN, int choose, int numElement)
{
    srand(time_t(NULL));
    int * a = new int[iN];
    cout << "Масив: ";
    for (int i = 0; i < iN; i++) {
        a[i] = rand() % 10;
        cout << a[i] << " ";
    }
    cout << endl;
    return a;
}
void shift(int * a, int iN)
{
    int nullEl, lastEl, choose, numElement;
    // вибір зсуву
    do {
        cout << "Ви бажаєте зсунути елементи масиву наліво (1) чи направо (2)?: ";
        cin >> choose;
    } while (choose != 1 && choose != 2);
    // величина зсуву масиву
    cout << "Введіть, на яку кількість елементів хочете здвинути масив: ";
    cin >> numElement;
    // зсув наліво
    if (choose == 1) {
        for (int m = 0; m < numElement; m++) {
            nullEl = a[0];
            for (int i = 0; i < iN; i++) {
                a[i] = a[i + 1];
                if ( i + 1 == iN) {
                    a[i] = nullEl;
                }
            }
        }
    }
    // зсув вправо
    else if (choose == 2) {
        for (int m = 0; m < numElement; m++) {
            lastEl = a[iN - 1];
            for (int i = iN - 1; i > 0; i--) {
                a[i] = a[i - 1];
                if (i - 1 == 0) {
                    a[0] = lastEl;
                }
            }
        }
    }
}
void output(int * a, int iN)
{
    // кінцевий вигляд масиву
    cout << "Масив: ";
    for (int i = 0; i < iN; i++) {
        cout << a[i] << " ";
    }
    cout << endl;
}

Xcode явных ошибок не находит, но показывает вот такие эрроры:

Answer 1

В общем, так:

Была ошибка в кол-ве аргументов функции input().

#include <iostream>
#include <cmath>
using namespace std;

int *input(int iN)
{
    srand(time_t(NULL));
    int *a = new int[iN];
    cout << "Масив: ";
    for (int i = 0; i < iN; i++) {
        a[i] = rand() % 10;
        cout << a[i] << " ";
    }
    cout << endl;
    return a;
}
void shift(int *a, int iN)
{
    int nullEl, lastEl, choose, numElement;
    // вибір зсуву
    do {
        cout << "Ви бажаєте зсунути елементи масиву наліво (1) чи направо (2)?: ";
        cin >> choose;
    } while (choose != 1 && choose != 2);
    // величина зсуву масиву
    cout << "Введіть, на яку кількість елементів хочете здвинути масив: ";
    cin >> numElement;
    // зсув наліво
    if (choose == 1) {
        for (int m = 0; m < numElement; m++) {
            nullEl = a[0];
            for (int i = 0; i < iN; i++) {
                a[i] = a[i + 1];
                if ( i + 1 == iN) {
                    a[i] = nullEl;
                }
            }
        }
    }
    // зсув вправо
    else if (choose == 2) {
        for (int m = 0; m < numElement; m++) {
            lastEl = a[iN - 1];
            for (int i = iN - 1; i > 0; i--) {
                a[i] = a[i - 1];
                if (i - 1 == 0) {
                    a[0] = lastEl;
                }
            }
        }
    }
}
void output(int *a, int iN)
{
    // кінцевий вигляд масиву
    cout << "Масив: ";
    for (int i = 0; i < iN; i++) {
        cout << a[i] << " ";
    }
    cout << endl;
}
int main() {
    int iN;
    int *a;
    cout << "Введіть величину масиву: ";
    cin >> iN;
    a = input(iN);
    shift(a, iN);
    output(a, iN);
    return 0;
}
READ ALSO
Расшифровка в &ldquo;C++&rdquo; с помощью массивов

Расшифровка в “C++” с помощью массивов

Как осуществить расшифровку текста с данным ключом с помощью массивов? (В "C++" 2-ой месяц)

177
Не выводит данные на jsp страничке

Не выводит данные на jsp страничке

Проблема в отображении person на jsp страницеЕсли оставить только id, то страница отображается и показывает id

203