Tutorial 14
Ques 1. Implement different operations on a vector A.
1. x (Adds an element x to the vector A at the end)
2. (Sorts the vector A in ascending order)
3. (Reverses the vector A)
4. (prints the size of the vector)
5. (prints space separated values of the vector)
6. (Sorts the vector A in descending order)
Ques 2. What is true about his statement in C++?
std::vector<int> vecInts(5);
(A) Initialize a Vector with 5 int & all default value is 0
(B) Initialize a Vector with 5 int
(C) Initialize a Vector with 5 int & all default values will be garbage
(D) Initialize a Vector with 5 int & All default value with be -1
Ques 3.
What does this function do?
void func() {
std::vector<std::string> vecOfString(5, "Hi");
for (std::string str : vecOfStr)
std::cout << str << std::endl;
}
(A) Initialize vect to 5 string with value "Hi"
(B) Initialize vect's first element to a string with value "Hi" & prints them
(C) Initialize vect to 1 string with value "Hi" & prints only one
(D) Initialize vect to 5 string with value "Hi" & prints them
Ques 4. Implement a class in C++ that behaves just like the Vector class.
It should include the following functions:
1)Push(data)
2)Push(data,index)
3)Get(index)
4)Pop()
5)Size()
6)GetCapacity()
7)Print()