In: Computer Science
QUESTION 60
Given the following Product structure:
struct Product {
string name;
double price;
int quantity;
bool equals(const Product&);
};
how would you define the equals function so two products are equal
if their names and prices are equal?
a. |
bool equals(const Product& to_compare) { |
|
b. |
bool Product::equals(const Product& to_compare)
{ |
|
c. |
bool equals(const Product& to_compare) { |
|
d. |
bool Product::equals(const Product& to_compare)
{ |
1.5 points
QUESTION 61
What are the values of the keys in the set named years after the
following code is executed?
set<int> years { 2016, 1985, 2001 };
years.insert(1992);
years.insert(2001);
auto iter = years.find(1985);
if (iter != years.end()) {
years.erase(iter);
}
a. |
2016, 2001, 1992 |
|
b. |
1992, 2001, 2016 |
|
c. |
2016, 2001, 2001, 1992 |
|
d. |
1992, 2001, 2001, 2016 |
1.5 points
QUESTION 62
The capacity of a vector indicates
a. |
the number of elements it can currently store |
|
b. |
the current size of the vector in bytes |
|
c. |
the largest number of elements it can store |
|
d. |
the number of elements it contains |
1.5 points
QUESTION 63
Which of the following is not a limitation of an array when compared with a vector?
a. |
An array can’t increase its size automatically. |
|
b. |
The size of an array must be known at compile time. |
|
c. |
An array doesn’t use memory as efficiently as a vector. |
|
d. |
An array doesn’t provide functions that let you modify its elements. |
1.5 points
QUESTION 64
A stack container provides
a. |
last-in, first-out access |
|
b. |
first-in, last-out access |
|
c. |
last-in, last out access |
|
d. |
first-in, first-out access |
1.5 points
QUESTION 65
Code Example 9-2
struct Phone {
int area_code;
int prefix;
int number;
};
struct Contact {
string name;
string email;
Phone phone;
};
(Refer to Code Example 9-2.) Given a Contact object named contact, what code would you use to assign values to the the data members of the Phone object for that contact?
a. |
contact.phone.area_code = 555; |
|
b. |
Phone phone; |
|
c. |
Phone phone; |
|
d. |
Phone phone; |
1.5 points
QUESTION 66
What is the easiest way to deploy a C++ program to a user’s computer?
a. |
Copy the executable file to the user’s computer |
|
b. |
Create a batch file that copies the program to the user’s computer and then run it |
|
c. |
Create an installer program and then run it on the user’s computer |
|
d. |
Copy the source code to the user’s computer and then compile it |
1.5 points
QUESTION 67
Which of the following statements is not true about structures?
a. |
They include data members that must be fundamental data types. |
|
b. |
They can include member functions that operate on the data members. |
|
c. |
They define a data type. |
|
d. |
They are typically used to organize related data. |
1.5 points
QUESTION 68
When you dereference an iterator, you get the value of the element that the iterator points to
True
False
1 points
QUESTION 69
A stack container provides last-in, first-out access
True
False
1 points
QUESTION 70
A deque container is a fixed-size collection of elements that’s stored in contiguous memory
True
False
60. a. bool equals(const Product& to_compare)
{
return (name == to_compare.name && price
== to_compare.price);
}
This function will return true only if both the names and prices of products are equal.
61. b. 1992, 2001, 2016
The elements of set are in sorted order and no duplicate elements are allowed in set. So the order will be 1992, 2001 and 2016. Here 1985 is erased. Duplicate of 2001 is not allowed here.
62. c. the largest number of elements it can store
The capacity of a vector indicates the largest number of elements it can store.
63. d. An array doesn’t provide functions that let you modify its elements.
The array provide functions that let you modify its elements. It is not a limitation
64. a. last-in, first-out access
A stack container provides last-in, first-out access.
65. b.
Phone phone;
contact.phone.area_code = 555;
contact.phone.prefix = 555;
contact.number = 1212;
we need to create a phone object first and then assign the valuesto the the data members of the Phone object.
66. a. Copy the executable file to the user’s computer
The easiest way to deploy a C++ program to a user’s computer? Copy the executable file to the user’s computer.
67. a. They include data members that must be fundamental data types.
They include data members that can both fundamental data types and also the derived data types.
68. True
When you dereference an iterator, you get the value of the element that the iterator points to.
69. True
A stack container provides last-in, first-out access
70. False
A deque container is not fixed-size collection of elements. There is no guarantee of contiguous storage allocation in dequeues.