In: Computer Science
C++ Questions
What is the output of the following pseudocode code:
ages = new List
Append(ages, 55)
Append(ages, 88)
Append(ages, 66)
Print(ages)
A. |
55, 66, 88 |
|
B. |
55, 88, 66 |
|
C. |
55, because there is no loop |
|
D. |
66, because there is no loop |
|
E. |
None of the above. |
QUESTION 2
Type the list after the given operations. Each question starts with an empty list. Type the list as: 5, 7, 9
Append(list, 3)
Append(list, 2)
Append(list, 1)
Remove(list, 3)
A. |
3, 2 |
|
B. |
2, 1 |
|
C. |
1, 2 |
|
D. |
2, 3 |
|
E. |
None of the above. |
QUESTION 3
Assume 11 element list alist contains the characters in the string "mathematics". What is the sequence of elements after executing the instructions?
list<char> alist;
list<char>::iterator iter;
iter = alist.begin();
iter++;
alist.erase(iter++);
iter++;
alist.erase(iter);
alist.pop_front();
A. |
m a t h e m a t |
|
B. |
a t h e m a t i |
|
C. |
m t e a t i c s |
|
D. |
t e m a t i c s |
|
E. |
None of the above. |
QUESTION 4
Given a list with nodes 'Z', 'A', 'B', Sort(list) yields 'A', 'B', 'Z'.
A. |
True |
|
B. |
False |
|
C. |
Lists can not be sorted |
|
D. |
Not enough information whether it is ascending or descending. |
|
E. |
None of the above. |
QUESTION 5
Assume the declaration:
string weekName[] = {"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat");
const int DAYSINWEEK = 7;
list<string>::iterator strIterA, strIterB;
After executing the following instructions, strIterA is the location of day _______.
strIterA = weekList.end();
strIterA--;
strIterA--;
A. |
Mon |
|
B. |
Wed |
|
C. |
Fri |
|
D. |
Tues |
|
E. |
None of the above. |
Please follow the data and description :
a)
Given, pseudocode as
ages = new List
Append(ages, 55)
Append(ages, 88)
Append(ages, 66)
Print(ages)
Here the data is appended to the list so the data in the list is given as 55, 88, 66.
So the answer is OPTION B(55, 88, 66).
b)
After the given operations we have the resultant list as
Append(list, 3)
Append(list, 2)
Append(list, 1)
Remove(list, 3)
2,1
So the answer is OPTION B(2,1).
c)
After the given operations we have the resultant list as
list<char> alist;
list<char>::iterator iter;
iter = alist.begin();
iter++;
alist.erase(iter++);
iter++;
alist.erase(iter);
alist.pop_front();
t e m a t i c s
So the answer is OPTION D (t e m a t i c s).
d)
Given a list with nodes 'Z', 'A', 'B', Sort(list) yields 'A', 'B', 'Z'.
We can't use std::sort to sort std::list, because std::sort requires iterators to be random access, and std::list iterators are only bidirectional.
So the answer is OPTION C(Lists can not be sorted).
e)
From the code we could see that the list named weekList is not present. So the answer is OPTION E (None of the Above).
Hope this is helpful.