MidTerm_1D04_Post - Question 1 2 marks The following...

Info icon This preview shows pages 1–5. Sign up to view the full content.

View Full Document Right Arrow Icon
Page 1 of 16 Question 1. 2 marks The following statements are found in a C# program. What is the final value of z ? int z, q; z = 6; q = 20; z = z % q; q = q – z; z = z + q / 2; Answer 1. A. 13 B. 15 C. 20 D. 27 E. 28 Question 2. 2 marks What is the value of z at the end of this code segment? int i = 4; int z = 5; for (i = 3; i > 0; i--) { z += 5 + i * i; } Answer 2.
Image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Page 2 of 16 Question 3. 2 marks What is the purpose of implementing a method? Answer 3. Question 4. 2 marks How do you correctly subtract 1 from the variable a of type integer? Answer 4. Question 5. 2 marks What is purpose of having the type-casting in the example below ( nrElements and nSum are declared as integers, dAverage is declared as double)? dAverage = (double)nSum / nElements; Answer 5. A. There is no need for type-casting, the division result is always a double. B. To inform the compiler that the result should be a double we need to type-cast at least one element of the division. C. The type-casting allows avoiding execution errors in case nElements is 0. D. The type-casting should be performed as (double)(nSum / nElements); E. None of the above.
Image of page 2
Page 3 of 16 Question 6. 3 marks We have a text box called txtValue on our form. What is displayed in txtValue at the end of this code segment? int xyz = 0; for (int i = -1; i <= 1; i++) { xyz += i; } txtValue.Text = "Value is " + xyz; Answer 6. Question 7. 3 marks int i=0; int j=5; int k=1; for(i=1;i<5 && j > 3;i++) { j--; k++; } <----- At this point in code: 1. Value of i = 3 2. Value of j = 1 3. Value of k = 3 Answer 7.
Image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Page 4 of 16 Question 8. 3 marks string MethodExam (int a, int b) { int x = 0; if (a > x) return Convert.ToString(a) else return Convert.ToString(b) if (b > x) return Convert.ToString(b); else return Convert.ToString(a) } What will the above method return with parameters (0, -3)? Answer 8.
Image of page 4
Image of page 5
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern