0% found this document useful (0 votes)
142 views4 pages

HH

This document provides instructions for a final exam on Computer Programming I - C. The exam consists of 4 sections and students must answer any 3 questions from Section B. Question 1 involves writing a program to find the sum and average of even numbers from 1 to 250, and a program to find the sum of elements in an array. Question 2 involves finding and correcting errors in code snippets and writing code to check if a number is odd or even. Question 3 involves writing function headers and a function to calculate the area and circumference of a circle. Question 4 involves defining arrays and pointers, string manipulation, defining a structure, and file input/output. Question 5 defines arrays and provides a structure definition and file input/output statements.

Uploaded by

Angel Lawson
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
142 views4 pages

HH

This document provides instructions for a final exam on Computer Programming I - C. The exam consists of 4 sections and students must answer any 3 questions from Section B. Question 1 involves writing a program to find the sum and average of even numbers from 1 to 250, and a program to find the sum of elements in an array. Question 2 involves finding and correcting errors in code snippets and writing code to check if a number is odd or even. Question 3 involves writing function headers and a function to calculate the area and circumference of a circle. Question 4 involves defining arrays and pointers, string manipulation, defining a structure, and file input/output. Question 5 defines arrays and provides a structure definition and file input/output statements.

Uploaded by

Angel Lawson
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 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

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy