Programs (Set - 2)

Question 6 :

What will be the output of the following program?

#include < iostream . h > 
class IndiaParinam
{
    int K; 
    public:
    void ParinamFunction(float, int , char);
    void ParinamFunction(float, char, char);
    
};
int main()
{
    IndiaParinam objIB;
    objIB.ParinamFunction(15.09, 'A', char('A' + 'A'));
    return 0;
}
void IndiaParinam::ParinamFunction(float, char y, char z)
{
    K = int(z);
    K = int(y);
    K = y + z;
    cout<< "K = " << K << endl; 
}


A). The program will print the output M = 130.
B). The program will print the output M = 195.
C). The program will print the output M = -21.
D). The program will print the output M = -61.
E). The program will report compile time error.
Answer : Option D

Question 7 :

What will be the output of the following program?

#include < iostream . h > 
class TestDrive
{
    int x; 
    public:
    TestDrive(int xx)
    {
        x = xx;
    }
    int DriveIt(void);
};
int TestDrive::DriveIt(void)
{
    static int value = 0;
    int m;
    m = x % 2;
    x = x / 2;
    if((x / 2)) DriveIt(); 
    value = value + m * 10; 
    return value;
}
int main()
{
    TestDrive TD(1234);
    cout<< TD.DriveIt() * 10 << endl;
    return 0; 
}


A). 300
B). 200
C). Garbage value
D). 400
Answer : Option D

Question 8 :

What will be the output of the following program?

#include < iostream . h > 
class IndiaParinam
{
    int Num; 
    public:
    IndiaParinam(int x)
    {
        Num = x;
    }
    int ParinamFunction(void);
};
int IndiaParinam::ParinamFunction(void)
{
    static int Sum = 0; 
    int Dec;
    Dec = Num % 10; 
    Num = Num / 10; 
    if((Num / 100)) ParinamFunction(); 
    Sum  = Sum * 10 + Dec; 
    return Sum;
}
int main()
{
    IndiaParinam objParinam(12345);
    cout<< objParinam.ParinamFunction();
    return 0; 
}


A). 123
B). 321
C). 345
D). 12345
E). 54321
Answer : Option C

Question 9 :

What is correct about the following program?

#include < iostream . h > 
class Addition
{
    int x; 
    public: 
    Addition()
    {
        x = 0;
    }       
    Addition(int xx)
    {
        x = xx;
    }
    Addition operator + (int xx = 0)
    {
        Addition objTemp; 
        objTemp.x = x + xx; 
        return(objTemp);
    }
    void Display(void)
    {
        cout<< x << endl;
    }
};
int main()
{
    Addition objA(15), objB;
    objB = objA + 5;
    objB.Display();
    return 0; 
}


A). The program will print the output 20.
B). The program will report run time error.
C). The program will print the garbage value.
D). Compilation fails due to 'operator +' cannot have default arguments.
Answer : Option D

Question 10 :

What will be the output of the following program?

#include < iostream . h > 
class AreaFinder
{
    float l, b, h; 
    float result; 
    public:
    AreaFinder(float hh = 0, float ll = 0, float bb = 0) 
    {
        l = ll; 
        b = bb; 
        h = hh;
    }
    void Display(int ll)
    {
        if(l = 0)
            result = 3.14f * h * h; 
        else
            result = l * b; 
        cout<< result; 
    }
};
int main()
{
    AreaFinder objAF(10, 10, 20);
    objAF.Display(0); 
    return 0; 
}


A). 0
B). 314
C). 314.0000
D). 200.0000
Answer : Option A