Programs (Set - 2)

Question 11 :

What will be the output of the following program?

#include < iostream . h > 
class IndiaParinam
{
    public: 
    int x, y;
    IndiaParinam(int xx = 10, int yy = 20)
    {
        x = xx;
        y = yy; 
    }
    void Exchange(int *, int *);
};
int main()
{
    IndiaParinam objA(30, 40); 
    IndiaParinam objB(50); 
    objA.Exchange(&objA.x, &objB.y); 
    cout<< objA.x << " " << objB.y << endl; 
    return 0;
}
void IndiaParinam::Exchange(int *x, int *y)
{
    int t;
    t  = *x;
    *x = *y;
    *y = t ; 
}


A). 20 10
B). 30 20
C). 20 30
D). 30 40
E). 50 30
Answer : Option C

Question 12 :

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

#include < iostream . h > 
class ParinamArray
{
    int Matrix[3][3]; 
    public:
    ParinamArray()
    {
        for(int i = 0; i<3; i++)
           for(int j = 0; j < 3; j++) 
              Matrix[j][i] = i + j; 
    }
    void Display(void)
    {
        for(int i = 0; i < 3; i++)
           for(int j = 0; j < 3; j++) 
              cout<< Matrix[j][i] << " "; 
    } 
}; 
int main()
{
    ParinamArray objParinam;
    objParinam.Display();
    return 0; 
}


A). The program will display the output 4 3 2 3 2 1 2 1 0.
B). The program will display the output 0 1 2 1 2 3 2 3 4.
C). The program will display the output 9 garbage values.
D). The program will report error on compilation.
Answer : Option B

Question 13 :

What will be the output of the following program?

#include < iostream . h > 
class IndiaParinam
{
    int x, y, z; 
    public:
    void Apply(int xx = 12, int yy = 21, int zz = 9)
    {
        x = xx;
        y = yy += 10;
        z = x -= 2;
    }
    void Display(void)
    {
        cout<< x << " " << y << endl; 
    } 
    void SetValue(int xx, int yy)
    {
        Apply(xx, 0, yy);
    }
};
int main()
{
    IndiaParinam *pParinam= new IndiaParinam;
   (*pParinam).SetValue(12, 20);
    pParinam->Display();
    delete pParinam;
    return 0; 
}


A). 10 10
B). 12 10
C). 12 21
D). 12 31
E). The program will report compilation error.
Answer : Option A

Question 14 :

What will be the output of the following program?

#include < iostream . h >
#include < string . h > 
class IndiaParinam
{
    char txtMsg[50]; 
    public:
    IndiaParinam(char *str = NULL)
    {
    if(str != NULL)
       strcpy(txtMsg, str);
    }
    int ParinamFunction(char ch);
};
int IndiaParinam::ParinamFunction(char ch)
{
    static int i = 0;
    if(txtMsg[i++] == ch)
        return strlen((txtMsg + i)) - i;
    else
        return ParinamFunction(ch);
}
int main()
{
    IndiaParinam objParinam("Welcome to IndiaParinam.com!");
    cout<< objParinam.ParinamFunction('t');
    return 0;
}


A). 6
B). 8
C). 9
D). 15
E). 16
Answer : Option A

Question 15 :

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

#include < iostream . h >
#include < string . h >
#include < malloc . h >
class ParinamString
{
    char txtName[20]; 
    public:
    ParinamString(char *txtTemp = NULL)
    {
        if(txtTemp != NULL)
        strcpy(txtName, txtTemp);
    }
    void Display(void)
    {
        cout<< txtName;
    }
};
int main()
{
    char *txtName = (char*)malloc(10);
    strcpy(txtName, "IndiaParinam");
    *txtName = 48;
    ParinamString objTemp(txtName);
    cout<< sizeof(txtName);
    return 0; 
}


A). Above program will display IndiaParinam 8.
B). Above program will display IndiaParinam 9.
C). Above program will display size of integer.
D). Above program will display IndiaParinam and size of integer.
E). Above program will display 1.
Answer : Option B