Docsity

Stepwise refinement - Computing - Exam, Exams of Computer Science

Toggle sidebar
bg1
Cork Institute of Technology
Bachelor of Engineering in Electronic Automation and Robotics – Stage 1
Bachelor of Engineering in Applied Electronics Design – Stage 1
Bachelor of Engineering in Communications Systems – Stage 1
(NFQ Level 7)
Summer 2007
Computing
(Time: 3 Hours)
Answer any four questions
Maximum available marks is 100
All questions carry equal marks
Examiners: Mr. P Cogan
Mr. D. Denieffe
Dr. R. Dubhghaill
Q1. (a) Write a note discussing how each of the following relates to writing BASIC
programs;
(i) Constants
(ii) Stepwise refinement.
(iii) Functions
(iv) Strings. [8 marks]
(b) Explain each line of the following program, draw the program’s output and
describe what happens if the numbers 4 and 0 are entered. [10 marks]
REM summer 2007 q1(b)
DIM var1 AS INTEGER
DIM var2 AS LONG
DIM var3 AS SINGLE
CLS
INPUT "Enter two numbers "; var1
INPUT var2
IF (var1 = 0) OR (var2 = 0) THEN
PRINT "cannot perform calculation"
ELSEIF var1 > var2 THEN
var3 = var1 / var2
ELSEIF var1 < var2 THEN
var3 = var2 / var1
END IF
PRINT "result is "; var3
END
(c) Write a simple BASIC program that reads in the names and temperatures of
three locations. The program should then report the highest temperature and
name any of the locations that are freezing (their temperature was less than 0).
[7 marks]
continued overleaf …. (25 Marks in total)
pf3
pf4

Partial preview of the text

Download Stepwise refinement - Computing - Exam and more Exams Computer Science in PDF only on Docsity!

Cork Institute of Technology

Bachelor of Engineering in Electronic Automation and Robotics – Stage 1

Bachelor of Engineering in Applied Electronics Design – Stage 1

Bachelor of Engineering in Communications Systems – Stage 1

(NFQ Level 7)

Summer 2007

Computing

(Time: 3 Hours)

Answer any four questions Maximum available marks is 100

All questions carry equal marks

Examiners: Mr. P Cogan Mr. D. Denieffe Dr. R. Dubhghaill

Q1. (a) Write a note discussing how each of the following relates to writing BASIC programs; (i) Constants (ii) Stepwise refinement. (iii) Functions (iv) Strings. (^) [8 marks] (b) Explain each line of the following program, draw the program’s output and describe what happens if the numbers 4 and 0 are entered. [10 marks]

REM summer 2007 q1(b) DIM var1 AS INTEGER DIM var2 AS LONG DIM var3 AS SINGLE CLS INPUT "Enter two numbers "; var INPUT var IF (var1 = 0) OR (var2 = 0) THEN PRINT "cannot perform calculation" ELSEIF var1 > var2 THEN var3 = var1 / var ELSEIF var1 < var2 THEN var3 = var2 / var END IF PRINT "result is "; var END

(c) Write a simple BASIC program that reads in the names and temperatures of three locations. The program should then report the highest temperature and name any of the locations that are freezing (their temperature was less than 0). [7 marks] continued overleaf …. (25 Marks in total)

Q2. (a) Cells A3 to A8 on a spreadsheet contain a list of numbers in ascending order. Write down and explain the formulae that you would use to; (i) Compare the first two numbers in the list and give the biggest number. (ii) get the average of all the numbers in the list. (iii) find the number closest to but not exceeding 44.

[7 marks] (b) Write a BASIC program that reads in an exam mark which is an integer number and grades it as follows; 0 to 29 = F 30 to 39 = E 40 to 49 = Pass 50 to 59 = Merit 2 60 to 69 = Merit 1 70 to 100 = Distinction Anything else = Error message as mark is invalid [6 marks]

(c) Write a BASIC program that generates numbers for a lottery. It should generate 5 random numbers from 1 to 50 and an additional two random numbers between 1 and 9. Your program should wait for a key press and then generate a new set of numbers. It should repeat until the key pressed is ‘Q’. [12 marks] (25 Marks in total)

Q3. (a) Why are loops used in programming? Give some BASIC language examples of how the main types of loop are used. [4 marks]

(b) Give the syntax of the following two BASIC statements: (i) FOR … NEXT (ii) DO … LOOP [4 marks]

(c) Distinguish between post-test loops and pre-test loops. [2 marks]

(d) Write a program, using NESTED FOR LOOPS , which produces the following output:



**

  • [5 marks] continued overleaf ….

Option 1 should calculate and display reactance (X (^) L) using the formula

X L = 2 π fL

where f is the frequency and L is the inductance. The program should read in f and L and not proceed with the calculation until a positive value is entered for L.

Option 2 should calculate and display the total inductance (Ltotal ) of three inductors (L 1 , L 2 and L 3 ) in parallel. This is given by the formula

1 2 3

Ltotal L L L

Under no circumstances should any of the inductances entered be zero, the values entered must be checked to prevent this.

Option 3 should display a table of the inductor reactance for a frequency that varies between two limits using the formula in option 1. The user should enter L and the starting and finishing frequency. The user should also be asked to enter the increment size that f will change by in the table. For example if L =10 and the increment size is 2, the program might generate a table that looks like this; Frequency f (Hz) Reactance X (^) L(Ohms) 1 62. 3 188. 5 314.

Option 4 should cause the program to quit. [20 marks]

(25 Marks in total)

ooooOOOOoooo