Exercise 5 (Please use c++ code) bool isUnlucky(int all, int len); Implement a f
ID: 3929193 • Letter: E
Question
Exercise 5
(Please use c++ code)
bool isUnlucky(int all, int len); Implement a function that determines if the unlucky number 13 appears in an array. The function returns true if 13 appears in the array at least once; otherwise it returns false. Write test code that tests every statement in the function. Use assertions in your test code. bool isStrictlylncreasing (int a[], int len); Write a predicate function called isStrictlylncreasing 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.Explanation / Answer
Here are the 2 functions for you:
#include <iostream>
using namespace std;
bool isUnlucky(int a[], int len)
{
for(int i = 0; i < len; i++)
if(a[i] == 13)
return true;
return false;
}
bool isStrictlyIncreasing(int a[], int len)
{
for(int i = 0; i < len-2; i++)
if(a[i] > a[i+1])
return false;
return true;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.