Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

c++ 1. Which statement initializes (allocates) a pointer to point to a memory ad

ID: 3603873 • Letter: C

Question

c++

1.

Which statement initializes (allocates) a pointer to point to a memory address in the heap?

int* p;

2.

Here is a function declaration:

Suppose that a is an int* variable pointing to some integer, and *a is equal to zero. What is printed if you cout << a; after the function call goo(a)?

The address of x

3.

Suppose bag is a template class, what is the syntax for declaring a bag b of doubles?

bag<double> b;

4.

Consider the following bag class:

Which steps would be necessary for changing this bag class to hold double values instead of integers?

PreviousNext

5.

With a single template class, we can implement a container class that can be instantiated with a different data type for each object.

False

6.

When you write a template class, where does the template prefix occur? (Select all that apply)

Before the template class definition

7.

Consider this prototype for a template function:

Something is wrong with this prototype. Which line has the error?

line 2

8.

The address of p1

9.

What is wrong with this block of code?

PreviousNext

10.

Consider the following bag class:

What is data? (Select the most likely answer)

A pointer to an object of the Standard Template Library class

A pointer to an vector that holds int values

An integer variable

11.

What kind of a container is an object of type list from the Standard Template Library?

Associative

12.

What does the following code block do?

This code block declares a vector of integers and an iterator for a vector of integers. The iterator called iter is set to point to the smallest element in the vector and that value is displayed.

13.

What is the delete keyword used for?

To delete the value stored in the heap pointed to by a pointer

14.

Which of the following declarations is legal (will not generate an error)?

int *q;

15.

Which keyword can be used to allow a non-member function to see the private variables of another class?

overload

16.

Consider the following main function:

What is necessary in the Time class to make this main function compile?

A friend function called t is needed.

17.

In which of the following ways can you write an operator overload? (Select all that apply)

in a friend function

18.

What is printed by these statements?

3

19.

Suppose cursor is a pointer that points to a penguin node in a linked list using a penguin class that includes a member function get_link(). You wish to move cursor to point to the next node (to the next penguin) in the list. Which statement do you use?

cursor.get_link();

20.

Suppose cursor points to a penguin node in a linked list using a penguin class, which includes functions called get_data() and get_link(). What Boolean expression should be true when that penguin node is the ONLY node in the list?

cursor == NULL

21.

The following steps have been performed for deleting a node from a linked list. The nodes have the member accessor function get_link(). The head_ptr points to the head node of a list.
Step 1: Set up a local variable called remove_ptr and set it equal to head_ptr
Step 2: Set head_ptr equal to the head_ptr->get_link()
Step 3: Delete remove_ptr
Which of the following situations should use these steps?

To delete a node from the middle (neither front nor end) of a list.

22.

Which operation is better for storing items in an array than storing items on a linked list?

Growing the size of the container.

23.

You are working with a node class named node. Suppose that f is a non-member function with a prototype like this with a missing data type in the parameter list:
void f(________ head_ptr);
// Precondition: head_ptr is a head pointer for a linked list.
// Postcondition: The function f has done some computation with
// the linked list, but the list itself is unchanged.
What is the best data type for head_ptr in the parameter list of this function?

node&

24.

A virtual function provides you with the ability to have several different functions with the same name in a parent and children classes and have C++ figure out which one to call at run-time.

False

25.

Suppose cursor points to a node in a linked list (using the node definition with member functions called get_data and get_link). What Boolean expression will be true when cursor points to the tail node (last node) of the list?

cursor->get_data( ) == NULL

26.

Consider the following class:

How could you create an object of this class (Select all that apply)?

hourlyEmp arnold("Arnold Jones","23456664",13,20);

27.

Which of the following is a pure abstract function?

28.

A programming language is required to provide which things in order for it to be considered an object oriented programming language?

inheritance

29.

Consider the following:

What is the output of this program?

Error. Ambiguous reference.

30.

Consider the following:

What is the output of this program?

This is derived1's vfunc().
This is derived1's vfunc().

31.

You wish to convert a container class to a template container class. Which of the following should you consider?

Make sure all return statements that return container data only return container data. If a return statement returns container data under certain conditions, but another return statement returns something that is not container data under other conditions, there could be a data type conflict when a different data type is used for this template.

32.

Which of the following is a container class in the Standard Template Library? (Select all that apply)

list

33.

Consider the following code.

string str1(3, 'a');

cout << str1 << endl;

string str2(str1);

cout << str2 << endl;

string str3("hello", 2);

cout << str3 << endl;

string str5 = "How are you?";
string str6(str5, 4, 3);

cout << str6 << endl;

Assuming that this code has the using namespace std directive and the appropriate #include statements, what would you expect the output to be?

aaa

aa
he
are

he

aaa
aaa
aaa

aaa

aa
he
are

aaa

aaa
he
are

int *p = new int;

Explanation / Answer

1.Answer) int *p = new int;

2.Answer) The address of a

3.Answer) bag<double> b;

4.Answer) Change the int to double for the array and for all return values and parameters related to the array, then recompile.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote