Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Help! 1-What is the output of this program? bool function(int *arr, int v, int s); int main() { int myArr[5] = {3, 7, 5, 77,

Help!

1-What is the output of this program?

bool function(int *arr, int v, int s);

int main()

{

int myArr[5] = {3, 7, 5, 77, 87};

if(function(myArr, 7, 5))

cout << "YES!" << endl;

else

cout << "NO!" << endl;

return 0;

}

bool function(int *arr, int v, int s)

{

if (s == 0)

return false;

else if (arr[s - 1] == v)

return true;

else

return function(arr, v, s-1);

}

================================================================

2-What is the expected output of the program below?

void function(string str, int pos, int size);

int main()

{

string mystr = "Exam1";

function(mystr, 0, mystr.size());

return 0;

}

void function(string str, int pos, int size)

{

if(pos < size)

{

function(str, pos+1, size);

cout << str[pos];

}

}

===========================================================

4-The following is the pseudocode for which type of algorithm?

Set first to 0

Set last to the last subscript in the array

Set found to false

Set position to -1

While found is not true and first is less than or equal to last

Set middle to the subscript halfway between array[first] and array[last]

If array[middle] equals the desired value

Set found to true

Set position to middle

Else If array[middle] is greater than the desired value

Set last to middle - 1

Else

Set first to middle + 1

End If

End While

Return position

========================================

The following is the pseudocode for which type of algorithm?

For maxElement = each subscript in the array, from the last to the first

For index = 0 To maxElement - 1

If array[index] > array[index + 1]

swap array[index] with array[index + 1]

End If

End For

End For

======================================

Given the following code, assume the myStack object is a stack that can hold integers and that value is an int variable. 1 myStack.push(6); 2 myStack.push(7); 3 myStack.push(8); 4 myStack.pop(value); 5 myStack.push(9); 6 myStack.pop(value); 7 cout << value << endl; Assume that the pop function, called on lines 4 and 6, stores the number popped from the stack in the value variable. What will the statement on line 7 display?

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

DB2 11 The Ultimate Database For Cloud Analytics And Mobile

Authors: John Campbell, Chris Crone, Gareth Jones, Surekha Parekh, Jay Yothers

1st Edition

1583474013, 978-1583474013

More Books

Students also viewed these Databases questions