Exercise: Functions

Questions for: Functions

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; 
}
A:
130
B:
A0
C:
B0
D:
90
Answer: B
No answer description is available. Let's discuss.
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; 
}
A:
30 10 20
B:
Garbage 10 20
C:
40 50 20
D:
20 40 50
Answer: C
No answer description is available. Let's discuss.
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; 
}
A:
Java Programming!
B:
C++ Programming!
C:
Learn C++ Programming!
D:
Learn Java Programming!
Answer: D
No answer description is available. Let's discuss.
What will be the output of the following program?
#include<iostream.h> 
struct BixArray
{
    int arr[5]; 
    public:
    void BixFunction();
    void Display();
};
void BixArray::BixFunction()
{
    static int i = 0, j = 4; 
    i++;
    j--;
    if(j > 0)
        BixFunction(); 
    int tmp = arr[i]; 
    arr[i]  = arr[j]; 
    arr[j]  = tmp; 
    i--;
    j++;
}
void BixArray::Display()
{
    for(int i = 0; i < 5; i++)
        cout<< arr[i] << " ";
} 
int main()
{
    BixArray objArr = {{5, 6, 3, 9, 0}};
    objArr.BixFunction();
    objArr.Display();
    return 0; 
}
A:
5 6 3 9 0
B:
0 9 3 6 5
C:
0 5 6 3 9
D:
0 6 3 9 5
Answer: D
No answer description is available. Let's discuss.
Which of the following statement is correct about the program given below?
#include<iostream.h> 
class ExamAdept
{
    int x; 
    float y; 
    public:
    ExamAdept(int x)
    {
        x = x;
    }
    ExamAdept(int p = 0, int q = 10)
    {
        x = p += 2; 
        y = q * 1.0f;
    }
    void SetValue(int &y, float z)
    {
        x = y;
        y = (int)z;
    }
    void Display(void)
    {
        cout<< x;
    }
};
int main()
{
    int val = 12; 
    ExamAdept objBix(val); 
    ExamAdept objTmp();
    objBix.SetValue(val, 3.14f); 
    objBix.Display(); 
    return 0; 
}
A:
The program will print the output 2.
B:
The program will print the output 12.
C:
The program will report run time error.
D:
The program will not compile successfully.
Answer: D
No answer description is available. Let's discuss.
Ad Slot (Above Pagination)
Quiz