BCS THE CHARTERED INSTITUTE FOR IT-BCS HIGHER EDUCATION

Post New Homework

SECTION A

Answer 2 questions (out of 4).

A1

In the array V below, the maximum value is 17 and the minimum value is 4 so the range (calculated as 17-4) is 13.

index 0

1

2

3

4

5

6

7

8

9

V    10

9

17

7

12

8

5

15

4

6


a) Write a function minVal() to find the minimum value in an array V

b) Similarly write a function maxVal() to find the maximum value in an array V

c) Write a third function range1() to calculate the range of V (the difference between the max and min values) using minVal() and maxVal()

d) Write a function range2() that does not call the function minVal() or maxVal() or any other functions written by you, but calculates the same result as range1().

e) Choose which version of range calculation you prefer and state one reason why.

A2

In a certain game played with cards, a player is dealt a hand of 7 cards.

Each card has a value (Ace(one), Two, Three, Four, Five, Six, Seven, Eight, Nine, Ten, Jack(11), Queen(12) or King(13)) and each card has a Suit (Clubs(1), Diamonds(2), Hearts(3) or Spades(4)). So a card can be represented by 2 numbers (V,S). The first number V (in the range 1 to 13) represents the Value and the second number S (in the range 1 to 4) represents the Suit.

In the game it is important to know “the highest value of each Suit”.

An example of a hand of seven cards can be represented by two arrays

index

1

2

3

4

5

6

7

V

4

3

4

10

2

13

8

S

1

1

3

4

1

2

3


In this example of 7 cards, the highest value in Clubs is “Four” (i.e. S[1]=1, V[1]=4) and the highest value in Diamonds is “King” (i.e. S[6]=2, V[6]=13)..

You are required to write a program to find the highest value of each Suit.

Your program should assume the two arrays V and S exist and are already set up with the values to search. You should use this as data to discover the highest values.

The output from the program should be the four highest value cards (in this example, Four of Clubs, King of Diamonds, etc). Output “Not Found” for the value if a suit is not present in the hand.

A3

a) Trace the behaviour of the call h(), when h and V are defined as shown below.

index 0

1

2

3

4

5

V          9

8

7

4

5

1

int f(g){if(g<0)return -g; else return g;} int h(){

int i=f(V[1]-V[0]);

for(var j=2;j<6;j++){ if(f(V[j]-V[j-1])>i)

i=f(V[j]-V[j-1]);

}

return i;

}

b) Describe in a single sentence the overall effect of the function h()   

c) Rewrite the function h() changing all the identifiers to make the code more readable and understandable and add suitable comments.

A4

a) Consider the code below and write it out in a more familiar human readable form.

void p(int q,char r){for(int s=0;s<q;s++)printf("%c",r);}p(10,'+');

b) List the operators in the program above and, for each, state how many operands it has. One of the operators is a shorthand for something longer – write out the longer version.

c) Referring to the code in part a), find and write out the following:

i) all the different identifiers

ii) all the different constants

iii) a conditional (logical, boolean) expression

iv) an iterative (repetitive, loop) statement

v) the statement that is repeated by the loop

d) Write out the code from a) again, this time replacing the loop with an equivalent while loop.

SECTION B

Answer 5 questions (out of 8).

B5

A business uses a Straight Line depreciation function to calculate the value of its computer system assets over their useful life. Straight Line depreciation assumes that an item will depreciate by a set amount each year, given by the formula:

D = (P – F) / t

Where:

D = Depreciation per year

P = Purchase cost of the item F = Final value of the item

t    = Number of years the item will be in use

a) Write an expression in pseudocode (or a program in a language of your choice) in which variables P, F and t are input and the value of the item is printed each year after depreciation

b) Using the pseudocode (or program) from part a), trace the value of the item where

Purchase cost = £40,000,

Final value F = £5,000 and

the number of years of the item t = 4.

B6

Write a function factorial (n) in pseudocode (or a programming language of your choice) to calculate the factorial of n:

[Definition: factorial (n) = n * (n-1) * (n-2) ... * 2 * 1]

a) Using recursion 

b) Using iteration  

B7

a) Explain the difference between a compiler and interpreter.

b) Discuss the advantages and disadvantages between using a compiler and interpreter.

B8

a) Using an algorithm, describe the operation of a stack.

b) A stack contains the values 7, 6, 9 where 7 is the first value stored and 9 is the last. List the final values in the stack after the following operations are made:

1. Pop

2. Pop

3. Push12

4. Push16

5. Pop

6. Push 11

B9

When designing a web page to take information from a user there are various form elements available. Name FOUR different form elements, giving an example of the kind of information that each is best suited for and drawing what they look like on screen.

B10

Compare the following pairs of terms.

a) Truncation and rounding

b) Static and dynamic data structures

c) Flat file and relational databases
 
B11

a) Name the stage of the traditional software development process in which an algorithm would be created and the tasks it contains.

b) Name the stages that precede and follow the stage mentioned in a), describing the links between these three stages with reference to the algorithm.

B12

Consider the following function called findmax together with a single test case as shown below:

int findmax(int low, high){

/* specification: find the maximum value in array v between index low and index high inclusive */ int max; /* holds the maximum value found so far */

int i; /* loop counter */ max=100;

for ( i=low; i<high; i++)

if( v[i] > max )

max=v[i];

return(max);

}

test case: v[1]=55; v[2]=4; v[3]=16; low=1; high=3;

a) How would a black-box test of the function findmax be performed?

b) In what way would the error in the function findmax show up under black-box testing?

c) How would a white-box test of the function findmax be performed?

d) In what way would the error in the function findmax show up under white-box testing?

Post New Homework
Captcha

Looking tutor’s service for getting help in UK studies or college assignments? Order Now