universiti malaysia perlis ekt 120 pengaturcaraan...
TRANSCRIPT
SULIT
SULIT
UNIVERSITI MALAYSIA PERLIS
Peperiksaan Semester Pertama
Sidang Akademik 2015/2016
Januari 2016
EKT 120 – Pengaturcaraan Komputer
[Computer Programming]
Masa : 3 jam Duration : 3 hours
Please make sure that this paper has SIXTEEN (16) printed pages including this front page
before you start the examination. [Sila pastikan kertas soalan ini mengandungi ENAM BELAS (16) muka surat yang bercetak termasuk muka
hadapan sebelum anda memulakan peperiksaan ini.]
This question paper has EIGHT (8) questions. Answer ALL questions in SECTION A and
ANY TWO (2) questions in SECTION B. [Kertas soalan ini mengandungi LAPAN (8) soalan. Jawab SEMUA soalan di BAHAGIAN A dan pilih MANA-
MANA DUA (2) soalan di BAHAGIAN B.]
SULIT -2- (EKT120)
SULIT
SECTION A [Bahagian A]
Answer ALL questions in this section. [Jawab SEMUA soalan di bahagian ini.]
Question 1 [Soalan 1]
[C1, CO1, PO1]
(a) State the definition of application software. Give two (2) examples of application software. [Nyatakan definisi sistem aplikasi. Berikan dua (2) contoh sistem aplikasi.]
[5 marks/markah]
[C1, CO1, PO1]
(b) Define selection structure in C programming. [Definisikan struktur pemilihan di dalam pengaturcaraan C.]
[5 marks/markah]
SULIT -3- (EKT120)
SULIT
Question 2
[Soalan 2]
[C2, CO1, PO1, PO2]
(a) Rewrite the switch statement in Figure 2 using if…else if statement. [Tulis semula pernyataan ‘switch’ pada Rajah 2 menggunakan pernyataan ‘if…else if’.]
Figure 2 [Rajah 2]
[5 marks/markah]
[C2, CO3, PO1, PO2]
(b) Write a C program segment which contains loop structure to display these patterns. [Tulis segmen aturcara C yang mengandungi struktur gelung untuk mempamerkan corak berikut.]
&
&&
&&&
&&&&
[4 marks/markah]
[C2, C4, CO1, PO1, PO2]
(c) With the aid of flowchart, compare and explain the difference between while loop and do-
while loop. [Dengan bantuan carta alir, bandingkan dan terangkan perbezaan di antara gelung ‘while’ dan gelung ‘do-
while’.]
[4 marks/markah]
switch (option)
{
case ‘a’: printf (“\nA\n”); break;
case ‘b’: printf (“\nB\n”); break;
case ‘c’: printf (“\nC\n”); break;
case ‘d’: printf (“\nD\n”); break;
default: printf (“\nUnknown\n”);
}
SULIT -4- (EKT120)
SULIT
Question 3 [Soalan3]
[C2, C3, CO3, PO2]
(a) Figure 3a(i) is a program segment. It shows a function call named functionA.
functionA calls function definition in Figure 3a(ii). Identify error(s) and write corrections
of the function definition shown in Figure 3a(ii). [Rajah 3a(i) ialah segmen aturcara. Ia menunjukkan panggilan fungsi bernama functionA. functionA
memanggil definisi fungsi di Rajah 3a(ii). Kenalpasti ralat dan tulis pembetulan fungsi definisi yang
ditunjukkan di Rajah 3a(ii).]
Figure 3a(i) [Rajah 3a(i)]
Figure 3a(ii) [Rajah 3a(ii)]
[3 marks/markah]
int functionA(int x;int y;float z)
{ int total=0;
total += x+y+z;
return total;
}
int a,c;
float b;
printf(”%f”,functionA(a,b,c));
…5/16
SULIT -5- (EKT120)
SULIT
[C2, C3, CO3, PO1, PO2]
(b) Review and predict the output from the program shown in Figure 3b. [Ulangkaji dan ramal keluaran dari aturcara yang ditunjukkan di Rajah 3b.]
Figure 3b [Rajah 3b]
[4 marks/markah]
int z = 5;
void fun1(int, int *, int);
int main( )
{
int a=11, b=9, c=10;
fun1(a, &b, c );
printf(“a = %d\n“,a);
printf(“b = %d\n“,b);
printf(“c = %d\n“,c);
printf(“z = %d\n”, z);
}
void fun1(int p, int *q, int r)
{
p= 21;
*q = *q+3;
r = p + *q;
z = z + 3;
printf(“p = %d\n“,p);
printf(“q = %d\n“,*q);
printf(“r = %d\n“,r);
printf(“z = %d\n”, z);
}
…6/16
SULIT -6- (EKT120)
SULIT
[C5, CO3, PO1, PO2]
(c) A program computes perimeter of a parallelogram by requesting user to enter length in cm
and width in cm. The formula to calculate perimeter of a parallelogram is
perimeter = 2 * (length + width)
[Sebuah aturcara mengira ukur lilit perimeter segiempat selari dengan meminta pengguna memasukkan nilai
dapatan bagi panjang (cm) dan lebar (cm). Formula untuk mengira ukur lilit segiempat selari ialah
ukur lilit = 2 * (panjang + lebar).]
You are required to write two functions definition as follows: [Anda diminta untuk menulis dua definisi fungsi berikut:]
(i) readInput: read input of length and width and pass by reference those two
inputs. [readInput: membaca nilai dapatan bagi panjang dan lebar dengan memulangkan rujukan bagi
kedua-dua dapatan tersebut.]
[3 marks/markah]
(ii) calcPerimeter : accepts length and width in order to calculate perimeter by
passing those two arguments by value and, return calculation of perimeter by
reference. [calcPerimeter : menerima panjang dan lebar untuk mengira ukur lilit dengan memulangkan
nilai bagi kedua-dua argumen dan, memulangkan hasil pengiraan ukur lilit secara rujukan.]
[3 marks/markah]
SULIT -7- (EKT120)
SULIT
[C4, C5, CO3, PO2]
Question 4 [Soalan 4]
Analyze the structures employed to process students name, marks and total marks described in
Figure 4. Given a two-dimensional (2D) array marks stores test1 in first column, test2 in
second column and final exam in last column. [Analisa struktur yang digunakan untuk memproses nama pelajar, markah dan jumlah markah seperti digambarkan
di Rajah 4. Diberi sebuah tatasusunan dua dimensi (2D) marks yang menyimpan ujian1 di lajur pertama, ujian2 di
lajur kedua dan peperiksaan akhir di lajur terakhir.]
studentName marks total
[0] [1] [2]
Figure 4 [Rajah 4]
(a) Declare a two-dimensional (2D) array studentName of type char with maximum
characters of size 40, two-dimensional (2D) array marks of type float and array total
of type float that can store up to 20 students tests performance. [Isytihar tatasusunan dua dimensi (2D) studentName berjenis char dengan bilangan aksara maksimum
bersaiz 40, tatasusunan dua dimensi (2D) marks berjenis float dan tatasusunan total berjenis float
yang boleh menyimpan sehingga 20 prestasi ujian pelajar.]
[3 marks/markah]
(b) Write C statements to read 20 students name to two-dimensional (2D) array studentName
and each student test1, test2 and final exam marks in two-dimensional (2D) array marks
using loop structure. [Tulis pernyataan C untuk membaca 20 nama pelajar ke dalam tatasusunan dua dimensi (2D) studentName
dan setiap markah ujian1, ujian2 dan peperiksaan akhir setiap pelajar ke dalam tatasusunan dua-dimensi (2D)
marks menggunakan struktur gelung.]
[3 marks/markah]
[0]
[1]
…
…
[19]
[0]
[1]
…
…
[19]
[0]
[1]
…
…
[19]
…8/16
SULIT -8- (EKT120)
SULIT
(c) Array total calculates total marks of test1, test2 and final exam from array marks.Write
C statements to calculate total marks of each student using loop structure. [Tatasusunan total mengira jumlah markah ujian1, ujian2 dan peperiksaan akhir dari tatasusunan marks.
Tulis pernyataan C untuk mengira jumlah markah setiap pelajar menggunakan struktur gelung.]
[2 marks/markah]
(d) Write C statements to print contents of array studentName and total using loop
structure. [Tulis pernyataan C untuk mencetak isi kandungan tatasusunan studentName dan total menggunakan
struktur gelung.]
[2 marks/markah]
SULIT -9- (EKT120)
SULIT
[C5, CO3, PO3]
Question 5
[Soalan 5]
DIY Hardware Berhad plans to automate its selling item in order to cater for increasing need of
effective business management. You are required to use array of structure with members defined
as itemID of type long int, array itemName of type char, qty of type int, price of type
float and size of type int. The array of structure is able to store up to 100 items. [DIY Hardware Berhad merancang untuk mengautomasikan item jualan untuk menangani peningkatan keperluan
pengurusan perniagaan yang efektif. Anda dikehendaki menggunakan struktur tatasusunan dengan ahli-ahli yang
didefinisi sebagai itemID berjenis long int, tatasusunan itemName berjenis char, qty berjenis int, price
berjenis float dan size berjenis int.]
Using the requirements mentioned above, write C statements to: [Berdasarkan keperluan di atas, tulis pernyataan C untuk:]
a) Declare array of structure item of type itemType with all of its member. [Isytihar struktur tatasusunan item berjenis itemType dengan semua ahli-ahlinya.]
[4 marks/markah]
b) Read and store in members of array of structure item using loop structure. [Baca dan simpan ahli-ahli di dalam struktur tatasusunan item menggunakan struktur gelung.]
[3 marks/markah]
c) Calculate possible total sales of all current items using loop structure. [Kira kemungkinan jumlah jualan kesemua item terkini menggunakan struktur gelung.]
[3 marks/markah]
d) Print itemID, itemName and size whose quantity is less than 30 and price is less than RM
30.00 using loop structure. [Cetak itemID, itemName dan size yang berkuantiti kurang dari 30 dan berharga kurang dari RM 30.00
menggunakan struktur gelung.]
[4 marks/markah]
SULIT -10- (EKT120)
SULIT
Section B [Bahagian B]
Answer ANY TWO (2) questions in this section. [Jawab MANA-MANA DUA (2) soalan di bahagian ini.]
[C4, C5, CO4, PO1, PO2, PO11]
Question 6 [Soalan 6]
You are required to develop a computer program that helps in generating multiplication tables
for primary school students as described in Figure 6a. It will ask for the number of rows and
columns required for the table and will then automatically generate a multiplication table from
the numbers given and display them to the screen. Your program must use nested loop
structures to generate the table content. The sample output is shown in Figure 6b. Develop the
following requirement to solve the problem: [Anda dikehendaki untuk membangunkan satu aturcara komputer bagi menjana jadual sifir untuk pelajar sekolah
rendah seperti ditunjukkan di Rajah 6a. Ia akan meminta pengguna memasukkan bilangan baris dan lajur yang
dikehendaki dan akan menjana jadual sifir dan memaparkan jadual tersebut ke skrin bergantung kepada nilai yang
dimasukkan. Aturcara anda mesti menggunakan gelung bersarang bagi menjana jadual tersebut. Sampel keluaran
di tunjukkan di Rajah 6b. Bangunkan penyelesaikan anda berdasarkan keperluan di bawah:
1 1 2 3 4 5 6 7 8 9 10
2 2 4 6 8 10 12 14 16 18 20
3 3 6 9 12 15 18 21 24 27 30
4 4 8 12 16 20 24 28 32 36 40
5 5 10 15 20 25 30 35 40 45 50
MULTIPLY
Figure 6a [Rajah 6a]
Figure 6b [Rajah 6b]
Enter the number of rows: 5
Enter the number of columns: 10
1 1 2 3 4 5 6 7 8 9 10
2 2 4 6 8 10 12 14 16 18 20
3 3 6 9 12 15 18 21 24 27 30
4 4 8 12 16 20 24 28 32 36 40
5 5 10 15 20 25 30 35 40 45 50
…11/16
SULIT -11- (EKT120)
SULIT
(a) Create a flowchart to help guide the coding task. [Hasilkan carta alir bagi membantu tugas pengaturcaraan.]
[5 Marks/markah]
(b) Develop the complete C program. [Bangunkan program C yang lengkap.]
[15 Marks/markah]
SULIT -12- (EKT120)
SULIT
[C4, C5, C6, CO3, CO4, PO1, PO2, PO11]
Question 7
[Soalan 7]
A health care issue that has been in the news lately is the computerization of health records. This
possibility is being approached cautiously because of sensitive privacy and security concerns,
among others. Computerizing health records would make it easier for patients to share their
health profiles and histories among their various health care professionals. This could improve
the quality of health care, help avoid drug conflicts and erroneous drug prescriptions, reduce
costs and in emergencies could save lives.
In this question, you are required to design a HealthProfile structure for a person. The structure
members should include the person’s age, height (in meters) and weight (in kilogram). Your
program must have a function that receives this data and uses it to set the members of a
HealthProfile variable. The program must also include a function that calculate and return the
body mass index (BMI), maximum heart rate and target heart-rate range. The sample output is
described in Figure 7.
The following items are required to complete the program:
a) Structure struct HealthProfile
b) Function fnInputData
c) Function fnCalculate
[Isu penjagaan kesihatan yang sering diperkatakan baru-baru ini adalah berkenaan rekod kesihatan berkomputer.
Isu ini ditangani secara berhati-hati disebabkan ia melibatkan privasi dan isu keselamatan. Rekod kesihatan
berkomputer akan mempermudahkan pesakit berkongsi profil kesihatan mereka dengan professional di bidang
penjagaan kesihatan. Ini akan meningkatkan kualiti dalam sektor kesihatan, membantu mengelakkan konflik
pemberian ubat dan salah pemberian ubat-ubatan, mengurangkan kos dan boleh menyelamatkan nyawa dalam kes
kecemasan.
Kamu dikehendaki bagi merekabentuk satu struktur HealthProfile bagi seseorang individu. Ahli struktur ini perlu
merangkumi maklumat umur, tinggi (dalam meter) dan berat (dalam kilogram). Program kamu perlu mempunyai
satu fungsi yang menerima data-data ini dan menggunakannya untuk menetapkan ahli struktur HealthProfile.
Aturcara juga perlu mempunyai fungsi yang melakukan pengiraan dan memulangkan indeks jisim badan (BMI),
kadar degupan jantung maksimum dan julat sasaran degupan jantung. Sampel keluaran di tunjukkan di Rajah 7.
Perkara berikut adalah diperlukan bagi melengkapkan aturcara:
a) Struktur struct HealthProfile
b) Fungsi fnInputData
c) Fungsi fnCalculate ]
…13/16
SULIT -13- (EKT120)
SULIT
Reference: [Rujukan:]
According to the American Heart Association (AHA), the formula for calculating your
maximum heart rate (in beats per minute) is 220 minus your age (in years). Your target heart rate
is a range that is 50–85% of your maximum heart rate. The formula for calculating Body Mass
Index (BMI) is weight / (height * height). The equations are given below:
𝑀𝑎𝑥𝑖𝑚𝑢𝑚 ℎ𝑒𝑎𝑟𝑡 𝑟𝑎𝑡𝑒 = 220 − 𝑎𝑔𝑒 (𝑦𝑒𝑎𝑟𝑠)
𝑀𝑖𝑛𝑖𝑚𝑢𝑚 𝑡𝑎𝑟𝑔𝑒𝑡 ℎ𝑒𝑎𝑟𝑡 𝑟𝑎𝑡𝑒 = 50% 𝑜𝑓 max ℎ𝑒𝑎𝑟𝑡 𝑟𝑎𝑡𝑒
𝑀𝑎𝑥𝑖𝑚𝑢𝑚 𝑡𝑎𝑟𝑔𝑒𝑡 ℎ𝑒𝑎𝑟𝑡 𝑟𝑎𝑡𝑒 = 85% 𝑜𝑓 max ℎ𝑒𝑎𝑟𝑡 𝑟𝑎𝑡𝑒
𝐵𝑜𝑑𝑦 𝑀𝑎𝑠𝑠 𝐼𝑛𝑑𝑒𝑥 (𝐵𝑀𝐼) = 𝑤𝑒𝑖𝑔ℎ𝑡 (𝑘𝑔)
ℎ𝑒𝑖𝑔ℎ𝑡 (𝑚𝑒𝑡𝑒𝑟) ∗ ℎ𝑒𝑖𝑔ℎ𝑡(𝑚𝑒𝑡𝑒𝑟)
[Menurut Persatuan Jantung Amerika (AHA), formula untuk mengira kadar maksima degupan jantung adalah
dengan menggunakan kadar degupan sebanyak 220 degupan/minit ditolak dengan usia pengguna (dalam unit
tahun). Julat sasaran degupan pula dikira dengan meletakkan julat 50% hingga 85% kadar degupan jantung
maksimum (sasaran degupan minima adalah 50% daripada kadar degupan jantung maksima dan sasaran degupan
maksima adalah 85% daripada kadar degupan jantung maksima).
Formula pengiraan Indeks Jisim Badan (BMI) adalah berat / (tinggi * tinggi).]
Figure 7 [Rajah 7]
[20 Marks/markah]
Please enter user's age: 25
Please enter user's height (meters): 2.8
Please enter user's weight (kg): 60
User's height: 2.80 m
User's weight: 60.00 kg
User's maximum heart rate: 195 bpm
User's target heart rate: 98 - 166 bpm
User's BMI: 7.65
Do you wish to continue (Y/N)?
SULIT -14- (EKT120)
SULIT
[C4, C5, C6, CO3, CO4, PO1, PO2, PO11]
Question 8
[Soalan 8]
Air Pollution Index (API) is a simple and generalized way to describe air quality. It is calculated
from a several set of air pollution data which consists of four index pollutant components
(carbon monoxide, ozone, nitrogen dioxide and sulfur dioxide). The index also considers
particulate matter in the index.
You are tasked in developing a program to analyze the API reading for an area. The program will
read 10 API reading from a file named APIreading.txt as described in Figure 8a and stores
them in an array named aiAPIReading. The program will then calculate the lowest and highest
reading together with the average API from the reading. It will then classify the air pollution
level according to the average API calculated. All the API reading must be stored in an array
named aiAPIReading.
[Indeks Pencemaran Udara (IPU) merupakan satu teknik klasifikasi umum dan mudah bagi menggambarkan kualiti
udara. Ia dikira daripada beberapa set data yang merangkumi komponen indeks pencemaran (yang terdiri daripada
karbon monoksida, ozon, nitrogen dioksida dan sulfur dioksida). Indeks ini juga mengambil kira kandungan zarah
terampai di dalam udara.
Kamu ditugaskan bagi membangunkan satu program bagi mengira bacaan IPU bagi satu kawasan. Program
tersebut akan membaca 10 bacaan API dari satu fail input bernama APIreading.txt seperti ditunjukkan di Rajah 8a
dan menyimpan bacaan tersebut di dalam satu tatasusunan bernama aiAPIReading. Aturcara tersebut akan
mengira bacaan terendah dan bacaan tertinggi bersama purata bacaan API dari set data tersebut. Program
tersebut kemudian akan memberikan klasifikasi pencemaran udara bergantung kepada purata bacaan yang telah
dikira. Kesemua bacaan IPU yang diberikan perlu disimpan di dalam tatasusunan bernama aiAPIReading.]
Figure 8a [Rajah 8a]
105
150
98
86
91
209
270
123
132
109
…15/16
SULIT -15- (EKT120)
SULIT
Figure 8b [Rajah 8b]
Table 8 [Jadual 8]
API Air Pollution Level
0 - 50 Good
51 - 100 Moderate
101 - 200 Unhealthy
201 - 300 Very Unhealthy
301 - 500 Hazardous
500+ Emergency
Evaluate the given requirement, sample output in Figure 8b and air classification in Table 8 and
develop a C program to solve the problem. [Dengan mengambilkira keperluan yang diberi, contoh keluaran di Rajah 8b dan jadual klasifikasi pencemaran
udara di Jadual 8, bangunkan satu aturcara C bagi menyelesaikan masalah yang diberikan.]
[20 Marks/markah]
-oo0oo-
API reading = [105] [150] [98] [86] [91] [209] [270] [123] [132] [109]
Lowest reading: 86
Highest reading: 270
Average API = 137.30
Air quality : UNHEALTHY
SULIT -16- (EKT120)
SULIT
Course Outcomes (COs)
CO1 Ability to define and describe programming concepts and principles.
CO2 Ability to apply GNU/Linux for coding, compiling, executing and debugging
computer programs.
CO3 Ability to analyze and solve engineering related problems using computer
programming techniques.
CO4 Ability to evaluate programming techniques and tools to design computer programs.
Program Outcomes (POs)
PO 01 Ability to acquire and apply knowledge of mathematics, science, engineering and an
in-depth technical competence in computer engineering discipline to solve the
complex engineering problem
PO 02 Ability to identify, formulate and solve complex engineering problems.
PO 03 Ability to design solutions for complex engineering problems and systems,
components or processes to meet desired needs.
PO 04 Ability to conduct investigation into complex problems as well as to analyze and
interpret data.
PO 05 Ability to use techniques, skills and modern engineering tools necessary for complex
engineering practices so as to be easily adaptable to industrial needs.
PO 06 Understanding of the social, cultural, global and environmental responsibilities of a
professional engineer.
PO 07 Ability to have entrepreneurship, the process of innovation and the need for
environmental and sustainable development.
PO 08 Ability to understand the professional and ethical responsibilities and commitment to
the community.
PO 09 Ability to function on multi-disciplinary teams.
PO 10 Ability to communicate effectively on complex engineering activities with the
engineering community and with society at large
PO 11 A Recognition of the need for, and an ability to engage in life-long learning
PO 12 Demonstrate the understanding of project management and finance principles