-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathp3.cpp
40 lines (38 loc) · 993 Bytes
/
p3.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#include <iostream>
using namespace std;
class Array {
private:
int* arr;
int size;
public:
Array(int s) : size(s) {
arr = new int[size];}
Array(const Array& other) {
size = other.size;
arr = new int[size];
for (int i = 0; i < size; i++) {
arr[i] = other.arr[i];}}
void input() {
for (int i = 0; i < size; i++) {
cin >> arr[i];}}
int* getArray() const {
return arr;}
int getSize() const {
return size;} };
class SumOfPositive {
public:
static int calculate(const Array& arr) {
int sum = 0;
for (int i = 0; i < arr.getSize(); i++) {
if (arr.getArray()[i] > 0) {
sum += arr.getArray()[i];}}
return sum;}};
void main() {
int n;
cout<<"ENTER THE SIZE OF ARRAY:";
cin >> n;
Array arr(n);
cout<<"ENTER THE ARRAY:";
arr.input();
Array copyArr = arr;
cout << SumOfPositive::calculate(copyArr) << endl;}