Examveda

What will be the output of the following C++ code?
#include <iostream>
using namespace std;
class Distance
{
    private:
    int feet;
    int inches;
    public:
    Distance()
    {
        feet = 0;
        inches = 0;
    }
    Distance(int f, int i) 
    {
        feet = f;
        inches = i;
    }
    Distance operator()(int a, int b, int c)
    {
        Distance D;
        D.feet = a + c + 10;
        D.inches = b + c + 100 ;
        return D;
    }
    void displayDistance()
    {
        cout  << feet <<  inches << endl;
    }
};
int main()
{
    Distance D1(11, 10), D2;
    cout << "First Distance : ";
    D1.displayDistance();
    D2 = D1(10, 10, 10);
    cout << "Second Distance :";
    D2.displayDistance();
    return 0;
}

A. First Distance : 1110
Second Distance :30120

B. First Distance : 110
Second Distance :3020

C. First Distance : 1115
Second Distance :30125

D. First Distance : 100
Second Distance :30120

Answer: Option A


Join The Discussion

Related Questions on Classes and Objects in C plus plus