Conversion Operators

1

Pick out the correct syntax of operator conversion.

A. operator float()const
B. operator float()const
C. operator const
D. None of the mentioned

2

How types are there in user defined conversion?

A. 1
B. 2
C. 3
D. 4

3

What is the output of this program?

1.
    #include 
2.
    using namespace std;
3.
    int main()
4.
    {
5.
        double a = 21.09399;
6.
        float b = 10.20;
7.
        int c ;
8.
        c = (int) a;
9.
        cout << c ;
10.
        c = (int) b;
11.
        cout << c ;
12.
        return 0;
13.
    }
A. 2110
B. 1210
C. 21
D. None of the mentioned

4

What is the output of this program?

1.
    #include 
2.
    #include 
3.
    using namespace std;
4.
    class test
5.
    {
6.
        public:
7.
        operator string ()
8.
        {  
9.
            return "Converted";
10.
        }
11.
    };
12.
    int main()
13.
    {
14.
        test t;
15.
        string s = t;
16.
        cout << s << endl;
17.
        return 0;
18.
    }
A. converted
B. error
C. run time error
D. None of the mentioned

5

What is the output of this program?

1.
    #include 
2.
    #include 
3.
    using namespace std;
4.
    class Complex
5.
    {
6.
        private:
7.
        double real;
8.
        double imag;
9.
        public:
10.
        Complex(double r = 0.0, double i = 0.0) : real(r), imag(i)
11.
        {}
12.
        double mag()
13.
        {  
14.
            return getMag();
15.
        }
16.
        operator double ()
17.
        {
18.
            return getMag();
19.
        }
20.
        private:
21.
        double getMag()
22.
        {
23.
            return sqrt(real * real + imag * imag);
24.
        }
25.
    };
26.
    int main()
27.
    {
28.
        Complex com(3.0, 4.0);
29.
        cout << com.mag();
30.
        cout << com;
31.
        return 0
32.
    }
A. 5 5
B. 4 5
C. 6 6
D. None of the mentioned