Please write these problems in C++ format 32. a) Write a function named ascendin
ID: 3626518 • Letter: P
Question
Please write these problems in C++ format
32. a) Write a function named ascending that passes in a vector of integers and returnstrue
if all values in the vector are in ascending order and false otherwise. In other words, the function should return true if the values in the vector are arranged from the smallest
number to the largest number. For example, if the function is passed a vector with the values,
Member Functions
Point: Rect:
get_x() get_lower_left()
get_y() get_width()
get_height()
1, 2, 5, 6, 6, 9, 11, 17 in this order, then the function should return
function is passed a vector with the values, 6, 6, 5, 8, 8, 9, in this order, then the function
should return
b) Write a program (main function) that tests your
the vector, you may initialize it with any values you choose, but you must give it at least 3
values. This main function must output “
(ascending returns the correct value) or “Failed” if the function does not pass the test
(ascending returns an incorrect value).
Explanation / Answer
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
bool asecnding(vector<int>& v)
{
for(int i=0; i<v.size()-1; i++)
if(v[i]>v[i+1]) return false;
return true;
}
int main()
{
int a[]={1,2,3,4,5,6};
vector<int> v(a,a+6);
cout << asecnding(v)<<endl;
return 0;
}