Question

1.Which of the following is the correct code snippet for throwing a pair of 12-sided dice...

1.Which of the following is the correct code snippet for throwing a pair of 12-sided dice to get a sum of the numbers on two dice between 2 and 24 with different probabilities

2 * (rand() % 11 + 2)

rand() % 23 + 2

(rand() % 12) + (rand() % 12)

(rand() % 12 + 1) + (rand() % 12 + 1)

2.What would be the correct replacement for the following if () statement ?

if (0 > temperature > 212)

It is correct, no need to replace the statement.

if (0 > temperature && temperature > 212)

if (0 > temperature || temperature > 212)

if (0 > temperature and temperature > 212)

3.What, if anything, is syntactically wrong with the following function definition?

int sign(int x) 
{ 
   if (x < 0) 
      return -1;  
   else if (x > 0) 
      return 1;  
}

It should have a double argument, not an int.

If x == 0, neither return statement is executed.

The if() statement needs braces {}.

The code has no syntax errors.

4.What is calculated by the code snippet?

int n = 0;
int x;
while (cin >> x)
{
   if (x > n)
   {
      n = x;
   }
}

The average of the input values

The number of input values

The minimum value of all input values

The maximum value of all input values

0 0
Add a comment Improve this question Transcribed image text
Answer #1
1)  D.  (rand() % 12 + 1) + (rand() % 12 + 1)
2)  B.  if (0 > temperature && temperature > 212)
3)  If x == 0, neither return statement is executed.
4)  D.  The maximum value of all input values


Add a comment
Know the answer?
Add Answer to:
1.Which of the following is the correct code snippet for throwing a pair of 12-sided dice...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • QUESTION 1 What is the output of the following code snippet? int main() { bool attendance...

    QUESTION 1 What is the output of the following code snippet? int main() { bool attendance = false; string str = "Unknown"; attendance = !(attendance); if (!attendance) { str = "False"; } if (attendance) { attendance = false; } if (attendance) { str = "True"; } else { str = "Maybe"; } cout << str << endl; return 0; } False True Unknown Maybe QUESTION 2 What is the output of the following code snippet? #include <iostream> #include <string> using...

  • 31. The following code segment is syntactically correct:              int number{20};          cout << number <<...

    31. The following code segment is syntactically correct:              int number{20};          cout << number << setbase(16) << " " << number                               << setbase(10) << " " << number                                 << showpos << " " << number << endl;                 T__   F__       32. The following statement wants to determine if ‘count’ is outside the     range of 0 through 100:             if (count < 0 && count > 100)                                             T__   F__ 33. There is...

  • 12) 8 pts. Find the errors in the following code fragment and correct them. #i nclude...

    12) 8 pts. Find the errors in the following code fragment and correct them. #i nclude <iostream> using namespace std; double fudge (double s) f return s 2.3; int mainO cout >> "Your original estimate" double estimate; cin >> estimate; cout << endl; for (int 1 = 0;1c3;i++); cout << "EStimate' < fudge(estimate) <<endl Hint: There are 4 syntax errors. There is one error that is syntactically correct but causes the output to not be what you would expect. Once...

  • A random experiment consists of throwing two three-sided dice (show- ing the numbers 1, 2, 3). Let Y be the random variable which records the product of the pair of numbers showing on the dice. (i) Wr...

    A random experiment consists of throwing two three-sided dice (show- ing the numbers 1, 2, 3). Let Y be the random variable which records the product of the pair of numbers showing on the dice. (i) Write down the range RY of Y . (ii) Determine the probability distribution of Y . (iii) Calculate E(Y ) and V (Y ).

  • Consider the syntactically correct C code below, which is missing a function copy_positive. #include <stdio.h> /*...

    Consider the syntactically correct C code below, which is missing a function copy_positive. #include <stdio.h> /* copy_positive(A, Aout, size) * Given an array A, which will have the provided size, copy all positive * (non-negative/non-zero) elements of A into the provided output array Aout. * Return the size of the resulting array. */ /* (your code from below would be placed here) */ void print_array(int arr[], int n){ for( int i = 0; i < n; i++ ) printf("%d ",...

  • 1). What is the complexity of the following code snippet? { for (int count2 = 0;...

    1). What is the complexity of the following code snippet? { for (int count2 = 0; count2<n; count2++) { /*some sequence of O(1) step*/ } } select one: a. O(N^2) b. O(Log N) c. O(1) d. O(N!) 2). What is the complexity of the following code snippet? for (int count = 0; count<n; count++) { printsum(count) } select one: a. We need to know the complexity of the printsum() function. b. O(Log N) c. O(1) d. O(N) e. O(N^2) 3)....

  • What is the output of the following code snippet? (If there is some kind of syntax...

    What is the output of the following code snippet? (If there is some kind of syntax error indicate this by marking "error" in your answer choice) 1.        int fly = 5; int x;        if (fly-- > 5)               x = 5;        else               x = 2;        if (x++ > 3)               cout << x;        cout << fly << endl; 2.   int i = 0;        bool b = i == 0 || i++ > 0;        if (!b)               cout << i << endl;        else               cout...

  • find complexity Problem 1 Find out the computational complexity (Big-Oh notation) of the code snippet: Code...

    find complexity Problem 1 Find out the computational complexity (Big-Oh notation) of the code snippet: Code 1: for (int i = n; i > 0; i /= 2) { for (int j = 1; j < n; j *= 2) {     for (int k = 0; k < n; k += 2) {               // constant number of operations here     } } } Code 2: Hint: Lecture Note 5, Page 7-8 void f(int n) { if (n...

  • For Question 14 - 15, please refer to the following code snippet. 1 class Fitness 2...

    For Question 14 - 15, please refer to the following code snippet. 1 class Fitness 2 { 3 int Jumping; int Running; 12 }; 8 class Round ISAShape: public class Fitness 9 { 10 11 int Sleeping; int Eating; 13 }; 14. The following statements are TRUE based on the code snippet above, EXCEPT (A) class RoundISAShape is inheriting from class Fitness (B) class RoundISAShape is the base class for class Fitness (C) class Round ISAShape is considered as the...

  • Consider the following C++code snippet and what is the output of this program? # include<iostream> using...

    Consider the following C++code snippet and what is the output of this program? # include<iostream> using namespace std; void arraySome (int[), int, int); int main () const int arraysize = 10; int a[arraysize]-1,2,3,4,5, 6,7,8,9,10 cout << "The values in the array are:" << endl; arraySome (a, 0, arraySize) cout<< endl; system ("pause") return 0; void arraySome (int b[], int current, int size) if (current< size) arraySome (b, current+1, size); cout << b[current] <<""; a) Print the array values b) Double...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT