0% found this document useful (0 votes)
105 views10 pages

Universiti Tenaga Nasional: College of Computing and Informatics

This document contains instructions and content for a final examination for a Programming 1 course. It includes 10 multiple choice questions worth 1 mark each and 6 short answer questions worth between 1-6 marks each. The multiple choice section covers topics like flowcharts, variable declarations, operators, loops, functions and arrays. The short answer questions involve writing code snippets to demonstrate understanding of concepts like functions, arrays, loops, strings and more.

Uploaded by

Ratha
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)
105 views10 pages

Universiti Tenaga Nasional: College of Computing and Informatics

This document contains instructions and content for a final examination for a Programming 1 course. It includes 10 multiple choice questions worth 1 mark each and 6 short answer questions worth between 1-6 marks each. The multiple choice section covers topics like flowcharts, variable declarations, operators, loops, functions and arrays. The short answer questions involve writing code snippets to demonstrate understanding of concepts like functions, arrays, loops, strings and more.

Uploaded by

Ratha
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/ 10

UNIVERSITI TENAGA NASIONAL

College of Computing and Informatics

BACHELOR OF COMPUTER SCIENCE (CYBER SECURITY) (HONS.)


BACHELOR OF COMPUTER SCIENCE (SYSTEMS AND NETWORKING)
(HONS.)
BACHELOR OF COMPUTER SCIENCE (SOFTWARE ENGINEERING)
(HONS.)

FINAL EXAMINATION
SEMESTER I 2019/2020

PROGRAMMING 1 WITH C
(CSNB144)
PROGRAMMING 1
(CSEB134)

September 2019

Time allowed: 3 hours + 10 minutes for reading

INSTRUCTIONS TO CANDIDATES

1. The total marks for this exam is 100.


2. There are THREE (3) SECTIONS to this paper: Section A, Section B and Section C.
3. Answer ALL questions in the answer booklet provided.

DO NOT OPEN THIS QUESTION PAPER UNTIL YOU ARE INSTRUCTED TO DO SO


THIS QUESTION PAPER CONSISTS OF 10 PRINTED PAGES INCLUDING THIS PAGE

Page 1 of 10
SECTION A: MULTIPLE-CHOICE QUESTIONS
(10 QUESTIONS, 10 MARKS)
Instruction: Please choose the best answer. Each question worth 1 mark.

1. Select the task represented by the following flow chart symbol in Figure 1:

Figure 1
(A) Terminal
(B) Process
(C) Input/Output
(D) Printer output symbol

2. Which of the variable declarations below are CORRECT?


(i) char name = Uniten;

(ii) double volume = 9.65E-5;


(iii) int amount =-1989;
(iv) float price = 26.68;

(A) (i) and (ii) only


(B) (i), (ii) and (iii) only
(C) (ii), (iii) and (iv) only
(D) (iii) and (iv)

3. The __________ sign is also known as the __________ operator?


(A) + ……. assignment
(B) = ……. assignment
(C) * ……. stream manipulator
(D) & ……. stream insertion

Page 2 of 10
Semester I 2019/2020 Programming 1 with C /

Programming 1
4. Which of the following operators is NOT a relational operator in C?
(A) < >
(B) ==
(C) >=
(D) >

5. The ________________ statement when execute in a switch statement causes


immediately exit from the structure.
(A) break
(B) continue
(C) exit
(D) default

6. Which of the following statements concerning the while statement is correct?


(A) It is used to define loops.
(B) The loop body is executed if the associated condition is false.
(C) When the condition becomes true, the control drops out of the loop.
(D) All of the above

7. Based on the code below, how many times will the asterisk (*) be printed out.
for (point = 7; point > 0; point=-2)
printf("*");

(A) 8
(B) 7
(C) 5
(D) 4

8. Which of the following statements calls function named calculateCharge?


(A) call calculateCharge;
(B) charge = calculateCharge( );
(C) calculateCharge;
(D) void calculateCharge (float price, float length);
Page 3 of 10
Semester I 2019/2020 Programming 1 with C /

Programming 1
9. Array declaration is made by specifying the ____________
(A) Data type, array name and array size.
(B) Data type and variable name.
(C) Data type and array size.
(D) Array name and array size.

10. What would be the output of the following C-statements:


int num1, num2, number=3, *numPtr;
num1= 2 * (number + 5);
numPtr =&number;
num2= 2* (*numPtr + 5);
printf(“\num1 = %d num2 = %d”, num1, num2);

(A) num1 = 16 num2 = 16


(B) num1 = 17 num2 = 42
(C) num1 = 16 num2 = 42
(D) num1 = 17 num2 = 16

Page 4 of 10
Semester I 2019/2020 Programming 1 with C /

Programming 1
SECTION B: SHORT ANSWER QUESTIONS (6 QUESTIONS, 60 MARKS)
Instruction:Answer ALL questions.

Question 1
A snipped C program contains the following declaration and initial assignments

int a = 8, b = 5, x;
float x = 2.0, y= -1.0, z;

Determine the value of x in each of the following expressions. Use the values initially
assigned to the variables for each expression.

(a) c = 3 * ((a/5) + (4*(b-3)) % (a+b-2))


[3 marks]

(b) c = ++x - x++ + ++y


[2 marks]

(c) c = (a += (b – 2))
[2 marks]

Question 2
Based on the C segment in code below
int x, y;
scanf("%d", &x);
if(x > 2)
if(x < 10)
if(x >= 5)
printf(“Welcome to UNITEN);
else
printf(“Today is final exam day”);
else
printf(“Good luck for your final exam”);
else
printf(“I like programming”);

