Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I need some help. Trying to study. (10 Pts) Given the function definition below, what will the following code display? int num1 = 0, num2=1654893;

I need some help. Trying to study.

(10 Pts) Given the function definition below, what will the following code display? int num1 = 0, num2=1654893; cout << num1 << << num2 << endl; num1 = getLast(num2); cout << num1 << << num2 << endl; // program continues int getLast(int num2) { num2%=10; return num2; }

0 1654893

1 1654893

Syntax error. The function is trying to return num2 and put it into num1!

0 1654893

3 1654893

0 1654893

1654893 1654893

Flag this Question

Question 225 pts

(25Pts)Pick the best answer to accomplish the following task:

Write a function to accept a vector of ints and an int value, n. The function should double the value at location n in the vector, and then triple every value from n+1 to the end. There was code in main to ensure that n is less than the size of the vector.

void fixem(vector &V, int n) {

V[n]*=2;

for(int i=0,i

void fixem(vector &V, int n) {

V[n]*=2;

for(int i=n+1,i

void fixem(vector &V, int n) {

V[n]*=2;

for(int i=n+1,i

void fixem(vector V, int n) {

V[n]*=2;

for(int i=n+1,i

Flag this Question

Question 320 pts

(20 Pts) Given this struct struct quizzes { int Q1; int Q2; int Q3; double Average; }; Choose the best answer to accomplish this task:write a function which accepts a vector of structs and puts the average of the three quizzes in the Average field for each struct in the vector.

void averageQuiz(vector &V) { int count = 0; for(int i=0;i
void averageQuiz(vector &V) { int count = 0; for(int i=0;i
void averageQuiz(vector &V) { int count = 0; for(int i=0;i
void averageQuiz(vector V) { int count = 0; for(int i=0;i

Flag this Question

Question 420 pts

( 20 Pts) Select the best answer below:

Write a function which accepts a vector of strings and returns the average of the lengths of the strings.

double averageLength(const vector &V) { double average = 0; for(int i=0;i
double averageLength(const vector &V) { double average = 0; for(int i=0;i
double averageLength(const vector &V) { double average = 0; for(int i=0;i
double averageLength(const vector &V) { double average = 0; for(int i=0;i

Flag this Question

Question 510 pts

(10 Pts) The fastest search algorithm for vectors with a size greater than 50 is:

Linear Search

Linear Search with early exit
Binary Search

Shell Search

Quick Search

Flag this Question

Question 625 pts

(25 Pts)Choose the best answer:

Write a function to accept a vector of strings and a char and return a count of how many times the char appears in the vector

int countChar(const vector &V, char ch) { int count =0; for(int i=0;i
void countChar(const vector &V, char ch) { int count =0; for(int i=0;i
int countChar(const vector &V, char ch) { int count; for(int i=0;i
int countChar(const vector &V, char ch) { int count =0; for(int i=0;i

Flag this Question

Question 720 pts

(20 Pts) Choose the best solution (Analyze ALL the possible answers before choosing):

Write a bool function, areSame, to accept two vectors of ints and return true if the two vectors contain the same values in every cell. . The vectors are the same size. Efficiency counts!

bool areSame(const vector &V1, const vector &V2) { bool OK = true; int i=0; for(int i=0; i < V1.size());i++) { if(V1[i] != V2[i]) OK = false; } return OK; }
bool areSame(const vector &V1, const vector &V2) { bool OK = false; int i=0; while(OK && i < V1.size()) { if(V1[i] == V2[i]) i++; else OK = true; } return OK; }
bool areSame(const vector &V1, const vector &V2) { bool OK = true; int i=0; while(OK && i < V1.size()) { if(V1[i] == V2[i]) i++; else OK = false; } return OK; }
bool areSame(const vector &V1, const vector &V2) { bool OK; int i=0; for(int i=0; i < V1.size());i++) { if(V1[i] != V2[i]) OK = false; } else OK = false; return OK; }

Flag this Question

Question 825 pts

(25 Pts)Choose the best answer:

Write a function to accept a vector of ints and an empty vector of bools. For each value in the vector of ints which is even, it should set the corresponding cell in the vector of bools to true. All others should be false.

void AreOK(vector V1, vector V2) { for(int i=0;i

else V2.push_back(true); } }

void AreOK(const vector &V1, vector &V2) { if(V1 %2 ==1) V2=false;

else V2=true; } }

void AreOK(const vector &V1, vector &V2) { for(int i=0;i

else V2[i]=true; } }

void AreOK(const vector &V1, vector &V2) { for(int i=0;i

else V2.push_back(true); } }

Flag this Question

Question 920 pts

(20 Pts) Select the best solution:

Write a function that will accept an empty vector of ints and an int and will fill the vector with the ulam sequence beginning with the int. You may assume that the int is greater than 2.

vector &V;

int start)

cout << "Enter starting number" << endl; cin >> start; V.push_back(start);

while(start > 1) { if(start %2 ==0) start /=2; else start = start * 3 + 1; V.push_back(start);

void ulam(vector &V, int start)

{ V.push_back(start);

while(start > 1) { if(start %2 ==0) start /=2; else start = start * 3 + 1; V.push_back(start); }

}

void ulam(vector &V, int start)

{ for (i=start;i>1;i+=(i%2) { if(start %2 ==0) i /=2; else i = start * 3 + 1; V.push_back(i); }

}

void ulam(vector &V, int start)

{ V.push_back(start);

while(start > 1) { if(start %2 ==1) start /=2; else start = start * 3 + 1; V.push_back(start); }

}

Flag this Question

Question 1020 pts

(20 Pts) What will be the value of V[2] after this code runs?

vector V(3); for(int i = 0;i<3();i++) { V.push_back(i*2); }

3
6
0
That cell will be empty.

Flag this Question

Question 115 pts

(5 Pts) Choose the correct function below:

void goodbye() { cout << "I hope you enjoyed the class!" << endl; }

This is the wrong answer!
So is this!
No answer text provided.

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

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

EXPLAIN the strategic importance of technology in HRM.

Answered: 1 week ago

Question

7. Senior management supports the career system.

Answered: 1 week ago