Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

What is wrong in the following code? #include <iostream> #include <vector> using

ID: 3580100 • Letter: W

Question

What is wrong in the following code?

    #include <iostream>

    #include <vector>

    using namespace std;

    int main()

    {

        vector<int> v;

        cout << v[0];

        return 0;

    }

   2.In a recursive power function that calculates some base to the exp power, what is the recursive call?

     3.What is the output of the following code fragment?

int f1(int n, int m)

{

                if(n < m)

                                return 0;

                else if(n==m)

                                return m+ f1(n-1,m);

                else

                                return n+ f1(n-2,m-1);

}

int main()

{

    cout << f1(1,4);

    return 0;

}

4.The following catch block catches all __________ exceptions.

catch ( string e)

{

}

5.Given the following function definition, what happens if the function throws the exception?

void f1( ) throw (double)

{    if( //some code here)

                throw 12;

}

the 12 will be converted to 12.0

the function will throw an integer exception which is passed to the calling code.

the function will cause the program to exit

this code has a syntax error

6.template<typename T>
T maxValue(const T &value1, const T &value2)
{
   if (value1 > value2)
     return value1;
   else
     return value2;
}
Which of the following statements are correct?

A. cout << maxValue(1.5, 2)

B. cout << maxValue('A', 'B')

C. cout << maxValue(1, 2)

D. cout << maxValue("AB", "AB")

E. cout << maxValue(1.5, 2.5)

7. Given the following search function declaration, give the corresponding declaration for a templated search function?

int search( int array[], int start, int target, int size);

//pre: start is > 0, and < size

//the position of the first occurance of target at or after start is returned, or -1 is returned.

Explanation / Answer

3)

Here n=1 and m= 4

now if (n<m)
i<4 true
it return 0

4) 4) This catch block will not catch any exception instead it won't compile as Exception is the super class of exceptions and if you want a generic oject then create
catch(Exception e)
also string is not any exception class

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote