01. First declare double vector with name vecLane: Fill vecLane with 0.1, 0.2, 0
ID: 3821816 • Letter: 0
Question
01. First declare double vector with name vecLane: Fill vecLane with 0.1, 0.2, 0.3, 0.4, 0.5: Then write the statement to find the ending location of vecLane and assign it to iterator pos: Then move back iterator pos one position: Then retrieve the item in the above iterator and output it to the screen:
02. What is the output of the following? deque d; for (int i = 25; i < 30; i++) { if (i % 2 != 0) d.push_front(i); else d.push_back(i); } while (!d.empty() ) { cout << d.back(); d.pop_back(); }
03.What is the output of the following program segment? vector intVector; vector::iterator vecIt; intVector.push_back(3); intVector.push_back(5); intVector.push_back(7); vecIt = intVector.begin( ); vecIt++; intVector.erase(vecIt); intVector.push_back(9); for(int i = 0; i < intVector.size(); i++) cout << intVector[i];
04. What is the ouput of the following function F, for the call int i = F(3)? int F(int n) { int result; if (n > 20) return 1; else { result = F(2*n) * 2; cout << result << " "; return result; } }
05. int Wow (int n, int m) { if (m ==1) return n; if ( n == m) return 1; return Wow(n - 1, m - 1) + Wow (n - 1 , m); } What will Wow(5 , 2) return?
Explanation / Answer
#include<iostream>
#include<vector>
using namespace std;
int main(void)
{
vector<double> vecLane;
vecLane.push_back(0.1);
vecLane.push_back(0.2);
vecLane.push_back(0.3);
vecLane.push_back(0.4);
vecLane.push_back(0.5);
//pointing to end of the vector and move in reverse direction
vector<double>::reverse_iterator it=vecLane.rbegin();
it++;
cout<<*it;
return 0;
}
--------------------------------------------------------
Ans-2) output is 28 26 25 27 29
There was problem in dqueue declaration
it shuold be deque<int> d;
-------------------------------------------------------------
Ans-3) output: 3 7 9
There was problem in vector declaration
it shuold be vector<int> intVector;
vector<int>::iterator vecIt
--------------------------------------------------------------
Ans-4) output: 2 4 8 8
------------------------------------------------------------
Ans-5) output: 10
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.