
C/C++
Информатика 2 курс

05)
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <numeric>
#include <cstdlib>
#include <ctime>
#define RAND(min, max) (rand() % ((max) - (min)) + (min))
using namespace std;
int main() {
srand(unsigned(time(nullptr)));
system("chcp 1251 > nul");
cout.setf(ios::fixed);
cout.precision(2U);
auto w = 4U;
int box[10];
for (auto& x : box) {
x = RAND(-5, 6);
cout << setw(w) << x;
}
puts("");
auto avg = accumulate(begin(box), end(box), 0.0) / size(box);
cout << "\n Среднее арифметическое: " << avg << "\n\n";
auto fpos = find_if(begin(box), end(box), [](int x) { return x > 0; });
auto first = box[0];
for (auto& x : box) if (x > avg) x = first;
for (auto x : box) cout << setw(w) << x;
puts("");
system("pause > nul");
}
2)
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstdlib>
using namespace std;
struct RectangularParallelepiped {
double a, b, h;
RectangularParallelepiped() : a(0), b(0), h(0) {}
RectangularParallelepiped(double a, double b, double d) : a(a), b(b), h(h) {}
double volume()const {
return a * b * h;
}
friend istream& operator>>(istream& inp, RectangularParallelepiped& rp) {
return inp >> rp.a >> rp.b >> rp.h;
}
friend bool operator<(const RectangularParallelepiped& a, const RectangularParallelepiped& b) {
return a.volume() < b.volume();
}
};
int main() {
double a, b, h;
RectangularParallelepiped rp[5];
for (auto i = 0U; i < size(rp); ++i) {
cout << i + 1 << ". ";
cin >> rp[i];
}
auto min = min_element(begin(rp), end(rp));
auto pos = distance(begin(rp), min) + 1;
cout << "Element #" << pos << '\n';
system("pause > nul");
}
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <numeric>
#include <cstdlib>
#include <ctime>
#define RAND(min, max) (rand() % ((max) - (min)) + (min))
using namespace std;
int main() {
srand(unsigned(time(nullptr)));
system("chcp 1251 > nul");
cout.setf(ios::fixed);
cout.precision(2U);
auto w = 4U;
int box[10];
for (auto& x : box) {
x = RAND(-5, 6);
cout << setw(w) << x;
}
puts("");
auto avg = accumulate(begin(box), end(box), 0.0) / size(box);
cout << "\n Среднее арифметическое: " << avg << "\n\n";
auto fpos = find_if(begin(box), end(box), [](int x) { return x > 0; });
auto first = box[0];
for (auto& x : box) if (x > avg) x = first;
for (auto x : box) cout << setw(w) << x;
puts("");
system("pause > nul");
}
2)
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstdlib>
using namespace std;
struct RectangularParallelepiped {
double a, b, h;
RectangularParallelepiped() : a(0), b(0), h(0) {}
RectangularParallelepiped(double a, double b, double d) : a(a), b(b), h(h) {}
double volume()const {
return a * b * h;
}
friend istream& operator>>(istream& inp, RectangularParallelepiped& rp) {
return inp >> rp.a >> rp.b >> rp.h;
}
friend bool operator<(const RectangularParallelepiped& a, const RectangularParallelepiped& b) {
return a.volume() < b.volume();
}
};
int main() {
double a, b, h;
RectangularParallelepiped rp[5];
for (auto i = 0U; i < size(rp); ++i) {
cout << i + 1 << ". ";
cin >> rp[i];
}
auto min = min_element(begin(rp), end(rp));
auto pos = distance(begin(rp), min) + 1;
cout << "Element #" << pos << '\n';
system("pause > nul");
}
Похожие вопросы
- Программа по с++ информатика пожалуйста ю
- Напишите пожалуйста код на 5 вариант очень простой я на 1 курсе вуза и нужен простой код.
- Вопрос, про курс по программированию на C++
- Почему в школах начинают информатику учить с систем счисления? Это все равно что в 1 классе заставить интегралы учить.
- Информатика нужна программа
- Информатика, 8 класс. C++
- Помогите с информатикой. не могу найти ошибку в коде
- Информатика(Программирование). Перевод с С++ на Паскаль.
- Задача по информатике, C++
- Задача по информатике, C++, помогите