Другие языки программирования и технологии

Помогите пожалуйста переделать сей код под указатели и потом под функцию C++

#include <iostream>
#include <utility>
#include <iomanip>
#include <cstdlib>
using namespace std;
typedef bool(*compare)(const float, const float);
void input(float*, const size_t);
void print(float*, const size_t, const char* = "Элементы последовательности: \n");
size_t get_index_max_element(float*, const size_t);
size_t get_index_min_element(float*, const size_t);
int get_index_first_negative_element(float*, const int);
int get_index_last_negative_element(float*, const int);
int get_index_first_positive_element(float*, const int);
int get_index_last_positive_element(float*, const int);
double sum_array(float*, const size_t);
bool increase(const float, const float);
bool decrease(const float, const float);
void bubble(float*, const size_t, compare = increase);
int main() {
setlocale(LC_ALL, "Russian");
const size_t size = 10;
float arr[size];
input(arr, size);
print(arr, size);
cout << "Индекс максимального элемента последовательности: " << get_index_max_element(arr, size);
cout << "\nИндекс минимального элемента последовательности: " << get_index_min_element(arr, size);
cout << "\nИндекс первого отрицательного элемента последовательности: " << get_index_first_negative_element(arr, size);
cout << "\nИндекс последнего отрицательного элемента последовательности: " << get_index_last_negative_element(arr, size);
cout << "\nИндекс первого положительного элемента последовательности: " << get_index_first_positive_element(arr, size);
cout << "\nИндекс последнего положительного элемента последовательности: " << get_index_last_positive_element(arr, size);
cout << "\nСумма элементов последовательности: " << sum_array(arr, size);
bubble(arr, size);
print(arr, size, "\n\nМассив отсортированный по возрастанию: \n");
bubble(arr, size, decrease);
print(arr, size, "Массив отсортированный по убыванию: \n");
cin.sync();
cin.get();
return 0;
}
void bubble(float* v, const size_t s, compare cmp) {
for (size_t n = 1; n < s; ++n) for (size_t m = 0; m < s - n; ++m) if ((*cmp)(v[m], v[m + 1])) swap(v[m], v[m + 1]);
}
bool decrease(const float a, const float b) { return a < b; }
bool increase(const float a, const float b) { return a > b; }
double sum_array(float* v, const size_t s) {
double sm = 0;
for (size_t i = 0; i < s; ++i) sm += v[i];
return sm;
}
int get_index_last_positive_element(float* v, const int s) {
int last = s;
while (--last) if (v[last] >= 0) break;
return last;
}
int get_index_first_positive_element(float* v, const int s) {
for (int first = 0; first < s; ++first) if (v[first] >= 0) return first;
return -1;
}
int get_index_last_negative_element(float* v, const int s) {
int last = s;
while (--last) if (v[last] < 0) break;
return last;
}
int get_index_first_negative_element(float* v, const int s) {
for (int first = 0; first < s; ++first) if (v[first] < 0) return first;
return -1;
}
size_t get_index_min_element(float* v, const size_t s) {
float min_element = v[0];
size_t index = 0;
for (size_t i = 1; i < s; ++i) if (min_element > v[i]) {
min_element = v[i];
index = i;
}
return index;
}
size_t get_index_max_element(float* v, const size_t s) {
float max_element = v[0];
size_t index = 0;
for (size_t i = 1; i < s; ++i) if (max_element < v[i]) {
max_element = v[i];
index = i;
}
return index;
}
void print(float* v, const size_t s, const char* msg) {
cout << msg;
for (size_t i = 0; i < s; ++i) cout << left << fixed << setprecision(2) << setw(8) << v[i];
cout << endl;
}
Андрей Штрек
Андрей Штрек
90 243
Лучший ответ