Sum the array values

In reply to Design Engineer:
For the sum you can refer to this 7.12.3 Array reduction methods .


class A;
    typedef struct {
    int english,maths,science;
    string name;
    } mark_t;
    mark_t sheet ;
    mark_t q[$];
    mark_t result[$];
    int val ;
   
 task process_stuct_data();
      sheet = '{50,60,80,"john"};
      q.push_back(sheet);
      sheet = '{60,70,50,"peter"};
      q.push_back(sheet);
      sheet = '{70,60,90,"nathan"};
      q.push_back(sheet);
      
      result = q.find with ( item.english >= 60 && item.maths >= 60);
      // find the sum 
      foreach(q[i]) begin 
        val = q.sum with ( item.index == i ? item.english + item.maths + item.science : 0);   
    
        if(val > 200) begin 
          
          $display("%p",q[i]);
          
        end 
    endtask 
  endclass