C++ Programming - Functions

Exercise : Functions - Programs
36.
What will be the output of the following program?
#include<iostream.h>
#include<string.h> 
class BixString
{
    char x[50]; 
    char y[50]; 
    char z[50]; 
    public:
    BixString()
    { }
    BixString(char* xx)
    {
        strcpy(x, xx); 
        strcpy(y, xx);
    }
    BixString(char *xx, char *yy = " C++", char *zz = " Programming!")
    {
        strcpy(z, xx); 
        strcat(z, yy); 
        strcat(z, zz);
    } 
    void Display(void)
    {
    cout<< z << endl;
    } 
}; 
int main()
{
    BixString objStr("Learn", " Java");
    objStr.Display();
    return 0; 
}
Java Programming!
C++ Programming!
Learn C++ Programming!
Learn Java Programming!
Learn Java C++ Programming!
Answer: Option
Explanation:
No answer description is available. Let's discuss.

37.
What will be the output of the following program?
#include<iostream.h> 
class BaseCounter
{
    protected:
    long int count;

    public:
    void CountIt(int x, int y = 10, int z = 20)
    {
        count = 0;
        cout<< x << " " << y << " " << z << endl;
    } 
    BaseCounter()
    {
        count = 0;
    }
    BaseCounter(int x)
    {
        count = x ;
    } 
}; 
class DerivedCounter: public BaseCounter
{
    public:
    DerivedCounter()
    { }
    DerivedCounter(int x): BaseCounter(x) 
    { }
};
int main()
{
    DerivedCounter objDC(30); 
    objDC.CountIt(40, 50); 
    return 0; 
}
30 10 20
Garbage 10 20
40 50 20
20 40 50
40 Garbage Garbage
Answer: Option
Explanation:
No answer description is available. Let's discuss.

38.
What will be the output of the following program?
#include<iostream.h> 
class Number
{
    int Num; 
    public:
    Number(int x = 0)
    {
        Num = x;
    }
    void Display(void)
    {
        cout<< Num;
    }
    void Modify(); 
};
void Number::Modify()
{
    int Dec;
    Dec = Num % 13; 
    Num = Num / 13; 
    
         if(Num  > 0 ) Modify()   ; 
         if(Dec == 10) cout<< "A" ; 
    else if(Dec == 11) cout<< "B" ; 
    else if(Dec == 12) cout<< "C" ; 
    else if(Dec == 13) cout<< "D" ;
    else               cout<< Dec ;
}
int main()
{
    Number objNum(130);
    objNum.Modify();
    return 0; 
}
130
A0
B0
90
Answer: Option
Explanation:
No answer description is available. Let's discuss.

39.
What will be the output of the following program?
#include<iostream.h> 
class Base
{
    int x, y; 
    public:
    Base() 
    {
        x = y = 0; 
    } 
    Base(int xx)
    {
        x = xx;
    }
    Base(int p, int q = 10)
    {
        x = p + q;
        y = q; 
    } 
    void Display(void)
    {
        cout<< x << " " << y << endl;
    } 
}objDefault(1, 1);

class Derived: public Base
{
    Base obj; 
    public:
    Derived(int xx, int yy): Base(xx, xx + 1)
    { }
    Derived(Base objB = objDefault)
    { } 
}; 
int main()
{
    Derived objD(5, 3);
    Derived *ptrD = new Derived(objD);
    ptrD->Display();
    delete ptrD;
    return 0; 
}
3 2
8 3
11 6
11 10
The program will not compile successfully.
Answer: Option
Explanation:
No answer description is available. Let's discuss.

40.
What is correct about the following program?
#include<iostream.h> 
class Base
{
    int x, y, z; 
    public: 
    Base()
    {
        x = y = z = 0;
    }
    Base(int xx, int yy = 'A', int zz = 'B')
    {
        x = xx;
        y = x + yy;
        z = x + y;
    }
    void Display(void)
    {
        cout<< x << " " << y << " " << z << endl;
    }
};
class Derived : public Base
{
    int x, y; 
    public:
    Derived(int xx = 65, int yy = 66) : Base(xx, yy)
    {
        y = xx; 
        x = yy;
    }
    void Display(void)
    {
        cout<< x << " " << y << " ";
        Display(); 
    }
};
int main()
{
    Derived objD;
    objD.Display();
    return 0; 
}
The program will report compilation error.
The program will run successfully giving the output 66 65.
The program will run successfully giving the output 65 66.
The program will run successfully giving the output 66 65 65 131 196.
The program will produce the output 66 65 infinite number of times (or till stack memory overflow).
Answer: Option
Explanation:
No answer description is available. Let's discuss.