Page 5 of 10
Semester I 2019/2020 Programming 1 with C /

Programming 1
Trace the output of the above program if the input value for x is:

(a) 1
[1 mark]

(b) 5
[1 mark]

(c) 10
[1 mark]

Question 3
Change the while loop structure in code below using for loop without changing the
logic.
int ary[4] = { 1, 2, 3, 4 };
int p[4] = {};
int i = 0;
while (i<4) {
p[i] = ary[i] * i;
ary[i] = ary[i] + p[i];
i++;
}
printf("%d%d\n", p[2], ary[3]);
[6 marks]

Question 4
Given the main function below:
void main(){
int num1 = 10, num2 = 5, num3 = 6, minimum, total ;
char evenodd ;
minimum = min(num1, num2, num3);
evenodd = oddeven(num3);
add(&total,&num1, &num2);
}

(a) Write a function named min() that accept THREE (3) integers and returns the
smallest number of those three integers.
[6 marks]

Page 6 of 10
Semester I 2019/2020 Programming 1 with C /

Programming 1
(b) Write a function name oddeven() that accept ONE (1) integer and return
character ‘O’ if the number is odd or character ‘E” is the number is even.
[5 marks]

(c) Write a function name add() that accept THREE (3) address (total, num1,
and num2) by using passing by reference. Add the variable of num1 and num2
and store the result at total.
[5 marks]

Question 5
Array1 and Array2 below are one dimensional integer arrays.

0 1 2 3 4
Array1 55 37 89 14 61

0 1 2 3 4
Array2 24 90 73 45 32

(a) Write C programming language statement(s) to declare and initialize the TWO
(2) arrays above.
[2 marks]

(b) Write loop statement(s) to display the content of Array1. (You are not
required to write a full program).
[4 marks]

(c) Write program statement(s) to sum up all the numbers in Array2. (You are
not required to write full program)
[5 marks]

(d) Write program statements to SWAP the contents of location 3 (subscript is 3)


of these two arrays. (hints: You might need to use a temp variable)
[5 marks]

Page 7 of 10
Semester I 2019/2020 Programming 1 with C /

Programming 1
Question 6
Given the following C Program and answer the following questions
#include<stdio.h>
#include<string.h>
void main(void) {
char str1[15] = "I love";
char str2[100] = "Uniten";
int count;
strcat(str2, str1);
strncpy(str2, str1, 9);
count = strlen(str2);
printf("%s contains %d characters.\n", str2, count);
}

(a) What is the output for the above program?


[4 marks]

(b) Trace the output and explain what happens when each of the following
statements is executed.
i. strcat (str2, str1);
[4 marks]

ii. strncpy(str2, str1, 9);


[4 marks]

Page 8 of 10
Semester I 2019/2020 Programming 1 with C /

Programming 1
SECTION C: PROGRAMMING QUESTIONS (2 QUESTIONS, 30 MARKS)
Instruction:Answer ALL questions. Write a complete C program. Study the
problem carefully before you attempt to answer.

Question 1
You are required to write a program to perform the calculation of the amount of penalty
that need to pay by the book store customer. Your program is to accept the book price
from the user and the number of day (s) the book had overdue, the amount of penalty is
10% of the book price per day. If the amount of penalty is more than the book price,
then the system will advise the user to buy the book, otherwise the program will display
the amount of penalty. After display the answer, your program should ask the user
whether they wish to continue with the next book and your program should only stop,
if the user key in 0. Sample output as below:
Enter book price (press 0 to stop): RM 30.00
Enter day(s) book had overdue: 3
You need to pay RM9.00 for the penalty

Enter book price (press 0 to stop): RM 100.00


Enter day(s) book had overdue: 5
You need to pay RM50.00 for the penalty

Enter book price (press 0 to stop): RM 10.00


Enter day(s) book had overdue: 15
You need to pay RM15.00 for the penalty.
You are advised to buy the book because the penalty is more
or equal with the book price.

Enter book price (press 0 to stop): RM 0


Thank You. Exit.
Press any key to continue…

[10 marks]

Question 2
You are required to write a complete C program that will read the exam marks and
names for 5 students. The range of the marks should be in between 0-100. The program
should consists THREE (3) functions:

Page 9 of 10
Semester I 2019/2020 Programming 1 with C /

Programming 1
 A function name passfail( ). This function will accept the array of marks
then count and display the number of students passing and failing the exam.
(Tips: student needs to score at least 50 marks in order to pass an exam)
 A function name below20(). This function will accept the array of marks and
the array of students. Next, it should find and print the names for those scoring
20 marks and below.
 A function name max( ). This function will accept the array of marks and the
array of students. Next, find the top students whose get the highest marks and
display their name together with their marks.

You are required to declare your function prototypes, call the functions, and define the
functions precisely according to the problem given. Sample output as follow
Enter student 1: Ali
Enter marks: 60
Enter student 2: Siti
Enter marks: 300. Invalid marks.
Enter marks: 90
Enter student 3: Raju
Enter marks: 10
Enter student 4: Lim
Enter marks: 15
Enter student 30: Priya
Enter marks: 96

PASS : 3 students.
FAIL : 2 students.

-----Student who’s get 20 and below-------


1. Raju (10 marks)
2. Lim (15 marks)

------ The top students-------


Priya (96 marks)

Press any key to continue…

[20 marks]

---End of Questions---

Page 10 of 10
Semester I 2019/2020 Programming 1 with C /

Programming 1

You might also like