Programs

Question 1 :

What will be the output of the following program?

#include < iostream . h > 
class Parinam
{
    public:
      int x;
};
int main()
{
    Parinam *p = new Parinam();

    (*p).x = 10;
    cout<< (*p).x << " " << p->x << " " ;

    p->x = 20;
    cout<< (*p).x << " " << p->x ;

    return 0;
}


A). 10 10 20 20
B). Garbage garbage 20 20
C). 10 10 Garbage garbage
D). Garbage garbage Garbage garbage
Answer : Option A

Question 2 :

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

#include < iostream . h > 
class IndiaParinam
{
    static int x; 
    public:
    static void SetData(int xx)
    {
        x = xx; 
    }
    void Display() 
    {
        cout<< x ;
    }
};
int IndiaParinam::x = 0; 
int main()
{
    IndiaParinam::SetData(33);
    IndiaParinam::Display();
    return 0; 
}


A). The program will print the output 0.
B). The program will print the output 33.
C). The program will print the output Garbage.
D). The program will report compile time error.
Answer : Option D

Question 3 :

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

#include < iostream . h > 
class IndiaParinam
{
    static int x; 
    public:
    static void SetData(int xx)
    {
        x = xx; 
    }
    static void Display() 
    {
        cout<< x ;
    }
};
int IndiaParinam::x = 0; 
int main()
{
    IndiaParinam::SetData(44);
    IndiaParinam::Display();
    return 0; 
}


A). The program will print the output 0.
B). The program will print the output 44.
C). The program will print the output Garbage.
D). The program will report compile time error.
Answer : Option B

Question 4 :

What will be the output of the following program?

#include < iostream . h > 
class ParinamTeam
{
    int x, y; 
    public:
    ParinamTeam(int xx)
    {
        x = ++xx;
    }
    void Display()
    {
        cout<< --x << " ";
    }
};
int main()
{
    ParinamTeam objBT(45);
    objBT.Display();
    int *p = (int*)&objBT;
    *p = 23;
    objBT.Display();
    return 0; 
}


A). 45 22
B). 46 22
C). 45 23
D). 46 23
Answer : Option A

Question 5 :

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

#include < iostream . h > 
class IndiaParinam
{
    static int x; 
    public:
    static void SetData(int xx)
    {
        this->x = xx; 
    }
    static void Display() 
    {
        cout<< x ;
    }
};
int IndiaParinam::x = 0; 
int main()
{
    IndiaParinam::SetData(22);
    IndiaParinam::Display();
    return 0; 
}


A). The program will print the output 0.
B). The program will print the output 22.
C). The program will print the output Garbage.
D). The program will report compile time error.
Answer : Option D

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

Question 11 :

What will be the output of the following program?

#include < iostream . h > 
class IndiaParinam
{
    static int count; 
    public:
    static void First(void)
    {
        count = 10;
    }
    static void Second(int x)
    {
        count = count + x; 
    }
    static void Display(void)
    {
        cout<< count << endl;
    } 
};
int IndiaParinam::count = 0; 
int main()
{
    IndiaParinam :: First();
    IndiaParinam :: Second(5);
    IndiaParinam :: Display();
    return 0; 
}


A). 0
B). 5
C). 10
D). 15
E). The program will report compile time error.
Answer : Option D

Question 12 :

What will be the output of the following program?

#include < iostream . h > 
class ParinamBase
{
    public:
        float x; 
}; 
class ParinamDerived : public ParinamBase
{
    public: 
        char ch; 
        void Process()
        {
            ch = (int)((x=12.0)/3.0);
        }
        void Display()
        {
            cout<< (int)ch;
        } 
}; 
int main()
{
    class ParinamDerived  *objDev = new ParinamDerived;
    objDev->Process();
    objDev->Display();
    return 0; 
}


A). The program will print the output 4.
B). The program will print the ASCII value of 4.
C). The program will print the output 0.
D). The program will print the output garbage.
Answer : Option A

Question 13 :

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

#include < iostream . h >
#include < process . h > 
class IndiaParinam
{
    static int x; 
    public:
    IndiaParinam()
    {
        if(x == 1)
            exit(0); 
        else
            x++;
    }
    void Display()
    {
        cout<< x << " ";
    }
};
int IndiaParinam::x = 0; 
int main()
{
    IndiaParinam objParinam1; 
    objParinam1.Display(); 
    IndiaParinam objParinam2; 
    objParinam2.Display(); 
    return 0; 
}


A). The program will print the output 1 2.
B). The program will print the output 0 1.
C). The program will print the output 1 1.
D). The program will print the output 1.
E). The program will report compile time error.
Answer : Option D

