Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
\
NlV,E'I\51T1
NDIOIl<{\N
I
� ��J������
SULnN IDRIS EDUCATION UNIVERSITY
FINAL EXAMINATION
SEMESTE'R 1 SESSION 2015/2016
INSTRUCTIONS
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.
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
"
CONFIDENTIAL
MTS3013: Structured Programming 2
1. State whether the following statements are TRUE (T) or FALSE (F).
Nyatakan samada setiap penyataan berikut BENAR (B) atau PALSU (P).
(Pernyataan swi tch dan case adalah pernyataan lain untuk menggantikan if
berganda).
c) The while loop is a pre-test loop.
(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]
3. Given the age value of stdA, stdB and stdC variables. Write statements in C++ to
[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)?
[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]
5. Sultan Ahmad Shah Domestic Airport would like to improve the quality of services at the
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.
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).
untuk menjawab 20 soalan. Setiap soalan diberi lima pilihan dan setiap pilihan
mempunyai markah tertentu seperti yang ditunjukkan da/am Jadua/ 1. Kualiti
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;
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
(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]
[2 marks]
# 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;
----------------
//function header
for(int m=Oim<=xim++)
cout«y;
cout«"\n" ;
Program B
[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]
[2 marks]
int Skor_ujian_baru;
int *pjk;
pjk =
&Skor_ujian;
"
cout « "Skor Ujian « *pjk « endl;
*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 +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�]
string nama;
char jantina;
int umur;
} ;
(Dengan merujuk kepada pengisytiharan tersebut, tu/iskan segmen atur cara da/am C++
(a) The declaration of ncdrc_anak variable of a maklumat anak type in order to keep
information for 10 children.
(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]
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
56 89 64 78 90 60 -1
o -
60 2
61 -
70 1
71 -
100 3
[15 marks]
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
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
Kategori Akademik
[15 marks]
END OF QUESTIONS
SOALAN TAMAT