Question

In: Computer Science

C++ Questions What is the output of the following pseudocode code: ages = new List Append(ages,...

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.

Solutions

Expert Solution

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.


Related Solutions

write pseudocode for the following problems not c code Pseudocode only Write a C program to...
write pseudocode for the following problems not c code Pseudocode only Write a C program to print all natural numbers from 1 to n. - using while loop Write a C program to print all natural numbers in reverse (from n to 1). - using while loop Write a C program to print all alphabets from a to z. - using while loop Write a C program to print all even numbers between 1 to 100. - using while loop...
What is the output of the following C++ code? int* length; int* width; length = new...
What is the output of the following C++ code? int* length; int* width; length = new int; *length = 5; width = length; length = new int; *length = 2 * (*width); cout << *length << " " << *width << " " << (*length) * (*width) << endl;
What is the output from each of the following segments of C++ code? Record the output...
What is the output from each of the following segments of C++ code? Record the output after the “Answer” prompt at the end of each program fragment. Assume all variables have been suitably declared. (Each problem is worth 3 points.) 1. for (int j = 8; j > 3; j -= 2)         cout << setw(5) << j;     Answer:      2. int sum = 5;    for (int k = -4; k <= 1; k++)         sum = sum...
write the pseudocode and code to solve the following: you are given a list. determine the...
write the pseudocode and code to solve the following: you are given a list. determine the sum of all the elements in the list without using the built in puthon function sum(). Take your code and create your own function and name it my_sum_algo() which will return the sum of numbers PS please write comments in the code for my understanding, and please write jn jn PYTHON 3 languge. Thank you, have a great day !
a. What will be the output of LINE A in code “a” and output of code...
a. What will be the output of LINE A in code “a” and output of code “b”? Also write reasons for the outputs. a. #include <sys/types.h> #include <stdio.h> #include <unistd.h> int value = 3; int main() { pid_t pid; pid = fork(); if (pid = = 0) {/* child process */} value += 233; return 0; } else if (pid > 0) {/* parent process */} wait(NULL); printf(“PARENT: value = %d”, value); /* LINE A */ return 0; } }...
Using pseudocode or C++ code, write code to print “small” if the magnitude M of an...
Using pseudocode or C++ code, write code to print “small” if the magnitude M of an earthquake is in the range [0, 3), “medium” if M is in the range [3, 6), “large” if M is in the range [6, 9) and “epic” if M is greater than or equal to 9, where M is input by a user via the keyboard. (in c++)
All QUESTIONS, PLEASE 5.    What is the output of the following code: int product = 1,...
All QUESTIONS, PLEASE 5.    What is the output of the following code: int product = 1, i = 6; while (i < 9) {       product = product * i;       i++; } cout << “i is : ” << i << endl; cout << “product is : ” << product << endl; 6.    What is the output of the following code: int product = 1, i = 6;      do {       product = product * i;       i++;...
C++ program. Please explain how the code resulted in the output. The code and output is...
C++ program. Please explain how the code resulted in the output. The code and output is listed below. Code: #include <iostream> #include <string> using namespace std; int f(int& a, int b) {    int tmp = a;    a = b;    if (tmp == 0) { cout << tmp << ' ' << a << ' ' << b << endl; }    b = tmp;    return b;    return a; } int main() {    int a...
write JAVA code with the following condition Write the pseudocode for a new data type MyStack...
write JAVA code with the following condition Write the pseudocode for a new data type MyStack that implements a stack using the fact that you have access to a queue data structure with operations enqueue(), dequeue(), isEmpty(). Remember that every stack should have the operations push() and pop(). Hint: use two queues, one of which is the main one and one is temporary. Please note that you won’t be able to implement both push() and pop() in constant time. One...
What are the values in arrays a, b, and c after the following code executes (list...
What are the values in arrays a, b, and c after the following code executes (list all of the elements of the arrays)? double[] a = new double[4]; double[] b = {6,4,2}; a[a.length-1] = b[b.length-1]; double[] c = b; c[0] = -1; b[1] = c[2]; c = a; c[0] = -2; a[1] = c[3];
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT