Question 1: Consider the following incomplete main function. int main () { ofstr
ID: 3737633 • Letter: Q
Question
Question 1:
Consider the following incomplete main function.
int main () {
ofstream myfile ("example.txt");
if (myfile.is_open())
{
//TODO: complete this block of code
}
else cout << "Unable to open file";
return 0;
}
Which statements might be used to complete the if block?
Question 2 (Could choose more than one answer):
Consider the following recursive binary search function:
int search::rBinarySearch(int sortedArray[], int first, int last, int key)
{
if (first <= last) {
int mid = (first + last) / 2; // compute mid point.
if (key == sortedArray[mid])
return mid; // found it.
else if (key < sortedArray[mid])
// Calls itself for the lower part of the array
return rBinarySearch(sortedArray, first, mid-1, key);
else
// Calls itself for the upper part of the array
return rBinarySearch(sortedArray, mid+1, last, key);
}
return -1;
}
Which of the following might be described as the base case(s) for this method to end the recursion?
A. when there are no elements in the specified range of indices (when this statement is false):
C. When the midpoint value is greater than the target (when this statement is true)
D. when the value is found in the middle of the range (when this statement is true):
Question3:
What is wrong with this function?
void swapShellsFirstInArray(int &basket[5])
{
int temp = basket[0];
basket[0] = basket[1];
basket[1] = temp;
}
D. The return type should not be void
Question 4:
I have declared the following function:
Here is my main function:
What is wrong?
Question 5: (Could choose more than one answer)
Explain two things that are wrong with this code and how to fix them:
#include <string>
int sum(x, y)
{
std::string result;
result = x + y;
return result;
}
A. while ( myfile.good() ) { getline (myfile,line); cout << line << endl; } myfile.close();
Explanation / Answer
here are the answers..
Ans 1: Option A is correct.
Ans 2: Not clear
Ans 3: Option A is correct.
Ans 4: Option E is correct.
Ans 5: Option B, D are correct.
================================================================
KIndly Check and Verify Thanks..!!!
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.