Stepwise refinement technique - Computer Science - Exam, Exams of Computer Science

Main points of this past exam are: Stepwise Refinement Technique, Design, Simple Calculator Program, Operations Addition, Subtraction, Multiplication and Division, Implement the Program

Typology: Exams

2012/2013

Uploaded on 03/30/2013

lallit
lallit 🇮🇳

4

(27)

150 documents

1 / 3

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Cork Institute of Technology
Page 1 of 3
Bachelor of Engineering (Honours) in Electronic Engineering- Stage 1
(NFQ Level 8)
Autumn 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
1. (a) Use the stepwise refinement technique to design a simple calculator program. The
calculator should accept integers only and perform the operations addition, subtraction,
multiplication and division. [15 %]
(b) Write C code to implement the program developed in (a). [10 %]
2. (a) Describe when it is appropriate to use i) a for loop and ii) a while loop? Illustrate your
answer with examples. [8 %]
(b) Rewrite the following for loop with (i) a while loop and (ii) a do..while loop.
int p, q;
for (p = 0; p < 15; p++)
{
printf (“P is %d”, p);
printf (“X Squared is %d”, X* X);
}
[7 %]
(c) i. Read in a sentence (terminated by full stop) and output the number of space
characters it contains;
ii. Read in a list of numbers from the keyboard with a sentinel of -1 and output
their sum and average; [10 %]
pf3

Partial preview of the text

Download Stepwise refinement technique - 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)

Autumn 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

  1. (a) Use the stepwise refinement technique to design a simple calculator program. The calculator should accept integers only and perform the operations addition, subtraction, multiplication and division. [15 %] (b) Write C code to implement the program developed in (a). [10 %]
  2. (a) Describe when it is appropriate to use i) a for loop and ii) a while loop? Illustrate your answer with examples. [8 %]

(b) Rewrite the following for loop with (i) a while loop and (ii) a do..while loop. int p, q; for (p = 0; p < 15; p++) { printf (“P is %d”, p); printf (“X Squared is %d”, X* X); } [7 %]

(c) i. Read in a sentence (terminated by full stop) and output the number of space characters it contains;

ii. Read in a list of numbers from the keyboard with a sentinel of -1 and output their sum and average; [10 %]

  1. (a) Describe the purpose and benefits of using a functional approach to writing programs. [5 %]

(b) Describe two possible uses of the return type of a function. [2 %]

(c) Write a function which calculates how many characters are uppercase within the string supplied as a parameter to the function called ‘UpperCaseCount’. The number of uppercase characters should be returned as the result of the function. [10 %]

(d) Write a function to reverse the contents of a string supplied as an argument. [8 %]

  1. (a) Discuss the interpretation of function calls and their usage in Boolean expression by illustrating how the outcome of the expression in the example below is determined: Example: #define FALSE 0 … int x=4; while(FunctionCall (x) != FALSE) { x--; } where the function declaration is: int FunctionCall(int x) {return(x)}; [6 %]

(b) Is it possible to shorten the Boolean expression given in the example? Explain your answer. [4 %]

(c) Write a function which accepts the two following parameters:

i) An integer array ii) The number of values within the integer array

(i) Display a horizontal line of asterisks ‘*’ for each value in the array. The number of asterisks per line should equal the corresponding integer array value e.g. value[0]=5 *****, value[1]=3 ***, etc. [7 %]

(ii) The function should determine the (1) sum and (2) average of the numbers in the array. The two values should be displayed on screen. The average value should be returned as the result of the function. [8 %]