Answer the question
In order to leave comments, you need to log in
How to translate code into OOP c++?
There is a simple C++ program that, using a given formula, counts the elements of two arrays if they correspond to the positive elements of the third array. Here is the code:
#include <iostream>
#include <cmath>
using namespace std;
int main(void)
{
int i = 0;
int n = 10;
float avrg = 0;
int sum = 0;
// Определяю массивы
float a[n] = { -7, 17, 69, 25, 88, 14, 84, 36, -4, 75 };
float b[n] = { 16, -30, 11, 39, 15, -36, 12, 6, -30, 5 };
float c[n] = { -19, 35, -6, 15, -9, 13, 8, 12, -33, 42 };
cout << "Первый массив: ";
for (i = 0; i < n; i++)
cout << a[i] << " ";
cout << "\nВторой массив: ";
for (i = 0; i < n; i++)
cout << b[i] << " ";
cout << "\nТретий массив: ";
for (i = 0; i < n; i++)
cout << c[i] << " ";
// Определяю массив y
int y[n];
int yn = 0;
for (i = 0; i < 10; i++) {
if (c[i] > 0) {
y[i] = a[i] - b[i];
yn++;
} else {
y[i] = pow(10, 23);
}
}
cout << "\nЧетвёртый массив: ";
for (i = 0; i < n; i++) {
if (y[i] > -100) {
cout << y[i] << " ";
}
}
// Нахожу средние арифметические
for (i = 0; i < n; i++) {
if (y[i] > -100) {
sum += y[i];
}
}
avrg = sum / yn;
cout << "\nСреднее арифметические: " << avrg << endl;
// Дисперсия массива y
int d = 0;
for (i = 0; i < n; i++) {
if (y[i] > -100) {
d += (pow((y[i] - avrg), 2)) / (6 - 1);
}
}
cout << "Дисперсия: " << d;
// Минимальный элемент массива y
// float min = y[0];
// for (i = 0; i < n; ++i) {
// if (y[i] < min) {
// min = y[i];
// }
// }
// cout << "\nМинимальный элемент массива: " << min;
return 0;
}
Answer the question
In order to leave comments, you need to log in
Please help translate this program into OOP!
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question