Programs

Question 6 :

What will be the output of the following program?

#include < iostream . h > 
class India
{
    public:
    struct Parinam
    {
        int   x;
        float y;
        void Function(void)
        {
            y = x = (x = 4*4); 
            y = --y * y;
        }
        void Display()
        {
            cout<< y << endl;
        } 
    }B; 
}I; 
int main()
{
    I.B.Display(); 
    return 0;
}


A). 0
B). 1
C). -1
D). Garbage value
Answer : Option A

Question 7 :

What will be the output of the following program?

#include < iostream . h >
#include < string . h > 
class IndiaParinam
{
    int val; 
    public:
    void SetValue(char *str1, char *str2)
    {
        val = strcspn(str1, str2);
    }
    void ShowValue()
    {
        cout<< val;
    } 
};
int main() 
{
    IndiaParinam objParinam;
    objParinam.SetValue((char*)"India", (char*)"Parinam"); 
    objParinam.ShowValue(); 
    return 0; 
}


A). 2
B). 3
C). 5
D). 8
Answer : Option B

Question 8 :

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

#include < iostream . h >
#include < string . h > 
class IndiaParinam
{
    public:
    void GetData(char *s, int x, int y )
    {
        int i = 0;
        for (i = x-1; y>0; i++)
        {
            cout<< s[i];
            y--; 
        } 
    }
}; 
int main()
{
    IndiaParinam objParinam;
    objParinam.GetData((char*)"Welcome!", 1, 3);
    return 0; 
}


A). The program will print the output me!.
B). The program will print the output Wel.
C). The program will print the output !em.
D). The program will print the output Welcome!.
E). The program will result in a compile time error.
Answer : Option B

Question 9 :

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

#include < iostream . h > 
class ParinamData
{
    int x, y, z; 
    public:
    ParinamData(int xx, int yy, int zz)
    {
        x = ++xx;
        y = ++yy;
        z = ++zz;
    }
    void Show()
    {
        cout<< "" << x++ << " " << y++ << " " << z++;
    } 
}; 
int main()
{
    ParinamData objData(1, 2, 3);
    objData.Show();
    return 0; 
}


A). The program will print the output 1 2 3.
B). The program will print the output 2 3 4 .
C). The program will print the output 4 5 6.
D). The program will report compile time error.
Answer : Option B

Question 10 :

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

#include < iostream . h > 
class IndiaParinam
{
    int x; 
    float y; 
    public:
    void Function()
    {
        x = 4; 
        y = 2.50; delete this;
    }
    void Display()
    {
        cout<< x << " " << y;
    } 
}; 
int main()
{
    IndiaParinam *pParinam = new IndiaParinam();
    pParinam->Function(); 
    pParinam->Function(); 
    pParinam->Display(); 
    return 0; 
}


A). The program will print the output 4 2.5.
B). The program will print the output 4.
C). The program will report runtime error.
D). The program will report compile time error.
Answer : Option C