What will be the output of the following C++ code?#include using namespace std;class vec{public:vec(float f1, float f2) {x = f1;y = f2;}vec(){}float x;float y;};vec addvectors(vec v1, vec v2);int main() {vec v1(3, 6);vec v2(2, -2);vec v3 = addvectors(v1, v2);cout

🎲 Try a Random Question  |  Total Questions in Quiz: 112  |  🧠 Study this quiz with Flashcards
This question is part of a full practice quiz:
C++ Programming Practice Test: Strings, Streams & Numerics in C++ — practice the complete quiz, review flashcards, or try a random question.

C++ quiz on basic strings and their characters, I/O streams, file and string streams, standard library and mathematical applications like numeric limits, file handling, vector arithmetic and random numbers. Strings: A string in C++ is a sequence of characters. It is a data type that is used to store text. Strings are declared using the string keyword.  Strings can be concatenated using the + operator.  Strings can be compared using the ==, !=, , = operators.  Streams: A stream in C++ is a sequence of characters that can be read from or written to. Streams are used to input and output... Show more

What will be the output of the following C++ code?<br>#include <iostream><br>using namespace std;<br>class vec<br>{<br>public:<br>vec(float f1, float f2) <br>{<br>x = f1;<br>y = f2;<br>}<br>vec()<br>{<br>}<br>float x;<br>float y;<br>};<br>vec addvectors(vec v1, vec v2);<br>int main() <br>{<br>vec v1(3, 6);<br>vec v2(2, -2);<br>vec v3 = addvectors(v1, v2);<br>cout << v3.x << ", " << v3.y << endl;<br>}<br>vec addvectors(vec v1, vec v2)<br>{<br>vec result;<br>result.x = v1.x + v2.x;<br>result.y = v1.y + v2.y;<br>return result;<br>};