Exercise: Python

Questions for: Functions

What will be the output of the following program?
#include<iostream.h> 
class ExamAdept
{
    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()
{
    ExamAdept *pBix= new ExamAdept;
   (*pBix).SetValue(12, 20);
    pBix->Display();
    delete pBix;
    return 0; 
}
A:
10 10
B:
12 10
C:
12 21
D:
12 31
Answer: A
No answer description is available. Let's discuss.
Which of the following statement is correct about the program given below?
#include<iostream.h> 
class BixArray
{
    int Matrix[3][3]; 
    public:
    BixArray()
    {
        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()
{
    BixArray objBix;
    objBix.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: B
No answer description is available. Let's discuss.
What will be the output of the following program?
#include<iostream.h> 
class ExamAdept
{
    public: 
    int x, y;
    ExamAdept(int xx = 10, int yy = 20)
    {
        x = xx;
        y = yy; 
    }
    void Exchange(int *, int *);
};
int main()
{
    ExamAdept objA(30, 40); 
    ExamAdept objB(50); 
    objA.Exchange(&objA.x, &objB.y); 
    cout<< objA.x << " " << objB.y << endl; 
    return 0;
}
void ExamAdept::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
Answer: C
No answer description is available. Let's discuss.
What will be the output of the following program?
#include<iostream.h> 
class AreaFinder
{
    float l, b, h; 
    float result; 
    public:
    AreaFinder(float hh = 0, float ll = 0, float bb = 0) 
    {
        l = ll; 
        b = bb; 
        h = hh;
    }
    void Display(int ll)
    {
        if(l = 0)
            result = 3.14f * h * h; 
        else
            result = l * b; 
        cout<< result; 
    }
};
int main()
{
    AreaFinder objAF(10, 10, 20);
    objAF.Display(0); 
    return 0; 
}
A:
0
B:
314
C:
314.0000
D:
200.0000
Answer: A
No answer description is available. Let's discuss.
What is correct about the following program?
#include<iostream.h> 
class Addition
{
    int x; 
    public: 
    Addition()
    {
        x = 0;
    }       
    Addition(int xx)
    {
        x = xx;
    }
    Addition operator + (int xx = 0)
    {
        Addition objTemp; 
        objTemp.x = x + xx; 
        return(objTemp);
    }
    void Display(void)
    {
        cout<< x << endl;
    }
};
int main()
{
    Addition objA(15), objB;
    objB = objA + 5;
    objB.Display();
    return 0; 
}
A:
The program will print the output 20.
B:
The program will report run time error.
C:
The program will print the garbage value.
D:
Compilation fails due to 'operator +' cannot have default arguments.
Answer: D
No answer description is available. Let's discuss.
Ad Slot (Above Pagination)
Quiz