Download as pdf or txt
Download as pdf or txt
You are on page 1of 4

CPRG1201

THE COUNCIL OF COMMUNITY COLLEGES OF JAMAICA

ASSOCIATE OF SCIENCE EXAMINATION

SEMESTER II – 2015 MAY

PROGRAMMES: COMPUTER SERVICING AND ELECTRONICS


MANAGEMENT INFORMATION SYSTEMS

COURSE NAME: COMPUTER PROGRAMMING I – C


CODE : (CPRG1201)

YEAR GROUP: ONE

DATE: THURSDAY, 2015 MAY 7

TIME: 9:00 A.M. – 12:00 NOON

DURATION: 3 HOURS

EXAMINATION TYPE: FINAL

This Examination paper has 4 pages


INSTRUCTIONS:

SECTION B: ANSWER ANY THREE (3) QUESTIONS FROM THIS SECTION.

The Council of Community Colleges of Jamaica Page 7


CPRG1201

SECTION B

Instructions: Answer any THREE (3) questions from this section.

Question 1

a. Write a program that will find the sum of even numbers from 1 to 250 and output the sum
and average. (10 marks)

b. Write a C program that will find the sum of 10 elements in an array. The elements are 1,
3, 5, 4, 7, 2, 99, 16, 45, and 67. Output the contents of the array. The sum of the elements
in the array should be printed. (15 marks)

(Total 25 marks)

Question 2

a. Find and correct the error in each of the following (Note: there may be more than one
error):

i. For ( z = 50, z >= 0, x++ )


printf( "%d\n", x ); (5 marks)

b. Correct the following code so that it prints whether a given integer is odd or even:

if ( value % 2 )
printf( "Even integer\n" );

else
printf( "Odd integer\n" ); (10 marks)

c. Correct the following code so that it outputs odd integers from 2 to 350:
counter = 1;

Do {
if ( counter % 2 == 1 )
printf( "%d\n", counter );
counter += 2;
} While ( counter < 350 ); (10 marks)

(Total 25 marks)

The Council of Community Colleges of Jamaica Page 8


CPRG1201

Question 3

a. Give the function header for each of the following functions.

i. Function square that takes integer arguments, s1 and s2, and returns an integer result.
(5 marks)
ii. Procedure largest that takes three floats, a, b, c, and outputs the largest. (5 marks)
iii. Procedure instructions that does not receive any arguments and displays instructions
to a user. (5 marks)

b. Write a Function Circumference that calculates the area and circumference of a circle.

Area = pi × Radius × Radius


Circumference = 2 × pi × radius (10 marks)

(Total 25 marks)

Question 4

a. i. Define an array of type float called numbers with 5 elements, and initialize the
elements to the values 0.0, 1.1, 2.2, …, 5.5. Assume the symbolic constant SIZE has
been defined as 5. (5 marks)

ii. Define a pointer, zPtr, that points to an object of type int. (3 marks)

iii. Print the elements of array numbers using array subscript notation. Use a for
statement and assume the integer control variable i has been defined. Print each
number with 1 position of precision to the right of the decimal point. (3 marks)

iv. Give two (2) separate statements that assign the starting address of array numbers to
the pointer variable zPtr. (3 marks)

b. Write single statements to accomplish the following:

i. Concatenate the string in s1 to s2 and print the result. (4 marks)

ii. Use the function string copy to copy the contents of x into y. (4 marks)

c. Create a structure definition called card that contains two character pointer members, and
an array member called deck reserving space for 52 members. (3 marks)

(Total 25 marks)

The Council of Community Colleges of Jamaica Page 9


CPRG1201

Question 5

a. Define the term “arrays”. (3 mark)

b. Write the C program to open a file called homework for writing. Output an appropriate
message if the file cannot be opened. (10 marks)

c. Provide the definition for the following structure:

Structure inventory containing character array partName[ 30 ], integer partNumber,


floating point price, integer stock and integer reorder. (4 marks)

d. Write a single statement to accomplish each of the following. Assume that each of these
statements applies to the same program.

i. Write a statement that opens the file "oldmast.dat" for reading and assigns the
returned file pointer to ofPtr. (4 marks)

ii. Write a statement that opens the file "trans.dat" for reading and assigns the returned
file pointer to tfPtr. (4 marks)

(Total 25 marks)

END OF EXAMINATION

The Council of Community Colleges of Jamaica Page 10

You might also like