Question 14 :

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

#include < iostream . h > 
class ParinamBase
{
    int x, y; 
    public:
    ParinamBase(int xx = 10, int yy = 10)
    {
        x = xx;
        y = yy;
    }
    void Show()
    {
        cout<< x * y << endl;
    }
};
class ParinamDerived
{
    private:
        ParinamBase objBase; 
    public:
    ParinamDerived(int xx, int yy) : objBase(xx, yy)
    {
        objBase.Show();
    }
};
int main()
{
    ParinamDerived objDev(10, 20);
    return 0; 
}


A). The program will print the output 100.
B). The program will print the output 200.
C). The program will print the output Garbage-value.
D). The program will report compile time error.
Answer : Option B

Question 15 :

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

#include < iostream . h > 
class ParinamBase
{
    int x, y; 
    public:
    ParinamBase(int xx = 10, int yy = 10)
    {
        x = xx;
        y = yy;
    }
    void Show()
    {
        cout<< x * y << endl;
    }
};
class ParinamDerived : public ParinamBase
{
    private:
        ParinamBase objBase; 
    public:
    ParinamDerived(int xx, int yy) : ParinamBase(xx, yy)
    {
        objBase.Show();
    }
};
int main()
{
    ParinamDerived objDev(10, 20);
    return 0; 
}


A). The program will print the output 100.
B). The program will print the output 200.
C). The program will print the output Garbage-value.
D). The program will report compile time error.
Answer : Option A

Question 16 :

What will be the output of the following program?

#include < iostream . h > 
class A
{
    public:
    void ParinamFunction(void)
    {
        cout<< "Class A" << endl;
    }
};
class B: public A
{
    public:
    void ParinamFunction(void)
    {
        cout<< "Class B" << endl;
    } 
};
class C : public B
{
    public:
    void ParinamFunction(void)
    {
        cout<< "Class C" << endl;
    } 
};
int main()
{
    A *ptr;
    B objB;
    ptr = &objB;
    ptr = new C();
    ptr->ParinamFunction();
    return 0; 
}


A). Class A.
B). Class B.
C). Class C.
D). The program will report compile time error.
Answer : Option A

Question 17 :

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

#include < iostream . h > 
class ParinamBase
{
    int x, y; 
    public:
    ParinamBase(int xx = 10, int yy = 10)
    {
        x = xx;
        y = yy;
    }
    void Show()
    {
        cout<< x * y << endl;
    }
};
class ParinamDerived : public ParinamBase
{
    private:
        ParinamBase objBase; 
    public:
    ParinamDerived(int xx, int yy) : ParinamBase(xx, yy), objBase(yy, yy)
    {
        objBase.Show();
    }
};
int main()
{
    ParinamDerived objDev(10, 20);
    return 0; 
}


A). The program will print the output 100.
B). The program will print the output 200.
C). The program will print the output 400.
D). The program will print the output Garbage-value.
E). The program will report compile time error.
Answer : Option C

Question 18 :

What will be the output of the following program?

#include < iostream . h > 
class Point
{
    int x, y; 
    public:
    Point(int xx = 10, int yy = 20)
    {
        x = xx;
        y = yy; 
    }
    Point operator + (Point objPoint)
    {
        Point objTmp;
        objTmp.x = objPoint.x + this->x; 
        objTmp.y = objPoint.y + this->y;
        return objTmp;
    }
    void Display(void)
    {
        cout<< x << " " << y;
    }
};
int main()
{
    Point objP1;
    Point objP2(1, 2);
    Point objP3 = objP1 + objP2;
    objP3.Display(); 
    return 0; 
}


A). 1 2
B). 10 20
C). 11 22
D). Garbage Garbage
E). The program will report compile time error.
Answer : Option C

Question 19 :

What will be the output of the following program?

#include < iostream . h >
#include < string . h > 
class IndiaParinam
{
    char str[50]; 
    char tmp[50]; 
    public:
    IndiaParinam(char *s)
    {
        strcpy(str, s);
    }
    int ParinamFunction()
    {
        int i = 0, j = 0; 
        while(*(str + i))
        {
            if(*(str + i++) == ' ')
                *(tmp + j++) = *(str + i);
        }
        *(tmp + j) = 0; 
        return strlen(tmp); 
    }
};
int main()
{
    char txt[] = "Welcome to IndiaParinam.com!";
    IndiaParinam objParinam(txt); 
    cout<< objParinam.ParinamFunction();
    return 0;
}


A). 1
B). 2
C). 24
D). 25
Answer : Option B