{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

2011S2TestQuestions - CompSci 101 THE UNIVERSITY OF...

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

View Full Document Right Arrow Icon
CompSci 101 THE UNIVERSITY OF AUCKLAND SECOND SEMESTER, 2011 Campus: City COMPUTER SCIENCE TEST Principles of Programming (Time Allowed: 75 minutes) NOTE: You must answer all questions in this test. No calculators are permitted Answer in the spaces provided in this booklet. There is space at the back for answers that overflow the allotted space. Surname Forenames Student ID Login (UPI) Lab Time Q1 (/10) Q4 (/9) Q7 (/13) Q10 (/7) Q2 (/8) Q5 (/15) Q8 (/10) Total /100 Q3 (/10) Q6 (/6) Q9 (/12)
Image of page 1

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

View Full Document Right Arrow Icon
Question/Answer Sheet - Page 2 - CompSci 101 ID: ........................................................... continued Question 1 (10 marks) a) What output is produced when the following code is executed? System.out.println(4 + 3 * (5 / 3) + " * " + (4 - 3) + 1); (2 marks) b) Complete the output produced when the following code is executed. int a = 4; int b = a; a++; b = a; a = a - 2; b = 10 * a - b; System.out.println("a: " + a + " b: " + b); a: b: (2 marks)
Image of page 2
Question/Answer Sheet - Page 3 - CompSci 101 ID: ........................................................... continued c) Complete the output produced when the following code is executed. int a = 15; int b = 7; int c = a % a; int d = b % (b + 2); int e = a % b; int sum = c + d + e; System.out.println("Sum: " + sum); Sum: (2 marks) d) Complete the output produced when the following code is executed. double num1 = 27.6; int num2 = (int) num1; double num3 = 5 / 10; System.out.println("num2: " + num2); System.out.println("num3: " + num3); num2: num3: (2 marks)
Image of page 3

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

View Full Document Right Arrow Icon
Question/Answer Sheet - Page 4 - CompSci 101 ID: ........................................................... continued e) Complete the output produced when the following code is executed. int a = 3; int b = 12; int c = 6; int d = 1; System.out.println("1: " + (c + 2 * a)); System.out.println("2: " + (d - b / c)); 1: 2: (2 marks)
Image of page 4
Question/Answer Sheet - Page 5 - CompSci 101 ID: ........................................................... continued Question 2 (8 marks) Parts a), b) and c) refer to the following code. int value = ... if ((value < 10 || value > 30) && !(value == 0)) { System.out.println("A"); } else if (value > 15 && value < 25) { System.out.println("B"); } else if (value < 16) { System.out.println("C"); } else if (value > 25) { System.out.println("D"); } else { System.out.println("E"); } a) What is the output if the variable, value , is assigned 14? (2 marks) b) What is the output if the variable, value , is assigned 0? (2 marks) c) What is the output if the variable, value , is assigned 25? (2 marks)
Image of page 5

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

View Full Document Right Arrow Icon
Question/Answer Sheet - Page 6 - CompSci 101 ID: ........................................................... continued d) Write a boolean expression which tests whether the int variable, score , contains a value between 10 and 20 (both inclusive). (2 marks)
Image of page 6
Question/Answer Sheet - Page 7 - CompSci 101 ID: ........................................................... continued Question 3 (10 marks) a) The program below contains the display() method. In the start() method make a call to the display() method. Your call to the display() method can produce any output but it must compile.
Image of page 7

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

View Full Document Right Arrow Icon
Image of page 8
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