8293

4
UNIVERSITY OF TECI-INOLOGY, JAMAICA FACULTY: Eugineertng and Computing SCHOOL: Computing & Information Technology Final/ Redn Examina tiou, Semester 2 Module Name: Programming I Module Code: CMPI024 Date: April,20l2 Theory/ Practical: Theory Groups: BSCl, Franchise (Community Colleges) Duration: 2 hours INSTHUCTIONS 1. Answer all questions in Section [ and any two (2) from Section II of this test a. Answer Sections I and )[ in the Answer Booklet provided 2. The total marks for each Section is stated in brackets at the start of that Section 3. All working must be clearly shown. 4. Silent electronic calculators may be used [Of this test. 5. This paper is marked out of a total of 75 ilt:t r ks. no NOT TURN THiS rACE UNTIL YOU ARE TOLl) TO DO SO Page 1 of 4

Upload: kaheem-koolkidz-whittingham

Post on 15-Apr-2016

213 views

Category:

Documents


0 download

DESCRIPTION

programming past papers

TRANSCRIPT

UNIVERSITY OF TECI-INOLOGY, JAMAICA

FACULTY: Eugineertng and Computing

SCHOOL: Computing & Information Technology

Final/ Redn Examina tiou, Semester 2

Module Name: Programming I

Module Code: CMPI024

Date: April,20l2

Theory/ Practical: Theory

Groups: BSCl, Franchise (Community Colleges)

Duration: 2 hours

INSTHUCTIONS

1. Answer all questions in Section [ and any two (2) from Section II of this testa. Answer Sections I and )[ in the Answer Booklet provided

2. The total marks for each Section is stated in brackets at the start of that Section3. All working must be clearly shown.4. Silent electronic calculators may be used [Of this test.5. This paper is marked out of a total of 75 ilt:t r ks.

no NOT TURN THiS rACE UNTIL YOU ARE TOLl) TO DO SO

Page 1 of 4

t '

COMl'liLSOHY QlmSTlONSITOTAL = 25 marks]

Sectiuu 1- Auswcl' ALL qllcsliol1s

Justrncriuns: Answer !III questions within the Answer Booklet for a total of25 marks.

1. Answer all questions list cd below: -

A) Using nested for loops.write the pseudocode segment that will display the following:~.

-J.: * *

B) A C program contains the following dcclarntious: -

f16at mo, yz, rt;int x , y, z :

Write a single C statement EA.CH that will:

i. accept user-input values for y and yz

II. increase mo by a quarter of 1110

iii. print the rt as a currency value in the format: $999999.99

IV. use the couditional rpcrlltqr 10 assign y to x if mo is positive; but assign z to x ifmo is not positive.

II +1+ I +2f/1lJr~sJ

C) By tracing, show the state of each varialx., lX, Y IJfU( z) in every line for the followingpseudocode-segment (NOTE: Each line affects the variable's value/or the next line) : -

l. DECLARE x, y, Z AS WHOLE2. LET Z ~ 24 / 53. LET x ~ Z % ( Z + 3)4. LET Y 0 + x / 3 -t- z5. LET z ~ x / y / z6. LET x ,_. Z -I- (z - x) / 4

[5 l1I(lr{(s)

J)) It is suggested that you can tell someone's personality based on the first letter in theirfirst names. What follows is a table that have some of the first letters: -

~ ~ . ",H .'N Athletic

'F' Foxy

'E' Elegant

Others Philosophical

[)esigl~th~-~-cgnle~;t ~f tr;efl;;W-ch"rt(Y;~~-d;~(~i71al'cto write the ell/ire programdesign) that will display a message indicating a PEl{SONALlTV based on acharacter value thai represents the FIRST LETTER of the FIRST NAME using:i. The LINEAR/SEQUENTIAL IF design.

[6 !ll1I"k~'1

II. The CASE design.

Page2of4

ESSAY ITEMSItOtAL = 50 marks]

Sectiollll- Ailswer ANY rwo (2) questions.--~~--------------------------------------

lnstructlons: Answer any two (2) questions within the Answer Bonklet provided for a total of50 marks, Four (4) questions are provided.

2. [C code Analysis]

Consider the following program solution written in C.

ftinclude <stdio.h>void main(void){

int year;int popl;const int curryear = 2012;printf ("Please enter the current population:");scanf ("%d", &popl);printf ("YEAR POPULATION\n=======================\n\n") ;for (year = 5; year> 0; year -= 1){

printf ("%4d %06d\n", (curryear - year), popl);popl += popl % year;

A) Using a Trace Table, show the contents of each variable & what will be displayed by the

above program if the user enters: 23 as tile current population.

Iis marks]

13) Design the Pseudocode that performs the same task as the above program.

r 10 1II(O'I<s]

3. [Decision Tables]

"Employees at Greggs Ltd work a set number of hours related to the following: All female

workers work for 5 hours a day as long as their salaries are below $ 15,000.00. All male workers

work for 5 hours a clay. Anyone with salaries above $60,000.00 must work on weekends. All

males with salaries equals to or less than $GO,OOO.OO get a maximum of7 hours overtime. Any

worker with salaries bet ween $15,000.00 and $60,000.00 (inclusive) also get a maximum of 7

hours overtime."

A) Construct a decision table, simplifying the conditions and outcomes to be used in the

above program's design.

(22 matksl

B) Ilow many columns would you have used if there were 6 unique conditions within the

problem? Justify the reason for the formula used for your answer.

1.1 Illm1'5]

I'age 301" 4

, .

4. [Pscudocoi\cl

A dating service wants to be able to find matches For its customers. They have commissioned

YOIl to build a system that will match customers based On the following information:

• NOTE; The company wants the program to calculate and output the 101;11

numhcr of compatihle matches that were made below.

• First, prompt the user for the total number of records to be processed.

• For each record to be processed, YOII should accept the custumcris gender, agc

and hcight.

, The system must validate the gender to make sure that it is only 'M' or '1"'. Ifthe

gender is not valid then an appropi-iate errnr message must be printed, assign

'F' to the variable and then continue with the rest of the system.

• The system must validate the age to make sure that it falls within the range ofln

to 60 (inclusivev. If the age is not valid then an ,lpprnprio,lc er'rnr mcssagc must

be printed, assign 60 to the variable ami then continue with the rest of the system.

" The system must then accept a customer's gender, ilgc and height from the user.

Assume that the entered information is valid.

• The system must then displuy an appropriate message stating whether the

inputted customer is compatihle or incomputihle with the record ill the database.

Customers are compatible as long as they have different geuners; their heights

are within l' (one foot) of each other; and their ages are the same.

HEQIJIHE));

Write the pseudocode corresponding to the design requested by SOM8.

5. [Fluwchart]

A) Design the flowchart that uses a loop to display all of the multtples of a variable ~

between vnriubles Y and z (inciusivei. (Declare any variables needed before use)

For example: x = 3,J' = 4, Z = 12; output is: 6 9 12

P5 marks]

ll) Design the Flowchart fill' a system that prompts for a positive integer, then computes

and prints out the slim or all squares from I to (and including) the integer. (Declare

allY variables needed before lIse)

r 10 marks I

Page 4 of -l