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

23. What is the output of the following code? int main() { int x = 10; int y = 3

ID: 3871427 • Letter: 2

Question

23.

What is the output of the following code?

int main() {

   int x = 10; int y = 30;

   if (x < 0) {

       y = 0;

   }

   else if (x < 10) {

       y = 10;

   }

   else {

       y = 20;

   }

   cout << y;

   return 0;

}

Select one:

a. 0

b. 10

c. 20

d. 300

24..

What is the output of the following code?

int main() {

   int i = 6;

   while (i > 2) {

       i = i - 2;

       cout << i << " ";

   }

   return 0;

}

Select one:

a. 4 2

b. 6 4 2

c. 6 4

d. 4 2 0

34...

Given the following, which line of code stores 40 into the 4th column of the 6th row of array dataVals?

const int rows = 7;
const int cols = 5;
int dataVals[rows][cols];

Select one:

a. dataVals[5, 3] = 40;

b. dataVals[5 * 3] = 40;

c. dataVals[3][5] = 40;

d. dataVals[5][3] = 40;

36..

What is the output of the following code?

int main() {

   string cityName = “La Jolla”;

   cout << cityName.length();

   return 0;

}

Select one:

a. 8

b. 9

c. 7

d. Cannot be determined.

38..

What is the output of the following code?

// before’s elements set to: 0, 4, 8, then 12

after.at(0) = before.at(0);

for(i = 1; i < before.size(); ++i) {

   tmp = before.at(i-1) + before.at(i);

   after.at(i) = tmp / 2;

   cout << after.at(i) << " ";

}

Select one:

a. 0 4 8 12

b. 4 8 12

c. 0 2 6 10

d. 2 6 10

39..   

What is a line of code?

Select one:

a. Used to denote a list of statements.

b. A row of text.

c. Represents a particular memory location.

d. Textual representation of a program.

40..

Which line of code will cause an error when added to the following program?

int main() {

   const int      numCtry=16;

   vector<string> ctryNames(numCtry);

   vector<int>    ctryMins(numCtry);

   // line of code here

   return 0;

}

Select one:

a. ctryNames.at(0) = ctryMins.at(0);

b. ctryNames = "Germany";

c. ctryNames.at(5) = ctryNames.at(0);

d. ctryMins.at(0) = 223;

Explanation / Answer

23.
What is the output of the following code?
int main() {
int x = 10; int y = 30;
if (x < 0) {
y = 0;
}
else if (x < 10) {
y = 10;
}
else {
y = 20;
}
cout << y;
return 0;
}
Answer: Option c. 20
Explanation:

Program:

#include <iostream>

using namespace std;

int main() {

int x = 10; int y = 30;

if (x < 0) { // Here 10 > 0 so this condition Fails

y = 0;

}

else if (x < 10) { //Here 10 < 10 so this condition also Fails

y = 10;

}

else {

y = 20; // Here above two conditions becomes false so the Final value of y becomes 20

}

cout << y; // Here we are Printing the value of y

return 0;

}

Output: 20

24..

What is the output of the following code?

int main() {

   int i = 6;

   while (i > 2) {

       i = i - 2;

       cout << i << " ";

   }

   return 0;

}

Answer: Option a. 4 2?

Explanation:

Program:

#include <iostream>

using namespace std;

int main() {

int i = 6;

while (i > 2) { // Here the condition 6>2 and 4>2 becomes True

i = i - 2; // Here the value of i becomes 4 and 2

cout << i << " "; // Here we are Printing the i values

}

return 0;

}

Output:

4 2

34...

Given the following, which line of code stores 40 into the 4th column of the 6th row of array dataVals?

const int rows = 7;
const int cols = 5;
int dataVals[rows][cols];

Answer: Option d. dataVals[5][3] = 40;

Explanation:

Program:

#include <iostream>

using namespace std;

int main() {

const int rows = 7;

const int cols = 5;

int dataVals[rows][cols];

dataVals[5][3] = 40;

cout<< dataVals[5][3] <<endl;

return 0;

}

Output: 40

36..

What is the output of the following code?

int main() {

   string cityName = “La Jolla”;

   cout << cityName.length();

   return 0;

}

Answer: Option a. 8?

Explanation:

Program:

#include <iostream>
using namespace std;
int main() {
string cityName = "La Jolla";
cout << cityName.length();
return 0;
}

Output: 8

38..

What is the output of the following code?

// before’s elements set to: 0, 4, 8, then 12

after.at(0) = before.at(0);

for(i = 1; i < before.size(); ++i) {

   tmp = before.at(i-1) + before.at(i);

   after.at(i) = tmp / 2;

   cout << after.at(i) << " ";

}

Answer: Option d. 2 6 10?

Explanation:

4/2 = 2
12/2 = 6
20/2 = 10

39..   
What is a line of code?

Answer: Option d. Textual representation of a program.?

40..

Which line of code will cause an error when added to the following program?

int main() {

   const int      numCtry=16;

   vector<string> ctryNames(numCtry);

   vector<int>    ctryMins(numCtry);

   // line of code here

   return 0;

}

Answer: Option a. ctryNames.at(0) = ctryMins.at(0);

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