Docsity

Random lottery number - Computer Science - Exam, Exams of Computer Science

Toggle sidebar
bg1
Cork Institute of Technology
Page 1 of 4
Bachelor of Engineering (Honours) in Electronic Engineering – Stage 1
(NFQ – Level 8)
Summer 2006
Computer Science
(Time: 3 Hours)
Answer Question 1 and THREE others
All questions carry equal marks
Examiners: Mr. D. O’ Donovan
Prof. G. Hurley
Dr. S. Foley
Q1. Write a program whose objective is to generate a set of lottery numbers. This involves using the
computer to generate six random numbers between 1 and 40. The user should then enter six
numbers and the computer should verify whether the user’s numbers match the computer
generated random numbers.
(a) Write functions to implement the following:
i. Generate an appropriate random lottery number and return it as the
function’s result. [3 %]
ii. Accept two lottery numbers as parameters and indicate whether they are
equal as its result. [2 %]
iii. Write a function which will use (a) ii. to determine if you have won the
lottery. The function should accept two integer arrays containing 6 values
each. [6 %]
iv. Write the lotto numbers to a file called “c:\lotto.txt”. [4 %]
(b) In the main function:
i. Declare two arrays capable of storing 6 lottery numbers each. [2 %]
ii. Write a
for loop which will populate an array with six numbers using the
function in (a).i above. [4 %]
iii. Write a
for loop to accept 6 numbers from the keyboard and stores them in
the second array of i. [4 %]
pf3
pf4

Partial preview of the text

Download Random lottery number - Computer Science - Exam and more Exams Computer Science in PDF only on Docsity!

Cork Institute of Technology

Bachelor of Engineering (Honours) in Electronic Engineering – Stage 1

(NFQ – Level 8)

Summer 2006

Computer Science

(Time: 3 Hours)

Answer Question 1 and THREE others All questions carry equal marks

Examiners: Mr. D. O’ DonovanProf. G. Hurley Dr. S. Foley

Q1.Write a program whose objective is to generate a set of lottery numbers. This involves using the computer to generate six random numbers between 1 and 40. The user should then enter six numbers and the computer should verify whether the user’s numbers match the computer generated random numbers. (a) Write functions to implement the following: i. Generate an appropriate random lottery number and return it as the function’s result. [3 %] ii. Accept two lottery numbers as parameters and indicate whether they are equal as its result. [2 %] iii. Write a function which will use (a) ii. to determine if you have won the lottery. The function should accept two integer arrays containing 6 values each. [6 %] iv. Write the lotto numbers to a file called “c:\lotto.txt”. [4 %]

(b) In the main function: i. Declare two arrays capable of storing 6 lottery numbers each. [2 %] ii. Write a (^) for loop which will populate an array with six numbers using the function in (a).i above. [4 %] iii. Write a for loop to accept 6 numbers from the keyboard and stores them in the second array of i. [4 %]

Q2.(a) Describe, with the aid of examples, the syntax and operation of the FOR and WHILE loops. [6 %]

(b) Write a program to prompt the user to enter a value, t (^) final , in seconds between 0 and 15

seconds. Using the formula, ( ) 5 1 where 3 secs

t v t = ^ − e −^ τ τ=  

, write the resulting values between 0 and t (^) final at 10ms intervals to (i) on-screen and (ii) a file called “results.dat”, at increments of 0.01secs, in the following fashion:

Time, t: Value, v t ( ):

etc. [15 %]

(c) Re-write the program in (b) to allow the user to enter the voltage at which the program is required to stop. [4 %]

Q3. Consider the following problem statement: A program to allow a user to choose Fahrenheit (F) to Centigrade (C) or Centigrade to Fahrenheit conversion, enter a temperature and see the corresponding temperature in the other scale. Using the formulae: C = (F - 32) / 9 * 5 F = (C * 9 / 5) + 32 (a) Generate a program design. [12 %] (b) Write C code to implement the program design in (a). [13 %]

(b) i. The code segment in Figure 5-1 does not operate as expected – explain why. [3 %] ii. How would you correct this situation? [3 %] #include <stdio.h> void main(){ float count; count = 0.0; {while (count != 3.4) printf(“\n%f",count); } count+=0.2; } Figure 5 - 1 (c) A student grade is derived from its mark as follows: Mark Student Grade 100 - 80 A 79 - 60 B 59 - 40 C 39 - 0 F Write a C function which will return the appropriate student grade representing the mark supplied as an argument. [9 %]