Programs (Set - 1)

Question 6 :

Which of the following statement is correct about the program given below?

#include < iostream . h > 
class IndiaParinam
{ 
    public:
    void Parinam(int x = 15)
    {
        x = x/2; 
        if(x > 0)
            Parinam(); 
        else
            cout<< x % 2; 
    } 
};
int main()
{
    IndiaParinam objIB;
    objIB.Parinam();
    return 0; 
}


A). The program will display 1.
B). The program will display 2.
C). The program will display 15.
D). The program will go into an infinite loop.
E). The program will report error on compilation.
Answer : Option D

Question 7 :

Which of the following statement is correct about the program given below?

#include < iostream . h >
long GetNumber(long int Number)
{
    return --Number;
}
float GetNumber(int Number)
{
    return ++Number;
}
int main()
{
    int x = 20;
    int y = 30;
    cout<< GetNumber(x) << " ";
    cout<< GetNumber(y) ;
    return 0; 
}


A). The program will print the output 19 31.
B). The program will print the output 20 30.
C). The program will print the output 21 31.
D). The program will print the output 21 29.
E). Program will report compile time error.
Answer : Option C

Question 8 :

What will be the output of the following program?

#include < iostream . h > 
struct MyData
{
    public:
    int Addition(int a, int b = 10)
    {
        return (a *= b + 2);
    }
    float Addition(int a, float b);
};
int main()
{
    MyData data;
    cout<< data.Addition(1) <<" ";
    cout<< data.Addition(3, 4);
    return 0; 
}


A). 12 12
B). 12 18
C). 3 14
D). 18 12
E). Compilation fails.
Answer : Option B

Question 9 :

Which of the following statement is correct about the program given below?

#include < iostream . h >
int ParinamTest(int x, int y);
int ParinamTest(int x, int y, int z = 5);
int main()
{
    cout<< ParinamTest(2, 4) << endl; 
    return 0;
}
int ParinamTest(int x, int y)
{
    return x * y;
}
int ParinamTest(int x, int y, int z = 5)
{
    return x * y * z; 
}


A). The program will print the output 5.
B). The program will print the output 8.
C). The program will print the output 40.
D). The program will report compile time error.
Answer : Option D

Question 10 :

What will be the output of the following program?

#include < iostream . h > 
class IndiaParinamSample
{
    public:
        int   a; 
        float b;
        void ParinamFunction(int a, float b, float c = 100.0f)
        {
            cout<< a % 20 + c * --b;
        } 
}; 
int main()
{   IndiaParinamSample objParinam;
    objParinam.ParinamFunction(20, 2.000000f, 5.0f);
    return 0; 
}


A). 0
B). 5
C). 100
D). -5
E). None of these
Answer : Option B