Top-Rated Free Essay
Preview

my best

Good Essays
783 Words
Grammar
Grammar
Plagiarism
Plagiarism
Writing
Writing
Score
Score
my best
Tips for answering programming questions.

Most of the programming questions in this exam require you to write programs that solve a particular problem (do a particular task). A good way to go about answering these questions is as follows.
1) read the question carefully and make sure you understand the task your program should do.
2) On rough work paper, trace through an example of what your program should do. Pretend you are the program!!! and see what variables you need, what loops etc. Do not write any code yet! Try and figure out HOW to solve the problem before starting to write any code.
3) Once you’ve figured out from your rough work how to solve the problem, the next step is to write a program that contains this solution: As a step to writing your program you could do the following:
a. Note down the variables that will be used and their type: the type is important!;
b. Note the loops required and when those loops should start and stop;
c. Note what statements should be inside the body of those loops and what statements should be outside;
d. Note what methods are needed; what those methods should do and what they should return (or if they return anything);
e. Note what classes are needed and what variables are inside those classes, and so on
4) Once you know HOW your program should solve the problem, and you know WHAT variables loops statements etc are needed for that program to work, it should be easy to write down your finished answer.
5) Once you’ve written your program, scan through it and make sure that all brackets, quotes etc are in the right place. Then you’re done!

The most important thing in answering a programming question is to figure out how to solve the problem you’ve been given. If you’ve got the procedure for solving the problem correctly, but you’ve made mistakes in the details of your code, you will still get good marks. If you haven’t figured out how to solve the problem, but you have grammatically correct code, you will not get very good marks. So always figure out how to solve the problem BEFORE you start writing your code!!!!
It’s a good idea to explain, in English, in your exam answer book how exactly you are going to solve a particular problem. This will make things clearer for the examiner and for yourself. Even if you don’t get the correct code to solve a particular problem, if you expain how you think the problem should be solved, you will get some marks.

Good luck in your exams,
Fintan

University College Dublin

National University of Ireland, Dublin

An Coláiste Ollscoile Baile Átha Cliath
Ollscoil na hEireann, Baile Átha Cliath

Sample Exam Paper 2004

scbdf0001/scbdf0015 - First Year Science Examination cobdf0025 -First Actuarial and Financial Studies arbdf0015 - First Arts

Computer Science

Paper I

COMP1001 Introduction to Computer Programming
COMP1005 Introduction to Computer Programming
COMP1600 Introduction to Computer Programming

Professor J. Kramer
Mr. G. O’Hare
Dr. F. Costello*

Instructions for candidates

Answer any 3 questions. All questions carry equal marks. All programming examples are expressed in Java. Use Java in your solutions.

(Time allowed: 2 hours)

1. Answer parts (a), (b) and (c). 100 marks in total
1.(a) The following is a section of code from a program. You should examine the statements marked (i) to (v). Each of these statements is intended to assign a value to a variable. Some of these statements are correct, some are incorrect. Say, for each statement, whether it is correct or incorrect. If the statement is correct, explain what it does. If the statement is incorrect, explain why it is incorrect.

String s = JoptionPane.showInputDialog(null,”enter a string:”); //(i) int i = JoptionPane.showInputDialog(null,”enter an int:”); //(ii) double[] da = new double[3]; //(iii) for(int j=0; j 0) { Curr_num = Integer.parseInt(s); // convert string to int sum = sum + curr_num; // add to sum and get next string s = JOptionPane.showInputDialog(null, “enter a number (sum so far: ”+ sum+ “)”);
}
JOptionPane.showMessageDialog(null, “the total sum of the numbers you entered was ”+sum);
2.(b) Assume an int variable X, holding some number between 1 and 10. Write a snippet of code using a for loop to print out every number between 1 and 100 into which X divides evenly. Use System.out for printing. Here’s an example:

X holds the int 5
Program prints out: “5 10 15 20 25 …85 90 95 100”. (40 marks)

ANSWER
Always think before answering questions! The “X divides evenly” here is a bit misleading: all we need to do is print every multiple of 5, as follows:

for (int x = 5; x

You May Also Find These Documents Helpful