Relz / OOP

Лабораторные работы по Объектно-ориентированному программированию (IDE - Visual Studio 2015)
0 stars 0 forks source link

Замечания по программе vector #4

Open alexey-malov opened 8 years ago

alexey-malov commented 8 years ago
alexey-malov commented 8 years ago
        for (unsigned i = 1; i < numbers.size(); i += 2)
        {
            numbers[i % numbers.size()] += positiveNumSum;
        }

из элементов, стоящих на нечетных позициях, вычесть сумму всех неотрицательных элементов

Тесты должны проверять эту ситуацию

alexey-malov commented 8 years ago
    for (unsigned i = 1; i < numbers.size(); i += 2)
    {
        numbers[i % numbers.size()] *= 2;
    }
alexey-malov commented 8 years ago
alexey-malov commented 8 years ago
alexey-malov commented 8 years ago

Бонус начисляется за вывод элементов массива в порядке возрастания их значений

alexey-malov commented 8 years ago
bool sortGreater(double a, double b)
bool vectorsAreEquals(vector<double> vector0, vector<double> vector1)
alexey-malov commented 8 years ago
bool vectorsAreEquals(vector<double> vector0, vector<double> vector1)
alexey-malov commented 8 years ago
bool vectorsAreEquals(vector<double> vector0, vector<double> vector1)
{
    if (vector0.size() != vector1.size())
    {
        return false;
    }
    for (unsigned i = 0; i < vector0.size(); ++i)
    {
        if (fabs(vector0[i] - vector1[i]) > 0.00001 * fabs(vector0[i]))
        {
            return false;
        }
    }
    return true;
}
alexey-malov commented 8 years ago
bool vectorsAreEquals(vector<double> vector0, vector<double> vector1)
{
    if (vector0.size() != vector1.size())
    {
        return false;
    }
    for (unsigned i = 0; i < vector0.size(); ++i)
    {
        if (fabs(vector0[i] - vector1[i]) > 0.00001 * fabs(vector0[i]))
        {
            return false;
        }
    }
    return true;
}

http://www.viva64.com/ru/w/V104/print/ http://www.viva64.com/ru/w/V108/print/

alexey-malov commented 8 years ago
BOOST_AUTO_TEST_CASE(does_not_change_vector_containing_zero_numbers)
{
    vector<double> numbers = { 0, 0, 0 };
    vector<double> copy(numbers);
    ProcessVector(numbers);
    BOOST_CHECK(vectorsAreEquals(numbers, copy));
}
alexey-malov commented 8 years ago
// Вычитание из каждого нечетного элемента вектора сумму положительных элементов
void SubEvensElementsWithPositives(std::vector<double> &numbers)
alexey-malov commented 8 years ago
        for (unsigned i = 0; i < numbers.size(); i += 2)
        {
            numbers[i] -= positiveNumSum;
        }

http://www.viva64.com/ru/w/V104/print/ http://www.viva64.com/ru/w/V108/print/

alexey-malov commented 8 years ago
void MulOddsEltsBy2(std::vector<double> &numbers)
{
    for (unsigned i = 1; i < numbers.size(); i += 2)
    {
        numbers[i % numbers.size()] *= 2;
    }
}
alexey-malov commented 8 years ago
alexey-malov commented 8 years ago
alexey-malov commented 8 years ago
alexey-malov commented 7 years ago
alexey-malov commented 7 years ago
    vector<double> numbers = { -1, 0, -3, 0 };
    vector<double> copy(numbers);
    ProcessVector(numbers);
    BOOST_CHECK(VectorsAreEquals(numbers, copy));

    numbers = { 0, 0, 0 };
    copy = numbers;
    ProcessVector(numbers);
    BOOST_CHECK(VectorsAreEquals(numbers, copy));

    numbers = { 1, 2.5, 3, 4.7, 5, 6.9, 7, 8.2, 9, 0 };
    vector<double> numbersRequired = { -46.3, 5, -44.3, 9.4, -42.3, 13.8, -40.3, 16.4, -38.3, 0 };
    ProcessVector(numbers);
    BOOST_CHECK(VectorsAreEquals(numbers, numbersRequired));

    numbers = { -1, -53.21, 1, 24.112, -213.521, 9842.124 };
    numbersRequired = { -9868.236, -106.42, -9866.236, 48.224, -10080.757, 19684.248 };
    ProcessVector(numbers);
    BOOST_CHECK(VectorsAreEquals(numbers, numbersRequired));
alexey-malov commented 7 years ago
        double positiveNumSum = 0;
        for (double number : numbers)
        {
            positiveNumSum += (number > 0) ? number : 0;
        }
alexey-malov commented 7 years ago
bool VectorsAreEquals(const vector<double> &vector0, const vector<double> &vector1)
{
    if (vector0.size() != vector1.size())
    {
        return false;
    }
    for (unsigned i = 0; i < vector0.size(); ++i)
    {
        if (fabs(vector0[i] - vector1[i]) > 0.00001 * fabs(vector0[i]))
        {
            return false;
        }
    }
    return true;
}