Vous êtes sur la page 1sur 5

CSC2203 (F) / Page 1 of 5

INTI INTERNATIONAL UNIVERSITY

BACHELOR OF ENGINEERING (HONS) IN MECHANICAL ENGINEERING (BMEGI)


BACHELOR OF ENGINEERING (HONS) IN CIVIL ENGINEERING (BCEGI)
CSC2203 INTRODUCTION TO PROGRAMMING
FINAL EXAMINATION: JANUARY 2017 SESSION

This paper consists of FIVE (5) questions.

Answer TWO (2) compulsory questions in Section A and any TWO (2) questions in Section B
in the answer booklet provided. All questions carry equal marks.

SECTION A
Answer ALL questions in this section. All questions carry equal marks.

QUESTION 1

a) Evaluate the following expression and write your answer of each:

(i) 10.0 + 15 / 2 * 6.0


(ii) 2*5 == 4 * 4
(iii) 10 + 17 % 3 + 4.0
(iv) 5 % 2 * 4 > 5 || 4 % 2 * 5 < 7
(v) 3*4%6+6
(5 marks)

b) Convert the following mathematical expression into computer form:

3z  1
(i) x  2y  (2 marks)
4(3 y  2)

8
(ii) x (2 marks)
3(2  x) y
CSC2203 (F) / Page 2 of 5

c) Write a complete C program for the following description:

The program will calculates the tax pay of each employee depends on the age and marital status
(1 for single and 2 for married). The user will enter employee ID, age, salary, and marital status.
There are 4 different type of tax rate: 5%, 3%, 1% and 0% depends on the age and marital
status values entered by the user. The tax pay is calculated based on the following formula
based the tax rate as the following table. At the end, the program will display the security code,
and the tax amount for each employee.
Formula  Tax pay =salary * tax rate

[PS: this program will allow the user to calculate tax pay for next employee, until the user
choose to terminate the program.]

Age Marital status Tax rate


[1 – single, 2 – married]
< 30 2 0.05 (5%)
< 30 1 0.03 (3%)
>=30 2 0.01 (1%)
>= 30 1 0.00 (0%)

(16 marks)

QUESTION 2

a) Determine whether the following statement is True (T) or False (F). Explain the reason if the
statement is false.

(i) A preprocessor directive always begins with a double slash (//).


(ii) The semicolon (;) is used to mark the end of a complete C programming statement.
(iii) In array, the index element is always started with 1.
(iv) An format command is identified by a forward slash ( / ).
(v) In a do_while structure, the statements in the loop body will repeatedly executed as
long as the condition is false.
(vi) An identifier is a programming defined name that represents some elements in a
program, such as variable.
(vii) The variable 4Paychecks is a valid C identifier.
(viii) When a function does not return any value, a void should use in front of the function
header.
(ix) A variable is holding a value where the value cannot be changed during the execution
of the program.
(15 marks)
CSC2203 (F) / Page 3 of 5

b) Write a complete C program to prompt user to enter 10 student names and store them into an
array called Sname. The program will then allow a user to enter a name in order to search it
from the list (Sname). Display an appropriate message if the searched name is in the list or
even it is not in the list.
(10 marks)

SECTION B
Answer ANY TWO (2) of the THREE (3) questions in this section. All questions carry equal
marks.

QUESTION 3
(a) Write a function called letter_grade that has a single float argument called score and the
function will return the appropriate letter grade using a straight scale (90 to 100 is an A; 80
to 89 is a B; 70 to 79 is a C; 60 to 69 is a D; and 0 to 59 is an F).
(10 marks)

(b) (i) Write the definition of a structure called Student with the following members:
 Student name(30 characters)
 Student ID (integer)
 Course code (10 characters)
(5 marks)

(ii) Write a segment of program to read in the values for structure variable named
Ahmad. [Do provide the declaration statement for the Ahmad structure]
(7 marks)

(iii) Write a segment of program to display the values from the structure variable Ahmad
for Q3 (b) (ii).
(3 marks)
CSC2203 (F) / Page 4 of 5

QUESTION 4

a) Write a program that accepts 10 values and stores them in an array. In your program, you
should sort the 10 values and display the values on the screen according to the ascending order.
[Hint: Use a simple sort method: Bubble sort.]

(15 marks)

b) Trace the output for the following sample program and assume the address of var is 6487620.

(10 marks)

#include <stdio.h>
int main()
{
int var =10;
int *p;
p= &var;

printf ( "\n Address of var is: %u", &var);


printf ( "\n Address of var is: %u", p);
printf ( "\n Value of var is: %d", var);
printf ( "\n Value of var is: %d", *p);
printf ( "\n Value of var is: %d", *( &var));
}

QUESTION 5

a) Write a program segment that calculates the sum of all odd integers between 50 and 100 using

(i) while loop structure


(5 marks)

(ii) do..while loop structure


(5 marks)

(iii) for loop structure


(5 marks)
CSC2203 (F) / Page 5 of 5

b) Write a program which input a string and then count the total number of characters, the number
of vowels (A, E, I, O and U) and the number of consonants (non-vowel letters) in the string.
An example of the input and output is as follows:

Enter a word: programming


Total number of characters : 11
Number of vowels : 3
Number of consonants: 8

(Hint: Assume that the input contains only letters of the alphabet without spaces, and the
length of the string does not exceed 20 characters).

(10 marks)

- THE END –
CSC2203 (F) / CHONG FONG KIM / JAN2017

Vous aimerez peut-être aussi