C/C++

ПРОГРАММИРОВАНИЕ ПОМОГИТЕ СРОЧНО

Создать очередь и заполнить её случайными целыми числами из диапазона 1-100. Найти и вывести на печать все: простые числа, количество чётных и нечётных чисел, все числа кратные 5-и и 10-и
#include <iostream>
#include <queue>
#include <random>
#include <iterator>
using namespace std;
class Statistic {
public:
Statistic(const queue<int> box) : box(box) {}
void show()const {
auto tmp = box;
cout << "Queue:";
while (!tmp.empty()) {
cout << ' ' << tmp.front();
tmp.pop();
}
puts("");
}
void show_prime()const {
auto count = 0U;
auto tmp = box;
cout << "Prime:";
while (!tmp.empty()) {
if (isprime(tmp.front())) {
cout << ' ' << tmp.front();
++count;
}
tmp.pop();
}
puts(count ? "" : "not found!");
}
size_t count_even()const {
auto count = 0U;
auto tmp = box;
while (!tmp.empty()) {
if (~tmp.front() & 1) ++count;
tmp.pop();
}
return count;
}
size_t count_odd()const {
auto count = 0U;
auto tmp = box;
while (!tmp.empty()) {
if (tmp.front() & 1) ++count;
tmp.pop();
}
return count;
}
void multiples(unsigned n)const {
auto count = 0U;
auto tmp = box;
cout << "Multiples " << n << ":";
while (!tmp.empty()) {
if (0 == tmp.front() % n) {
cout << ' ' << tmp.front();
++count;
}
tmp.pop();
}
puts(count ? "" : "not found!");
}
private:
queue<int> box;
bool isprime(unsigned n, unsigned m = 2)const {
if (m > (n >> 1)) return true;
return n % m? isprime(n, ++m) : false;
}
};
void random_fill(queue<int>& box, size_t n, unsigned a, unsigned b) {
if (a > b) swap(a, b);
uniform_int_distribution<unsigned> uid(a, b);
mt19937 gen{ random_device()() };
for (auto i = 0U; i < n; ++i) box.push(uid(gen));
}
int main() {
queue<int> box;
random_fill(box, 25, 1, 100);
Statistic tab(box);
tab.show();
tab.show_prime();
cout << "Even: " << tab.count_even() << '\n';
cout << "Odd: " << tab.count_odd() << '\n';
tab.multiples(5);
tab.multiples(10);
system("pause > nul");
}
Kaltai Kozhamzhar
Kaltai Kozhamzhar
62 550
Лучший ответ