Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

-Order the code for the class. Put the private section before the public section. - 1. 2. 3. 4. 5. 6. }; - 1. 2.

-Order the code for the class. Put the private section beforethe public section.

- 1. 2. 3. 4. 5. 6.

};

- 1. 2. 3. 4. 5. 6.

Person() { name=""; middle_initial=' '; birth_year=1990; }

- 1. 2. 3. 4. 5. 6.

class Person {

- 1. 2. 3. 4. 5. 6.

private:

- 1. 2. 3. 4. 5. 6.

string name; char middle_initial; int birth_year;

- 1. 2. 3. 4. 5. 6.

public:

-Using the STL (standard template library), the best (fastest) way to find the smallest number in an unsorted array (or vector) is to: 1) sort the numberts from smallest to largest 2) return element at [0]

True

False

-Fill in the missing parts to the definition and instance below. When complete, the code should compile.

---------------Person { ----------------first_name, last_name; enum type {male, female} gender; }; -------------banjo_maker; banjo_maker.first_name="Tom"; banjo_maker.last_name="Nechville"; banjo_maker.--------=-----------------; // assign the last, unused data member

-Several sorting algorithms were discussed in class and in the textbook. Which of the following are names of sorting algorithms? (Select all that apply).

bubble sort

searching sort

quantum sort

quick sort

selection sort

binary sort

-To use a-------------- instead of an array, you must use the compiler directive #< > then you can use container.---------(item) to append a new item at the end of the container. (Use a single term for each blank with no punctuation.)

-Why would you want to use a binary search instead of linear search?

Binary search is more complex than linear search.

Binary search is faster than linear search in most cases, but will be slower if the target is not found.

Binary search only has to look at half the elements in the array, making it twice as fast as linear search.

Binary search usually finds the target much faster than linear search, provided the array is sorted.

-It is preferred to delay constructing an object until after all the data required to construct the object is available.

True

False

-Select all the things that are the SAME for both a struct and a class.

can have setters and getters

can have constructors and destructors

is a programmer-defined data type

by convention, the name is capitalized

can use dot notation to access members

-The following O() functions represent the speed / performance / complexity of an algorithm. Order the following performance functions from fastestto slowest, where fastest is the fewest number of programming steps, and slowest is the most programming steps.

- 1. 2. 3. 4. 5. 6.

O(n^n)

- 1. 2. 3. 4. 5. 6.

O(n*n)

- 1. 2. 3. 4. 5. 6.

O(k)

- 1. 2. 3. 4. 5. 6.

O(log n)

- 1. 2. 3. 4. 5. 6.

O(n)

- 1. 2. 3. 4. 5. 6.

O(n log n)

-Below is C++ code that defines an array and loads it with some data. Select the C++ code equivalent(s) necessary for doing this with a vector.

char vowels[5]; vowels[0]='a'; vowels[1]='e'; vowels[2]='i'; vowels[3]='o'; vowels[4]='u';

#include

vector vowels {'a', 'e', 'i', 'o', 'u'};

vector vowels {"aeiou"};

vector vowels {" aeiou"};

vector vowels[5]; vowels[0]='a'; vowels[1]='e'; vowels[2]='i'; vowels[3]='o'; vowels[4]='u';

-Match the two related items.

- A. B. C. D.

string months[12];

- A. B. C. D.

#include

- A. B. C. D.

#include

- A. B. C. D.

log n

A.

binary search

B.

setw(8)

C.

sort()

D.

vector months(12);

-Select valid C++ code that performs a linear search on an array and returns the location where the target was found. If the target was not found, it returns a location one past the last valid location.

bool find(float array[], int size, float target) { for (int i=0; i if (array[i] == target) return true; return false; }

int find(float array[], unsigned short size, float target) { for (unsigned short i=0; i if (array[i] == target) return i; return target; }

None of these

int find(float array[], unsigned short size, float target) { unsigned short i=0; for (; i if (array[i] == target) break; return i; }

int find(float array[], unsigned short size, float target) { for (unsigned short i=0; i if (array[i] == target) break; return i; }

-Which of these is a declaration for an array called prices that holds 25 floating-point values?

int prices[25];

array[25] float-point prices;

float[25] prices;

prices float[25];

float prices[25];

-What is the order O( ) of linear search?

O(n log n)

O(n ^ 2) Clarification: The meaning of n ^ 2 is n-squared, or n * n

O(1)

O(log n)

O(n)

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started