Сдайте ему этот код и никаких вопросов к вам не возникнет.
#include
#include
#include
#include
#include
class array_12 {
public:
array_12();
array_12(int(&a)[12]);
const size_t size = 12;
typedef std::array array12;
typedef array12::const_iterator aci;
typedef array12::iterator ai;
void random_array(int = -10, int = 10);
long long sum_positive()const;
long long milt_negative()const;
void input_array();
bool is_positive()const;
bool is_negative()const;
private:
array12 v;
void reset();
friend std::ostream& operator<<(std::ostream&, const array_12&);
};
int randomize(int, int);
int input_int(const std::string = " enter one integer: ");
void without_positive();
void without_negative();
int main() {
array_12 a;
a.random_array();
std::cout << "\n random array: " << a << std::endl;
if (a.is_positive()) std::cout << " sum = " << a.sum_positive() << std::endl;
else without_positive();
if (a.is_negative()) std::cout << " mult = " << a.milt_negative() << std::endl;
else without_negative();
int b[12] = { -2, -3, -4, -5, -6, 3, 4, 5, 7, 8, 5, -2 };
array_12 c(b);
std::cout << "\n existing array: " << c << std::endl;
if (c.is_positive()) std::cout << " sum = " << c.sum_positive() << std::endl;
else without_positive();
if (c.is_negative()) std::cout << " mult = " << c.milt_negative() << std::endl;
else without_negative();
array_12 d;
std::cout << "\n\t enter the array:\n";
d.input_array();
std::cout << "\n entered array: " << d << std::endl;
if (d.is_positive()) std::cout << " sum = " << d.sum_positive() << std::endl;
else without_positive();
if (d.is_negative()) std::cout << " mult = " << d.milt_negative() << std::endl;
else without_negative();
std::cin.sync();
std::cin.get();
}
array_12::array_12() { reset(); }
array_12::array_12(int(&a)[12]) { for (auto i = 0u; i < size; ++i) v[i] = a[i]; }
void array_12::reset() { for (ai i = v.begin(); i != v.end(); ++i) *i = 0; }
void array_12::random_array(int l, int r) { for (ai i = v.begin(); i != v.end(); ++i) *i = randomize(l, r); }
std::ostream& operator<<(std::ostream& out, const array_12& arr) {
for (array_12::aci i = arr.v.begin(); i != arr.v.end(); ++i) out << ' ' << *i;
return out;
}
long long array_12::sum_positive()const {
long long sum = 0;
for (aci i = v.begin(); i != v.end(); ++i) if (*i > 0) sum += *i;
return sum;
}
long long array_12::milt_negative()const {
long long mult = 1;
for (aci i = v.begin(); i != v.end(); ++i) if (*i < 0) mult *= *i;
return mult;
}
void array_12::input_array() { for (ai i = v.begin(); i != v.end(); ++i) *i = input_int(); }
bool array_12::is_positive()const {
for (aci i = v.begin(); i != v.end(); ++i) if (*i >= 0) return true;
return false;
}
bool array_12::is_negative()const {
for (aci i = v.begin(); i != v.end(); ++i) if (*i < 0) return true;
return false;
}
int randomize(int left, int right) {
std::uniform_int_distribution rand(left, right);
std::random_device rnd;
return rand(rnd);
}
int input_int(const std::string msg) {
int i;
do {
std::cout << msg;
std::cin >> i;
if (std::cin.good()) return i;
else {
std::cin.clear();
std::cin.ignore(std::cin.rdbuf()->in_avail());
std::cout << "\aError!\n";
}
} while (true);
}
void without_positive() { std::cout << " positive numbers are missing" << std::endl; };
void without_negative() { std::cout << " negative numbers are missing" << std::endl; };