Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

Count - Computer Programming - Exam, Exams of Computer Engineering and Programming

Main points of this past exam are: Variables Number, Variable Names, Invalid Name, Balance Multiplied, Variable Interest, Java Statement, Output Produced, Program Code, Double Result, Boolean Expression

Typology: Exams

2012/2013

Uploaded on 03/28/2013

duraid
duraid 🇮🇳

4.3

(3)

75 documents

1 / 7

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Cork Institute of Technology
Graduate Diploma in Computing in Education
January 2006
Computer Programming
(Time: 2 Hours)
Choose any two questions.
All questions carry equal marks.
Examiners: Mr. T. Leane
Dr. H. Gibbons
Dr. M. O Moore
Q1. a) State whether each of the following is true or false. If false, explain why.
i) Comments cause the computer to print the text after the // on the screen when the program
is executed.
ii) All variables to be used in a program must be declared before they are used.
iii) All variables must be given a type when they are declared.
iv) Java considers the variables number and NuMbEr to be identical.
v) The operators *, /, %, + and – all have the same level of precedence.
(4 Marks)
b) Say whether each of the following variable names is valid or invalid and in the case of an
invalid name give the reason why it is invalid:
i) 1stnumber
ii) num1*num2
iii) guess?num
iv) Avg
(4 Marks)
pf3
pf4
pf5

Partial preview of the text

Download Count - Computer Programming - Exam and more Exams Computer Engineering and Programming in PDF only on Docsity!

Cork Institute of Technology

Graduate Diploma in Computing in Education

January 2006

Computer Programming

(Time: 2 Hours)

Choose any two questions. All questions carry equal marks.

Examiners: Mr. T. Leane Dr. H. Gibbons Dr. M. O Moore

Q1. a) State whether each of the following is true or false. If false, explain why.

i) Comments cause the computer to print the text after the // on the screen when the program is executed. ii) All variables to be used in a program must be declared before they are used. iii) All variables must be given a type when they are declared. iv) Java considers the variables number and NuMbEr to be identical. v) The operators *, /, %, + and – all have the same level of precedence. (4 Marks)

b) Say whether each of the following variable names is valid or invalid and in the case of an invalid name give the reason why it is invalid:

i) 1stnumber ii) num1*num iii) guess?num iv) Avg (4 Marks)

c) i) Give the declaration for a variable called count of type int. The variable should be

initialised to zero in the declaration.

ii) Give the declaration for two variables of type double. The variables are to be named rate and time. Both variables should be initialised to zero in the declaration.

iii) Give a Java assignment statement that will set the value of the variable interest to the value of the variable balance multiplied by 0.05. The variables are of type double.

iv) Give a Java assignment statement that will set the value of the variable interest to the value of the variable (^) balance multiplied by the value of the variable (^) rate. The variables are of type double.

v) Give a Java statement that will increase the value of the variable count by 3. The variable is of type int. (7 Marks)

d) i) What is the output produced by the following lines of program code?

int quotient, remainder; quotient = 7/3; remainder = 7%3; System.out.println (“quotient = “ + quotient); System.out.println (“remainder = “ + remainder);

ii) What is the output produced by the following lines of program code?

double result; result = (6 / 9) * 2; System.out.println (“(6 / 9) * 2 equals “ + result); (7 Marks)

e) Given that number is a variable of type int:

int x, y, z; x = 2; y = 3; if (x > 2) if (y > 2) { z = x + y; System.out.println (“z is “ + z); } else System.out.println (“x is “ + x);

ii) Show the output of the following code, if any.

int x, y, z; x = 3; y = 2; if (x > 2) { if (y > 2) { z = x + y; System.out.println (“z is “ + z); } } else System.out.println (“x is “ + x); (7 Marks)

h) i) What output will be produced by the following code?

int count = 0; while (count < 5) { System.out.println (count); count = count + 1; } System.out.println (“count after loop = “ + count);

ii) What output will be produced by the following code?

int count = 0; while (count < 5) { System.out.println (count); count = count - 1; } System.out.println (“count after loop = “ + count); (7 Marks)

Q2. Write a Java program for each of the following:

a) Write a program which prompts the user to enter two integer values. The program then compares the two values and writes a message to the screen reporting which value is smaller. (10 Marks) b) Write a program which prompts for and reads 100 integer values. The program will determine the smallest value entered and the largest value entered. These two values will then be written in an appropriate format to the screen. The program should use an array. (20 Marks) c) Write a program which implements a simple guessing game. The program should invite the user to guess a target value between 1 and 100. This target value is hard coded in to the program. The program should continue to give the user guesses until the target value is guessed correctly. The program should give the user feedback on each guess by telling the user if the guess was too high, too low, or correct. The program ends when the user guesses correctly. (20 Marks)

Q3. a) Show how a computer would sort the following list of numbers in ascending order using

c) Given the following sorted array:

illustrate the operation of the binary search algorithm by showing in detail how it would search for each of the following values:

i) 27 (which is present in the array) ii) 107 (which is not present in the array) (15 marks)

Q4. a) Name and explain the steps you should go through when given a problem statement and asked

to write a computer program to solve that problem. (5 Marks)

b) Write a Java program for recording students’ marks. The class size is 40 students. The program will read the name of each student and an integer mark (0-100) for each student. The program will calculate the following:

  • How many passed (> 39)
  • How many got honours (> 54)
  • Failure rate as a percentage.
  • Class average
  • How many students equaled or exceeded the class average. Finally the program will write the above values to the screen in a suitable format.

(45 Marks)