Home » C++ Programming » Questions and Answers » Question
  1. What is the output of this program?
    #include <iostream>
    using namespace std;
    class vectorClass
    {
    public:
    vectorClass(float float1, float float2)
    {
    p = float1;
    q = float2;
    }
    vectorClass()
    {
    }
    float p;
    float q;
    };
    vectorClass addvectors(vectorClass vect1, vectorClass vect2);
    int main()
    {
    vectorClass vect1(4, 7);
    vectorClass vect2(5, -3);
    vectorClass vect3 = addvectors(vect1, vect2);
    cout << vect3.p << ", " << vect3.p << endl;
    }
    vectorClass addvectors(vectorClass vect1, vectorClass vect2)
    {
    vectorClass result;
    result.p = vect1.p + vect2.p;
    result.q = vect1.q + vect2.q;
    return result;
    };
    1. 9
    2. Compilation Error
    3. 9, 9
    4. Runtime Error
    5. None of these
Correct Option: C

In this program, We are adding two vectors by using standalone function and printing it.



Your comments will be displayed only after manual approval.