Written by students who passed Immediately available after payment Read online or as PDF Wrong document? Swap it for free 4.6 TrustPilot
logo-home
Exam (elaborations)

Advanced programming

Rating
-
Sold
-
Pages
259
Grade
A+
Uploaded on
20-10-2023
Written in
2023/2024

Advanced programming CHAPTER 1 24.5 out of 30 Question 1 What will happen when you attempt to compile and run the following code? #include vector #include iostream int main () { std::vectorint v1; // LINE I _back(10); // LINE II std::cout()":"()std::endl; // LINE III return 0; } code compiles and executes successfully Question 2 Which statement is true about the code below? #include vector #include iostream using namespace std; int main () { vectorint v1(4, 3); _back(4); for(vectorint::iterator i = n(); i != (); ++i) { cout *i " "; } cout endl; return 0;

Show more Read less
Institution
Course

Content preview

Advanced programming

CHAPTER 1 24.5 out of 30
Question 1

What will happen when you attempt to compile and run the following code?

#include <vector>
#include <iostream>

int main ()
{
std::vector<int> v1; // LINE I
v1.push_back(10); // LINE II
std::cout<<v1.front()<<":"<<v1.back()<<std::endl; // LINE III
return 0;
}




code compiles and executes successfully
Question 2

Which statement is true about the code below?

#include <vector>
#include <iostream>
using namespace std;
int main ()
{
vector<int> v1(4, 3);
v1.push_back(4);
for(vector<int>::iterator i = v1.rbegin(); i != v1.rend(); ++i)
{
cout << *i << " ";
}
cout<< endl;
return 0;
}




program will not compile


Question 3

Which sentences are 100% true about the code below (multiple choice) when control reaches return.
Choose all that apply.

,#include <vector>
#include <iostream>

using namespace std;

int main ()
{
vector<int> v1(10, -1);
vector<int> v2;
v2.reserve(10);
for(unsigned i=0; i < 10; i++)
{
v2.push_back(i);
}
return 0;
}




size of vector v2 less than 20

both vectors v1 and v2 have the same capacity



value returned by size() is the same for vectors v1 and v2


Question 4
Which sentence is 100% true about the code below when control reaches return?

#include <vector>
#include <iostream>
#include <stdexcept>

using namespace std;

int main ()
{
int tab[]={1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
vector<int> v1(tab, tab+10);
vector<int> v2(v1.size(), 0);
try
{
for(unsigned i=0; i<=v1.size(); ++i)
{
int tmp = v1[i]; // LINE I
v1[i] = v1.at(v1.size()-i); // LINE II
v1.at(i) = tmp; // LINE III
cout<<v1[i] << " ";
}
}
catch(...)
{

, cout<<"Exception!"<<endl;
}

return 0;
}




program will run and print output: Exception!



Question 5
What will happen when you attempt to compile and run the following code?

#include <deque>
#include <iostream>

using namespace std;

template<typename T> ostream & print(T & start, T & end)
{
for(; start != end; ++start)
{
cout<< *start<< " ";
}
return cout;
}

int main()
{
int tab[]={1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
deque<int> d1(tab, tab+10);
deque<int> d2;
deque<int>::iterator it;
for(it = d1.begin(); it != d1.end(); ++it)
{
d2.push_back(d1[d1.end()-it-1]); //LINE I
}
print(d2.rbegin(), d2.rend()) << endl; //LINE II
return 0;
}


code will not compile due to error in line LINE II /mali
the result of program execution is unpredictable or there might be runtime exception /MALI

Question 6

What will happen when you attempt to compile and run the following code?

, #include <deque>
#include <iostream>

using namespace std;

template<typename T> ostream & print(T const & start, T const & end)
{
for (T i = start; i != end; ++i)
{
cout << *i << " ";
}
return cout;
}

int main()
{
int tab[]={1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
deque<int> d1(tab, tab+10);

deque<int>::const_iterator it = d1.begin()+3;
d1.erase(it, it + 1);
print(d1.begin(), d1.end());
d1.clear();
cout<<d1.size()<<endl;
return 0;
}




program will run successfully and display: 1 2 3 5 6 7 8 9 10 0
Question 7

Which methods from the std::deque class can be used to check if there are elements in
the container? Choose all that apply.
MALI
1. Empty,SIZE, CLEAR(0.5POINTS)
2. THERE IS NO SUCH METHOD
3. EMPTY SIZE CLEAR IS EMPTY

Question 8

What will happen when you attempt to compile and run the following code?

#include <deque>
#include <iostream>

using namespace std;

Written for

Course

Document information

Uploaded on
October 20, 2023
Number of pages
259
Written in
2023/2024
Type
Exam (elaborations)
Contains
Questions & answers

Subjects

$17.99
Get access to the full document:

Wrong document? Swap it for free Within 14 days of purchase and before downloading, you can choose a different document. You can simply spend the amount again.
Written by students who passed
Immediately available after payment
Read online or as PDF

Get to know the seller

Seller avatar
Reputation scores are based on the amount of documents a seller has sold for a fee and the reviews they have received for those documents. There are three levels: Bronze, Silver and Gold. The better the reputation, the more your can rely on the quality of the sellers work.
ACADEMICAIDSTORE Chamberlain College Of Nursing
Follow You need to be logged in order to follow users or courses
Sold
1211
Member since
4 year
Number of followers
892
Documents
12012
Last sold
1 week ago
ACADEMICAID STORE

Welcome to ACADEMICAID store! We specialize in reliable test banks, exam questions with verified answers, practice exams, study guides, and complete exam review materials to help students pass on the first try. Our uploads support Nursing programs, professional certifications, business courses, accounting classes, and college-level exams. All documents are well-organized, accurate, exam-focused, and easy to follow, making them ideal for quizzes, midterms, finals, ATI &amp; HESI prep, NCLEX-style practice, certification exams, and last-minute reviews. If you’re looking for trusted test banks, comprehensive exam prep, and time-saving study resources, you’re in the right place.

Read more Read less
4.1

176 reviews

5
98
4
29
3
28
2
6
1
15

Recently viewed by you

Why students choose Stuvia

Created by fellow students, verified by reviews

Quality you can trust: written by students who passed their tests and reviewed by others who've used these notes.

Didn't get what you expected? Choose another document

No worries! You can instantly pick a different document that better fits what you're looking for.

Pay as you like, start learning right away

No subscription, no commitments. Pay the way you're used to via credit card and download your PDF document instantly.

Student with book image

“Bought, downloaded, and aced it. It really can be that simple.”

Alisha Student

Working on your references?

Create accurate citations in APA, MLA and Harvard with our free citation generator.

Working on your references?

Frequently asked questions