Sunteți pe pagina 1din 5

MIDSEMESTER

PIBT TrimesterOne
Trimester 3, 2016
2014

Unit Code and Title CSP2151D - Programming Fundamentals SAMPLE PAPER


STANDARD PAPER

Duration Reading time 5 minutes


Working time 1 hours 30 minutes
Total time 1 hours 35 minutes

Attempt ALL questions.

Marks Section A – 60 marks

Type of Exam Closed Book exam – textbooks, reference books or


Closed Book or notes may not be consulted during the exam.

Equipment or • Scientific Calculator


attachments required
during examination

Special Instructions • This examination paper consists of 1 section.


How many parts & Answer all questions
pages?Where answer • Answer all questions in the spaces provided
questions?

Students are not permitted to write on the examination or any other paper during
reading time.

Do not commence the examination until you are told to do so.

Page 1 of 5
Section A (100 marks)
Attempt ALL Questions.

Q1) What is the output of this code snippet? (10 marks)

for (int i=1; i<=5; i=i+1) {


printf("%4d%10d\n", i, i*i);
} Text

Write answer here:

Q2) What is the output of this code snippet? (10 marks)

int x=3, y=4, z=6;


if (x>2)
if (y>6)
z = 7;
else
z = 8;
printf("After the if statement z=%d\n", z);

Write answer here:

After the if statement z=8

Page 2 of 5
Q3) What problems exist in the following code snippet? Please circle the issues
and explain below. (10 marks)

double savings_plan(double amount, double ann_rate, int years) {


int month;
double monthly_mult, balance=0.0;
monthly_mult = 1.00 + (ann_rate/100.00/12);
for (month=1; month=12*years; month++) {
balance *= monthly_mult;
balance += amount
}
return balance;
}

Write answer here:

Q4) What problems exist in the following code snippet? Please circle the issues
and explain below (10 marks)

// show multiplication table


for(int j; j=<3; ++j)
{
for(int k; k=>3; k++)
{
printf("%d %d %d", j, k, j*k)
}
}

Write answer here:

Page 3 of 5
Q5) Write a function to perform the following calculation (30 marks)

Write answer here:

Page 4 of 5
Q6) Write a program that prints all numbers divisible by 2 up to a maximum
number provided by the user. You should use a for loop and scanf to achieve
this. (30 marks)

Write answer here:

Page 5 of 5