This set of C++ Programming Multiple Choice Questions & Answers (MCQs) focuses on “Vector Arithmetic”.
1. Which of the following library is used to do vector arithmetic?
a) Boost
b) Time
c) OpenGL
d) OpenDL
View Answer
Explanation: Boost package has a linear algebra package that may well suits for vector arithmetic.
2. Which header file is used to manipulate the vector algebra in c++?
a) math
b) cmath
c) vmath
d) dmath
View Answer
Explanation: vmath is set of C++ classes for Vector and Matrix algebra used in the programs.
3. What type of reference should be used in vector arithmetic?
a) dynamic
b) const
c) both dynamic & const
d) static
View Answer
Explanation: As we are using the vector and it will give accurate result if we use const reference.
4. What will be the output of the following C++ code?
#include <iostream>
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 << v3.x << ", " << v3.y << endl;
}
vec addvectors(vec v1, vec v2)
{
vec result;
result.x = v1.x + v2.x;
result.y = v1.y + v2.y;
return result;
};
a) 4, 5
b) 4, 4
c) 5, 4
d) 5, 5
View Answer
Explanation: In this program, We are adding two vectors by using standalone function and printing it.
Output:
$ g++ vecar.cpp $ a.out 5, 4
5. What will be the output of the following C++ code?
#include <iostream>
#include <vector>
using namespace std;
int main ()
{
vector<bool> mask;
mask.push_back(true);
mask.flip();
cout << boolalpha;
for (unsigned i = 0; i < mask.size(); i++)
cout << mask.at(i);
return 0;
}
a) false
b) true
c) false & true
d) alpha
View Answer
Explanation: In this program, We are flipping the vector values by using flip function.
Output:
$ g++ vecar1.cpp $ a.out false
6. What will be the type of output of vector cross product?
a) Scalar
b) Vector
c) Both Scalar & Vector
d) Linear
View Answer
Explanation: Cross product of two vectors results into a vector.
7. Which function is used to optimize the space in vector?
a) at
b) bool
c) operator
d) operand
View Answer
Explanation: This is a specialized version of vector, which is used for elements of type bool and optimizes for space.
8. What is the use of vector arithmetic in c++?
a) Computer graphics
b) Computer booting
c) Both Computer graphics & Computer booting
d) Computer Networks
View Answer
Explanation: Computer graphics is the use of vector arithmetic in c++.
Sanfoundry Global Education & Learning Series – C++ Programming Language.
To practice all areas of C++ language, here is complete set of 1000+ Multiple Choice Questions and Answers.
- Practice Programming MCQs
- Check Computer Science Books
- Apply for Computer Science Internship
- Check C++ Books
- Check Programming Books