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
-
3. Write assignment statements that perform the following operations with the variables a, b, and c.…
- 1062 Words
- 8 Pages
Satisfactory Essays -
Question 7: (Practice) For the following section of code, determine the data type and scope…
- 720 Words
- 3 Pages
Satisfactory Essays -
4. The calculation should be executed only after all the valid input values are provided.…
- 1235 Words
- 5 Pages
Good Essays -
B. Write Code inside the main method and test it by compiling (F9) and running (Shift + F6) your code.…
- 2338 Words
- 10 Pages
Powerful Essays -
7. Convert the While loop in the following code to a Do-While loop: int x;…
- 431 Words
- 2 Pages
Satisfactory Essays -
f. (make sure to do these in OSI order and this is not in order yet)…
- 1636 Words
- 7 Pages
Satisfactory Essays -
This is our first individual assignment for Programming unit this semester. This assignment was given in December 2013, and submission date is on 10th February 2014.…
- 1859 Words
- 8 Pages
Good Essays -
Up to this point, you have identified the processes the program must perform, but you have not given any consideration to exactly how the processes work together to solve the problem. At this point, you must generate a description of the processing using pseudocode, a natural language description of the processing the application must perform.…
- 453 Words
- 4 Pages
Powerful Essays -
3. Write assignment statements that perform the following operations with the variables a, b, and c.…
- 313 Words
- 2 Pages
Satisfactory Essays -
An introduction to computer programming with an emphasis on problem solving will be presented. Specific topics include:…
- 1748 Words
- 8 Pages
Powerful Essays -
5.) Write the pseudocode for a program that will determine the average miles per gallon a car gets. (Inputs should be miles driven and gallons of gas used)…
- 470 Words
- 3 Pages
Satisfactory Essays -
b. So… all in all I’m really not sure what the exact answer is. Sorry bro…
- 1893 Words
- 8 Pages
Good Essays -
d. You will not have to add any other additional instance variables or methods, but…
- 495 Words
- 2 Pages
Satisfactory Essays -
c. Identify the objective of your call and the way in which you expect the call to end.…
- 308 Words
- 2 Pages
Satisfactory Essays -
I can benefit from HISCIP in many different aspects, each aspect of equal importance. The first way I can benefit from HISCIP is definitely experience. By having this rewarding opportunity of being a part of HISCIP, The familiarity I will gain will show me what prospect I will have to live up to and give me a deeper understanding of what to expect from the college lifestyle. This knowledge and awareness will be especially aiding to me and what I will take with me when I do go to college. Another aspect that HISCIP will benefit me in is to give me a sense of accomplishment, a reassurance that all that I have worked hard for hasn’t gone unnoticed. Not only will this give me a sense of accomplishment it will also give my family a sense of accomplishment, relief and the satisfaction to say that they raised me right on the principle and foundation of one thing and one thing only, getting a education.…
- 490 Words
- 2 Pages
Satisfactory Essays