[CPP] Chapter 2 Assessment
Due No due date
Points 28
Questions 28
Time Limit 40 Minutes
Allowed Attempts 2
Instructions
Welcome to chapter 2 assessment
This test will help you evaluate what you have learned in chapter 2. You will have 40 minutes to
answer 28 questions. You will not be able to see the correct answers. If you are not satisfied with
your result, you can re-take the test once. Good luck!
Attempt History
Attempt Time Score
KEPT Attempt 2 14 minutes 25 out of 28
, Attempt Time Score
LATEST Attempt 2 14 minutes 25 out of 28
Attempt 1 34 minutes 23.5 out of 28
Correct answers are hidden.
Score for this attempt: 25 out of 28
Submitted Dec 22 at 1:11pm
This attempt took 14 minutes.
Question 1
pts
What happens when you attempt to compile and run the following code? Choose all that apply.
#include <iostream>
#include <set>
#include <vector>
#include <functional>
using namespace std;
int main(){
int mynumbers[] = { 3, 9, 0, 2, 1, 4, 5 };
vector<int> v(mynumbers, mynumbers+7);
set<int> set1(v.begin(),v.end());
set<int, greater<int> > set2(v.begin(), v.end()); //LINE I
for(set<int, int>::iterator i=set2.begin();i!= set2.end(); i++)
cout<<*i<<" ";
for(set<int>::iterator i=set1.begin();i!= set1.end(); i++)
cout<<*i<<", ";
cout<<endl;
return 0;
}
program outputs: 9 5 4 3 2 1 0 0, 1, 2, 3, 4, 5, 9,
program outputs: 0 0 1 2 3 4 5 9, 1, 2, 3, 4, 5, 9,
compilation fails due to error in line I
code compiles and executes successfully
, program outputs: 9 5 4 3 2 1 0, 1, 2, 3, 4, 5, 9,
IncorrectQuestion 2
pts
What happens when you attempt to compile and run the following code? Choose all that apply.
#include <iostream>
#include <set>
#include <vector>
using namespace std;
int main(){
int mynumbers[] = { 3, 9, 0, 2, 1, 4, 5 };
vector<int> v(mynumbers, mynumbers+7);
set<int> s1(v.begin(),v.end());
s1.insert(v.begin(),v.end());
s1.insert(10);
s1.erase(s1.lower_bound(4),s1.upper_bound(6));
s1.insert(v.begin(),v.end());
for(set<int>::iterator i=s1.begin();i!= s1.end(); i++)
cout<<*i<<", ";
return 0;
}
the size of the s1 set is 7
program outputs: 0, 1, 2, 3, 4, 5, 9,
program outputs: 0, 1, 2, 3, 4, 5, 9, 10,
the size of the s1 set is 8
program outputs: 0, 1, 2, 3, 4, 5, 10,
Due No due date
Points 28
Questions 28
Time Limit 40 Minutes
Allowed Attempts 2
Instructions
Welcome to chapter 2 assessment
This test will help you evaluate what you have learned in chapter 2. You will have 40 minutes to
answer 28 questions. You will not be able to see the correct answers. If you are not satisfied with
your result, you can re-take the test once. Good luck!
Attempt History
Attempt Time Score
KEPT Attempt 2 14 minutes 25 out of 28
, Attempt Time Score
LATEST Attempt 2 14 minutes 25 out of 28
Attempt 1 34 minutes 23.5 out of 28
Correct answers are hidden.
Score for this attempt: 25 out of 28
Submitted Dec 22 at 1:11pm
This attempt took 14 minutes.
Question 1
pts
What happens when you attempt to compile and run the following code? Choose all that apply.
#include <iostream>
#include <set>
#include <vector>
#include <functional>
using namespace std;
int main(){
int mynumbers[] = { 3, 9, 0, 2, 1, 4, 5 };
vector<int> v(mynumbers, mynumbers+7);
set<int> set1(v.begin(),v.end());
set<int, greater<int> > set2(v.begin(), v.end()); //LINE I
for(set<int, int>::iterator i=set2.begin();i!= set2.end(); i++)
cout<<*i<<" ";
for(set<int>::iterator i=set1.begin();i!= set1.end(); i++)
cout<<*i<<", ";
cout<<endl;
return 0;
}
program outputs: 9 5 4 3 2 1 0 0, 1, 2, 3, 4, 5, 9,
program outputs: 0 0 1 2 3 4 5 9, 1, 2, 3, 4, 5, 9,
compilation fails due to error in line I
code compiles and executes successfully
, program outputs: 9 5 4 3 2 1 0, 1, 2, 3, 4, 5, 9,
IncorrectQuestion 2
pts
What happens when you attempt to compile and run the following code? Choose all that apply.
#include <iostream>
#include <set>
#include <vector>
using namespace std;
int main(){
int mynumbers[] = { 3, 9, 0, 2, 1, 4, 5 };
vector<int> v(mynumbers, mynumbers+7);
set<int> s1(v.begin(),v.end());
s1.insert(v.begin(),v.end());
s1.insert(10);
s1.erase(s1.lower_bound(4),s1.upper_bound(6));
s1.insert(v.begin(),v.end());
for(set<int>::iterator i=s1.begin();i!= s1.end(); i++)
cout<<*i<<", ";
return 0;
}
the size of the s1 set is 7
program outputs: 0, 1, 2, 3, 4, 5, 9,
program outputs: 0, 1, 2, 3, 4, 5, 9, 10,
the size of the s1 set is 8
program outputs: 0, 1, 2, 3, 4, 5, 10,