Форум программистов
 

Восстановите пароль или Зарегистрируйтесь на форуме, о проблемах и с заказом рекламы пишите сюда - alarforum@yandex.ru, проверяйте папку спам!

Вернуться   Форум программистов > IT форум > Помощь студентам
Регистрация

Восстановить пароль
Повторная активизация e-mail

Купить рекламу на форуме - 42 тыс руб за месяц

Ответ
 
Опции темы Поиск в этой теме
Старый 21.03.2023, 00:53   #1
faktor
Пользователь
 
Регистрация: 14.02.2023
Сообщений: 10
По умолчанию C/C++ помогите пожалуйста переделать код

Код:
#include <vector>
using namespace std;

vector<int> point;
void ListOfTheHighest(Abiturient pAbiturient[3], vector<int> list, int n)
{
    if (n < 1) return;

    int max = list[0];
    int ind = 0;

    for (int i = 0; i < list.size(); i++)
    {
        if (list[i] > max)
        {
            max = list[i];
            ind = i;
        }
    }
    for (int j = 0; j < 3; j++)
    {
        if (max == arr[j].point)
        {
            cout << arr[j].lastname << endl;
            list.erase(list.begin() + ind);
        }
    }
    ListOfTheHighest(arr, list, n - 1);
}

void SumMoreThenB(Abiturient pAbiturient[3], int b, int ind)
{
    if (ind < 0) return;

    int sum = 0;

    for (int i = 0; i < 3; i++)
    {
        for (int j = 0; j < 6; j++)
        {
            sum += arr[ind].marks[i].lect_mark[j];
        }
    }

    if (sum > b)
    {
        cout << "Abiturient " << arr[ind].lastname << " " << arr[ind].name << " " << arr[ind].patronymic << ": " << sum << '\n';
    }

    pAbiturient[ind].points = sum;
    point.push_back(sum);
    SumMoreThenB(arr, b, ind - 1);
}

int main() {
    Abiturient std[] = { std3, std2, std1 };

//Входные данные
    int a, b, c;

    cout << "Maximum unsatisfactory mark:";
    cin >> a;
    cout << "Marks sum:";
    cin >> b;
    cout << "The number of Abiturients with the hignest number of points:";
    cin >> c;
    cout << endl;

//Вызов рекурсии
    cout << "List of abiturients, whose sum of points is more than " << b << ":" << endl;
    SumMoreThenB(std, b, size(std) - 1);
    cout << endl;

//Вызов рекурсии
    cout << "List of abiturients(n = " << c << ") with highest points:" << endl;
    ListOfTheHighest(std, points, c);

    return 0;
}
Нужно не использовать vector а использовать настоящий массив
помогите пожалуйста переделать под настоящий массив
faktor вне форума Ответить с цитированием
Старый 21.03.2023, 01:35   #2
Linok0036
 
Регистрация: 20.03.2023
Сообщений: 4
По умолчанию

Код:
#define MAX_SIZE 100

Abiturient std[] = { std3, std2, std1 };
int point[MAX_SIZE];

void ListOfTheHighest(Abiturient pAbiturient[3], int list[], int n)
{
    if (n < 1) return;

    int max = list[0];
    int ind = 0;

    for (int i = 0; i < n; i++)
    {
        if (list[i] > max)
        {
            max = list[i];
            ind = i;
        }
    }

    for (int j = 0; j < 3; j++)
    {
        if (max == pAbiturient[j].points)
        {
            cout << pAbiturient[j].lastname << endl;
            list[ind] = -1;
        }
    }

    ListOfTheHighest(pAbiturient, list, n - 1);
}

void SumMoreThenB(Abiturient pAbiturient[3], int b, int ind)
{
    if (ind < 0) return;

    int sum = 0;

    for (int i = 0; i < 3; i++)
    {
        for (int j = 0; j < 6; j++)
        {
            sum += pAbiturient[ind].marks[i].lect_mark[j];
        }
    }

    if (sum > b)
    {
        cout << "Abiturient " << pAbiturient[ind].lastname << " " << pAbiturient[ind].name << " " << pAbiturient[ind].patronymic << ": " << sum << '\n';
    }

    pAbiturient[ind].points = sum;
    point[ind] = sum;
    SumMoreThenB(pAbiturient, b, ind - 1);
}

int main() {

    //Входные данные
    int a, b, c;

    cout << "Maximum unsatisfactory mark:";
    cin >> a;
    cout << "Marks sum:";
    cin >> b;
    cout << "The number of Abiturients with the hignest number of points:";
    cin >> c;
    cout << endl;

    //Вызов рекурсии
    cout << "List of abiturients, whose sum of points is more than " << b << ":" << endl;
    SumMoreThenB(std, b, 2);
    cout << endl;

    //Вызов рекурсии
    cout << "List of abiturients(n = " << c << ") with highest points:" << endl;
    ListOfTheHighest(std, point, c);

    return 0;
}
Linok0036 вне форума Ответить с цитированием
Старый 21.03.2023, 07:18   #3
Алексей1153
фрилансер
Форумчанин
 
Регистрация: 11.10.2019
Сообщений: 960
По умолчанию

faktor, зачем показывать код, который неполный, а затем просить его исправить?
Алексей1153 вне форума Ответить с цитированием
Ответ


Купить рекламу на форуме - 42 тыс руб за месяц



Похожие темы
Тема Автор Раздел Ответов Последнее сообщение
Помогите пожалуйста переделать код в ООП user12102018 JavaScript, Ajax 1 13.10.2018 20:31
Помогите переделать код под мое условие пожалуйста Desheg Помощь студентам 1 21.05.2018 19:56
Ребят пожалуйста помогите переделать код из си в паскаль Makson Паскаль, Turbo Pascal, PascalABC.NET 2 26.11.2014 21:37
Помогите,пожалуйста,переделать программу. vep Общие вопросы C/C++ 5 19.10.2009 00:35
Помогите пожалуйста переделать прогу barbossa Общие вопросы C/C++ 1 08.06.2009 13:10