首页 > 试题广场 >

阅读下列程序,写出运行结果: #include usi

[问答题]
阅读下列程序,写出运行结果:
#include <iostream>
using namespace std;
class Vector
{
public:
Vector(){ }
Vector(int i,int j)
  { x = i; y = j; }
friend Vector operator+ ( Vector v1, Vector v2 )
{
Vector tempVector;
tempVector.x = v1.x + v2.x;
tempVector.y = v1.y + v2.y;
return  tempVector;
}
void display()
 { cout << "( " << x << ", " << y << ") "<< endl; }
private:
int x, y;
};
int main()
{
Vector v1( 1, 2 ), v2( 3, 4 ), v3;
cout << "v1 = ";
v1.display();
cout << "v2 = ";
v2.display();
v3 = v1 + v2;
cout << "v3 = v1 + v2 = ";
v3.display();
}

推荐

v1 = ( 1, 2 )

v2 = ( 3, 4 )

v3 = v1 + v2 = ( 4, 6 )

发表于 2018-05-07 15:13:07 回复(0)