You are on page 1of 10

QUEEN MARY, UNIVERSITY OF LONDON

BSC IN THE FACULTY OF ENGINEERING AND MATHEMATICAL SCIENCES


Student No.:________________ DCS UserId (computer login) :________________ __________________

MODULE: ECS401: PROCEDURAL PROGRAMMING AUTUMN 2008 MID TERM TEST


Time allowed: 55 minutes. Answer ALL of the (multi-part) question There are two questions made of several parts on this test paper. Marks for each question part are indicated below each question part. The paper is worth 25 marks, though the marks are given only for feedback and to help you plan timing on this test. The mark for the first (theory) question (1a,1b) are combined and converted to a distinct A-F grade. The mark for the final (programming) question part (2) is also converted to a distinct A-F grade. Each count separately towards your coursework grade. Answer the questions in accordance with the instructions given with each question
[Should your answer not fit in the space provided, you may continue on the reverse of the page provided that you indicate clearly the question number/part to which your answer relates]. For examiners use only Question 1a+1b Question 2 Mark Grade Mark Grade /15 /10 14-15 A+ 9-10 A+ 12-13 A 7-8 A 10-11 B 6 B 8-9 C 5 C 6-7 D 4 D 3-5 F 2-3 F 0-2 FM 0-1 FM Page 1 of 10 ECS401 Mid term Test Autumn 2008

Question 1 [15 marks] a) i) Explain what a compiler does.


[3 Marks]

ii) Explain what is meant by a boolean expression and where they are used.
[3 Marks]

. Illustrate your answers with appropriate examples.


[Total Marks for Part 1a: 6 marks]

Answer to question 1a i):

Question 1 continues overleaf. Page 2 of 10 ECS401 Mid term Test Autumn 2008

Answer to question 1a ii):

Question 1 continues overleaf. Page 3 of 10 ECS401 Mid term Test Autumn 2008

1b) Give the value printed out after each fragment of code in the question sub-parts below is executed. Justify your answers. i)
String z = A; String x = B; x = x + z; z = z + x; System.out.println(z); [2 Marks]

Answer to question 1b i): Justification:

Question 1b continues overleaf. Page 4 of 10 ECS401 Mid term Test Autumn 2008

ii)
int y = 0; int x = 2; if(x>5) {y = 10;} else if (x>=2) {y = 15;} else if (x == 2) {y = 20;} else {y = 25;} System.out.println(y); [2 Marks]

Answer to question 1b ii): Justification:

Question 1b continues overleaf. Page 5 of 10 ECS401 Mid term Test Autumn 2008

iii)
String m = A; for(int i = 1; i < 4; i++) { m = m + B; } System.out.println(m); [2 Marks]

Answer to question 1b iii): Justification:

Question 1b continues overleaf. Page 6 of 10 ECS401 Mid term Test Autumn 2008

iv)
int p = 0; for(int i = 1; i <= 2; i++) { p = p+1; } for(int j = 1; j <= 4; j++) { p = p+1; } System.out.println(p); [3 Marks]

Answer to question 1b iv): Justification:

[Total Marks for Part 1b: 9] [Total Marks for Question 1: 15] Test continues overleaf. Page 7 of 10 ECS401 Mid term Test Autumn 2008

Question 2 [10 marks] Write a Java program that comments on the endangered status of different animals. It should ask the user to type in the name of an animal. Depending on the animal named it should print a message giving its status, chosen from: Extinct, Endangered, Vulnerable or Not in danger. For example, if the user typed in Dodo, it should print the message: The Dodo is unfortunately now extinct. The program should first ask how many animals the user would like to check. They type in a number. The program should then ask them for the name of an animal and immediately give a response. It should do this the requested number of times. An example run of the program might go: How many animals do you want to check? 7 OK. You will need to give me 7 animals. Give me the name of animal 1? Dodo The Dodo is unfortunately now extinct. Give me the name of animal 2? Blue Whale The Blue Whale is endangered and needs protection. Give me the name of animal 3? Passenger Pigeon The Passenger Pigeon is unfortunately now extinct Give me the name of animal 4? Gruffalo The Gruffalo is one I have not heard of. Give me the name of animal 5? Albatross The Albatross is endangered and needs protection. Give me the name of animal 6? Cheetah The Cheetah is vulnerable. Give me the name of animal 7? Rabbit The Rabbit is not in danger. Your program should be able to give the correct response for each of the animals above. Others it can just reply that it has not heard of them as above. The responses given for each category should exactly match those in the example above. Your program may use pop-up windows to ask questions and display its responses.
[10 Marks] Write your answer overleaf.

Page 8 of 10

ECS401 Mid term Test Autumn 2008

Answer to question 2:

Page 9 of 10

ECS401 Mid term Test Autumn 2008

Answer to question 2 continued:

[Total Marks for Test: 25]


END OF TEST

Page 10 of 10

ECS401 Mid term Test Autumn 2008

You might also like