CONFIDENTIAL
\
NlV,E'I\51T1
NDIOIl<{\N
I
� ��J������
SULnN IDRIS EDUCATION UNIVERSITY
UNIVERSITI PENDIDIKAN SULTAN lORIS
FINAL EXAMINATION
SEMESTE'R 1 SESSION 2015/2016
CODE : MTS3013 COURSE STRUCTURED PROGRAMMING
TIME 2 HOURS 30 MINUTES
DATE: 3 0 DEC 2015 :
INSTRUCTIONS
1. This question paper has TWO (2) sections: A and B.
2. Section A has EIGHT (8) structured questions, Answer ALL questions in booklet
provided.
3, Section B has TWO (2) essay questions. Answer only ONE (1) question in booklet
provided,
4, Candidates are not allowed to take the examination paper out from the examination hall.
This question paper contains 11 pages including cover page
PROGRAMME
YEAR GROUP:
MA TRIC NUMBER :
I I I I I I I I I I I I I
IC NUMBER :
I I I I I I I I I I I I I
"
LECTURER . PROF. MADYA DR. NOR HAS BlAH UBAIDULLAH
DO NOT OPEN THIS QUESTION PAPER UNTIL YOU ARE TOLD TO DO 50
CONFIDENTIAL
MTS3013: Structured Programming 2
SECTION A: (65 marks)
Instruction: Answer all questions in the answer booklet provided.
Arahan : Jawab semua soalan di dalam buku jawapan yang disediakan.
1. State whether the following statements are TRUE (T) or FALSE (F).
Nyatakan samada setiap penyataan berikut BENAR (B) atau PALSU (P).
a) Digit, character and underscore can be used in naming an identifier.
(Nombor, aksara dan underscore boleh digunakan dalam menamakan pencam).
b) switch and case statement is an alternative statement to replace multiple if .
(Pernyataan swi tch dan case adalah pernyataan lain untuk menggantikan if
berganda).
c) The while loop is a pre-test loop.
(Gelung while adalah gelung ujian-pra).
d) Each variable must be declared before it can be used in a program.
(Setiap pembolehubah mesti diisytihar sebelum ia boleh digunakan dalam satu atur
cara).
e) The subscript of the last element in a single-dimensional array must end with zero.
(Subskrip bagi elemen terakhir dalam tatasusunan satu dimensi mesti berakhir
dengan kosong).
[5 marks]
2. Given the identifiers below. State whether the identifier is valid or not. If it is invalid state
the reason.
(Oiberi pencam berikut. Nyatakan sama ada pencam tersebut sah atau tidak sah. Jika
nyatakan elesen).
a) _alamat&baru
b) alamat_lama
c) $cgpa
[5 marks]
[see next page
MTS3013: Structured Programming 3
3. Given the age value of stdA, stdB and stdC variables. Write statements in C++ to
identify the youngest age among them.
(Oiberi ni/ai umur bagi pembo/ehubah stdA, stdB dan stdC. Tulis pernyataan da/am
C++ untuk mengena/ pasti umur termuda da/am ka/angan mereka).
[5 marks]
4. (a) If the user input the code 1, what is the ouput of the following program
segment?
(Sekiranya pengguna memasukkan kod 1, apakah output bagi keratan atur cara
berikut)?
cout« "enter the code: (1-5)";
cin» code;
switch (code) {
case 1: cout « "\n aliran sains";
case 2:
case 3: cout « "\n aliran akaun";
case 4:
case 5: cout « "\n aliran sastera";break;
[5 marks]
(b) Trace and give the output of the following program segment.
(Surih dan berikan output bagi keratan atur cara di bawah).
int i,j;
for (i=l; i<=5;i++)
{
for(j=l;j<=i;j++)
cout«"\t"«j;
cout«endl;
[5 marks]
[see next page
MTS3013: Structured Programming 4
5. Sultan Ahmad Shah Domestic Airport would like to improve the quality of services at the
airport. Therefore, the management decided to do a survey among the passengers at
the airport. There is N number of passengers has been randomly chosen to answer 20
questions. There are five choices for every questions and each choice is given a certain
mark as shown in Table 1. The quality of the services will be based on the average of
the questionaire marks and the marks range for each level of service is shown in Table
2.
Choices Marks Marks Range Service Quality
A 5
B 4 4<mark<=5 Exellence
C 3 3<mark<=4 Good
D 2 2<mark<=3 Moderate
E 1 <=2 Poor
Table 1 Table 2
Program A shows an appropriate solutions to calculate and print the result of service
that the airport provided. However, the program has a few logic errors and you are
required to analyze the program to answer questions 5(a), 5(b) and 5(c).
(Lapangan Terbang Oomestik Sultan Ahmad Shah ingin meningkatkan mutu
perkhidmatan yang disediakan di lapangan terbang tersebut. Sehubungan dengan itu,
pihak pengurusan bercadang menjalankan kaji soal selidik di kalangan penumpang di
lapangan terbang tersebut. Seramai N orang penumpang telah dipilih secara rawak
untuk menjawab 20 soalan. Setiap soalan diberi lima pilihan dan setiap pilihan
mempunyai markah tertentu seperti yang ditunjukkan da/am Jadua/ 1. Kualiti
perkhidmatan adalah berdasarkan markah purata keseluruhan yang diperolehi yang
mana julat markah bagi setiap tahap kualiti adalah seperti ditunjukkan dalam Jadua/ 2.
[see next page
MTS3013: Structured Programming 5
Pilihan Markah Julat Markah Kualiti Servis
A 5
B 4 4<markah<=5 Cemerlang
C 3 3<markah<=4 Baik
D 2 2<markah<=3 Sederhana
E 1 <=2 Lemah
Jadual1 Jadual2
Atur cara A menunjukkan penye/esaian untuk mengira dan seterusnya mencetak hasil
keputusan mutu perkhidmatan yang disediakan o/eh /apangan terbang tersebut. Walau
bagaimana pun, atur cara ini mempunyai kesilapan logik dan anda dikehendak;
mengkaji atur cara in; untuk menjawab soalan 5(a), 5(b) dan 5(c).
#include <iostream.h>
void main ()
int passengernum,N,mark,totali
float average;
char grade;
cout «"Please enter number of passengers";
cin»N;
for (passengernum=O;passengernum<Nipassengernum++)
II section to enter the choice for each question
cout«"\n Please enter the grade";
cin»grade;
II section to calculate total mark
if(grade=='A')total+=5;
else if(grade=='B')total+=4;
else if(grade=='C')total+=3;
else if(grade=='D')total+=2;
else if(grade=='E')total+=l;
average=total/20;
cout«"The average mark of the services for the airport
is"«averagei
Program A
[see next page
MTS3013: Structured Programming 6
(a) You are required to identify the logic errors and state the effects to the program
output.
(Anda dikehendaki mengenal pasti ralat logik tersebut dan dan kesannya pada
output atur cara).
[4 marks]
(b) Complete the program and correct the error by rewriting the correct statements.
(Lengkapkan atur cara dan betulkan ralat tersebut dengan menulis semula
penyataan yang betul).
[4 marks]
(c) If N number of passengers is changed to few passengers, what is the most
suitable type of loop structure should be used. Justify your answer.
(Sekiranya N orang penumpang ditukar ke beberapa orang penumpang, struktur
kawalan manakah yang paling sesuai digunakan. Berikan justifikasi anda).
[2 marks]
6. Analyze Program B to answer questions 6(a), 6(b), 6(c) and 6(d).
(Analisis Program B untuk menjawab soalan 6(a), 6(b), 6(c) dan 6(d).
# include <iostream.h>
______________________
;//prototype function
void main ()
{int num=O;
while (num<==lO)
if (num%3==O)
, * I
cetak (num, ) ;
else if (num%3==1)
I
cetak (num%3, @ ') ;
else
cetak (num%3, '# ') ;
num+=3;
[see next page
MTS3013: Structured Programming 7
----------------
//function header
for(int m=Oim<=xim++)
cout«y;
cout«"\n" ;
Program B
(a) What are the scope of variables num, m, x and y?
(Apakah skop bagi pembolehubah num, m, x dan y )?
[2 marks]
(b) Write the function prototype and function header statements for this program.
(Tuliskan penyataan untuk prototaip fungsi dan kepala fungsi bagi program ini).
[2 marks]
(c) How many times function calls statements are executed?
(8erapa kalikah penyataan panggilan fungsi dilaksanakan)?
[2 marks]
(d) What is the output of the Program 8 ?
(Apakah output bagi Program B)?
[4 marks]
7. Trace and give the output of the following program segment.
(Surih dan berikan output bagi keratan atur cara berikut).
(a) int Skor_ujian =
94;
int Skor_ujian_baru;
int *pjk;
pjk =
&Skor_ujian;
"
cout « "Skor Ujian « *pjk « endl;
[see next page
MTS3013: Structured Programming 8
*pjk =
*pjk + 2;
Skor_ujian_baru =
*pjk;
eout «"Skor Ujian ialah:= "«
Skor_ujian «endl;
eout « "Skor Ujian Baru ialah: =
"
«Skor_ujian_baru «
endl;
[4 marks]
(� string *perkataan;
perkataan =new string[3];
*
perkataan ="1";
*( perkataan +l)="LOVE";
*( perkataan +2)="PROGRAMM1NG";
*
*( perkataan +1)= perkataan;
*( perkataan +2)= *( perkataan +1);
*
perkataan =
*( perkataan+2);
eout«* perkataan «"\t"«*( perkataan +l)«"\t"«
*( perkataan +2);
[4 marks]
(e ) int e, a =
22, b =
66 ;
int *ptl =
&a, *pt2 =
&b;
cout«a«" "«b«endl;
c =
*pt2;
*pt2= *pt1;
*pt1=c;
cout«a«" "«b;
[2 mark�]
[see next page
MTS3013: Structured Programming 9
8. A declaration of maklumat_anak structure is shown below.
(Pengisytiharan bagi struktur maklumat_anak ditunjukkan di bawah).
struct maklumat anak
string nama;
char jantina;
int umur;
int tahun lahir;
} ;
By referring to the above declaration, write a program segment in C++ for
thefollowing statements:
(Dengan merujuk kepada pengisytiharan tersebut, tu/iskan segmen atur cara da/am C++
untuk pernyataan berikut):
(a) The declaration of ncdrc_anak variable of a maklumat anak type in order to keep
information for 10 children.
(Pengisytiharan pembo/ehubah ncdrc anak berjenis maklumat anak untuk
menyimpan mak/umat 10 orang kanak-kanak).
[2 marks]
(b) main () function to input data into the ncdrc anak variable in 8(a) and to output data
from ncdrc anak variable in 8(a).
(Fungsi ma in () untuk menginput data ke da/am pembo/ehubah ncdrc _
ana k da/am
8(a} dan mengoutput data daripada pembo/ehubah ncdrc anak da/am 8(a}}.
[8 marks]
[see next page
MTS3013: Structured Programming 10
SECTION B: (15 marks)
Instruction: Answer only ONE (1) question in the answer booklet provided.
Arahan : Jawab hanya SA TV (1) soalan di dalam buku jawapan yang disediakan.
Question 1
Write a program in C++ that will read a daily everage temperature in a particular month. User is
required to key in a month and a year as input. User is also required to key in a value of daily
temperature that will terminate when a sentinel value which is -1 is entered. The following is the
example of the program output.
(Tulis satu atur cara dalam C++ yang akan membaca purata suhu harian dalam suatu bulan
tertentu. Pengguna dikehendaki memasukkan nilai bulan dan tahun sebagai input. Pengguna
juga dikehendaki memasukkan nilai suhu harian yang akan berakhir bila nilai sentinel iaitu -1
dimasukkan. Berikut adalah contoh output bagi atur cara).
Sila masukkan bulan dan tahun 2 2002
Sila masukkan purata suhu harian diakhiri dengan -1
56 89 64 78 90 60 -1
Laporan suhu bulanan bagi bulan Februari tahun 2002
Bilangan data yang dibaca : 6
Julat suhu Bilangan hari
o -
60 2
61 -
70 1
71 -
100 3
Atur cara tamat
[15 marks]
[see next page
MTS3013: Structured Programming 11
Question 2
Universiti AM has 150 staffs which consist of an academic and a non academic categories.
Each staff is given an option to select either a PENSION ON 56 YEARS scheme or a PENSION
ON 60 YEARS scheme. Display the details of each staff information and the total number of
academic staffs and non academic staffs that have selected a PENSION ON 56 YEARS
scheme and a PENSION ON 60 YEARS scheme. You are required to get an output as shown
below. Use an array to solve this problem.
Universiti AAA mempunyai 150 kakitangan yang terdiri dari kategori akademik dan bukan
akademik. Setiap kakitangan diberi pilihan untuk memilih sama ada skim PENCEN PADA
UMUR 56 atau pun skim PENCEN PADA UMUR 60. Paparkan maklumat setiap kakitangan
dan bilangan kakitangan akademik dan bukan akademik yang memilih skim PENCEN PADA
UMUR 56 dan juga skim PENCEN PADA UMUR 60. Anda dikehendaki mendapatkan output
seperti yang ditunjukkan bawah. Gunakan tatasusunan untuk menyelesaikan masalah ini.
Maklumat Kakitangan
Nama Nokp Umur Kategori Skim
Laporan skim yang dipilih
Kategori Akademik
PENCEN PADA UMUR 56
PENCEN PADA UMUR 60
Kategori Bukan Akademik
PENCEN PADA UMUR 56
PENCEN PADA UMUR 60
[15 marks]
END OF QUESTIONS
SOALAN TAMAT