c Write a predicate function called isStrictlyIncreasing tha

c++

Write a predicate function called isStrictlyIncreasing that checks whether an array of integers contains values that are in strictly increasing order. A declaration of the function is shown above. The function returns true if the elements are in strictly increasing order; otherwise it returns false. For example, it will return true for (-2, 4, 5, 6, 8) and it will return false for (3, 4, 6, 6, 9). Write test code that tests every statement in the function. Use assertions in your test code. Hint: Compare a[i] with a[i + 1] and remember to stop at i = n - 1 so you don\'t access a value past the end of the array.

Solution

#include <iostream>
using namespace std;
bool isStrictlyIncreasing(int a[], int len);
int main() {
   int len=5;
   int a[] = { -2, 4, 5, 6, 8 };
   cout << isStrictlyIncreasing(a,len) << endl;
}
bool isStrictlyIncreasing(int a[], int len){
   int count = 0;
for(int i = 0; i < len-1; i++){
   if(a[i] < a[i+1]){
       count = count + 1;
   }
}
  
if(count == len-1){
   return true;
}else{
   return false;
}
}

c++ Write a predicate function called isStrictlyIncreasing that checks whether an array of integers contains values that are in strictly increasing order. A dec

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site