Question: Write a program that takes an input array of integers and returns the sum of all the positive numbers in the array.

Requirements:

  1. Define a function named sumPositiveNumbers that takes two parameters: an integer array (arr) and its size (size).
  2. The function should iterate through each element of the array and calculate the sum of all positive numbers.
  3. Return the sum from the function.
  4. The program should prompt the user to enter the size of the array and its elements.
  5. Use dynamic memory allocation to create an array of the specified size.
  6. After calculating the sum, deallocate the dynamically allocated memory.

Example Output:

Enter the size of the array: 5
Enter the elements of the array:
Element 0: -1
Element 1: 4
Element 2: 0
Element 3: 7
Element 4: -3
Sum of positive numbers: 11

#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include<utility> 
#include<algorithm> 
using namespace std;

int main(){
    vector<int> arr; 
    int size; 
    cout << "Enter the size of the array: ";
    cin >> size;
    int number; 
    int total; 
    for(int i = 0; i < size; i++){
        cout << "Element " << i <<": "; 
        cin >> number; 
        arr.push_back(number); 
    }
    
    for(int i = 0; i < size; i++){
        if(arr[i] > 0){
            total += arr[i]; 

        }
    }
    cout << "Sum of positive numbers: " << total; 
}