Write a C++ class Vect for modeling two-dimensional vectors. Your class, when combined with the following main driver an
Posted: Sat May 14, 2022 7:02 pm
Write a C++ class Vect for
modeling two-dimensional vectors. Your class, when combined with
the following main driver and executed, should produce
the example output shown.
Math information:
int main()
{
Vect x,y(30,40),z;
cin >> x;
z=x+y;
cout << "Vector x = " << x;
cout << "Vector y = " << y;
cout << "Vector sum x+y = " << z;
cout << "Dot product x*y = " << x*y
<< endl;
x*=5.0;
cout << "Vector x after scalar multiplying by
5 = " << x;
if(x==y)
cout << "Vectors x and y
are equal\n";
else
cout << "Vectors x and y
are not equal\n";
return 0;
}
NOTE:
1. Vect class should ONLY use necessary member variables
that represent a vector, ONLY provide the declaration and
definition of constructors and operators used in the main
function.
2. When operators are natural members of the class, they
SHOULD be overloaded as member operators.
Enter vector <i,j>: <6,8>
Vector x = <6,8>
Vector y = <30,40>
Vector sum x+y = <36,48>
Dot product x*y = 500
Vector x after scalar multiplying by 5 = <30,40>
Vectors x and y are equal
--------------------------------
Process exited after 6.373 seconds with return value 0
Press any key to continue . . .
modeling two-dimensional vectors. Your class, when combined with
the following main driver and executed, should produce
the example output shown.
Math information:
int main()
{
Vect x,y(30,40),z;
cin >> x;
z=x+y;
cout << "Vector x = " << x;
cout << "Vector y = " << y;
cout << "Vector sum x+y = " << z;
cout << "Dot product x*y = " << x*y
<< endl;
x*=5.0;
cout << "Vector x after scalar multiplying by
5 = " << x;
if(x==y)
cout << "Vectors x and y
are equal\n";
else
cout << "Vectors x and y
are not equal\n";
return 0;
}
NOTE:
1. Vect class should ONLY use necessary member variables
that represent a vector, ONLY provide the declaration and
definition of constructors and operators used in the main
function.
2. When operators are natural members of the class, they
SHOULD be overloaded as member operators.
Enter vector <i,j>: <6,8>
Vector x = <6,8>
Vector y = <30,40>
Vector sum x+y = <36,48>
Dot product x*y = 500
Vector x after scalar multiplying by 5 = <30,40>
Vectors x and y are equal
--------------------------------
Process exited after 6.373 seconds with return value 0
Press any key to continue . . .