Download as pdf or txt
Download as pdf or txt
You are on page 1of 3

SSK3100_Final (A)_First Semester 2020/2021_Question 5 Matric Number:____________

FACULTY OF COMPUTER SCIENCE AND INFORMATION TECHNOLOGY

ONLINE TEST
SET A : QUESTION 5
FINAL EXAMINATION
FIRST SEMESTER 2020/2021

COURSE NAME : COMPUTER PROGRAMMING I

CODE : SSK3100

DATE : 22 FEBRUARY 2021


SUBMISSION TIME : 3:30 - 4:50 PM

INSTRUCTIONS :
1. This paper consists of ONE (1) question.
2. Answer all the questions.
3. The full mark for this paper is 40 marks.

1
SSK3100_Final (A)_First Semester 2020/2021_Question 5 Matric Number:____________

SOALAN 5: Atur Cara Lengkap / QUESTION 5: Full Program [10M]

Anda dikehendaki menulis satu atur cara untuk mengira bilangan elemen di dalam
satu senarai nombor perpuluhan yang mempunyai nilai lebih besar daripada nilai
purata nombor perpuluhan tersebut. Untuk menyelesaikan masalah ini, anda perlu
menulis metod-metod berikut:
1) metod readNumOfElem(input) meminta pengguna memasukkan bilangan
nombor perpuluhan yang akan diterima oleh atur cara melalui konsol. Metod ini
menerima pemboleh ubah rujukan bernama input untuk tujuan membaca
bilangan tersebut. Metod ini memulangkan bilangan nombor perpuluhan
tersebut.

2) metod readNumbers(input,numOfElem) meminta pengguna memasukkan


nombor perpuluhan yang akan disimpan di dalam satu tatasusunan bersaiz
bilangan nombor perpuluhan iaitu numOfElem. Metod ini menerima pemboleh
ubah rujukan bernama input untuk membaca nombor perpuluhan tersebut.
Metod ini memulangkan tatasusunan yang telah diisi dengan nombor perpuluhan
yang telah diinput melalui konsol.

3) metod calcAverage(numArray) mengira purata nombor perpuluhan yang


terdapat di dalam tatasusunan numArray. Metod ini memulangkan nilai purata
tersebut.

4) metod countAboveAverage(numArray, average) mengira bilangan elemen di


dalam tatasusunan numArray yang lebih besar daripada nilai average. Metod
ini memulangkan bilangan elemen tersebut.

5) metod printResult(average, count) memaparkan output nilai purata dan


bilangan elemen yang lebih besar daripada nilai purata seperti berikut:

Jawab soalan berikut:


a) Hasilkan carta IPO bagi masalah di atas.
[CPS8][10M]

b) Lukiskan carta alir bagi metod calcAverage and countAboveAverage.


[CPS8][10M]

c) Tuliskan atur cara lengkap untuk masalah di atas dengan menggunakan


bahasa pengaturcaraan Java.

2
SSK3100_Final (A)_First Semester 2020/2021_Question 5 Matric Number:____________

[CPS4][20M]

You are required to write a program to count the quantity of elements in a list of
floating-point numbers that is larger than the average value of the floating-point
numbers. To solve this problem, you need to write the following methods:
1) readNumOfElem(input) – the method asks the user to enter the quantity of
floating-point numbers via console. This method receives a reference variable
named input for the purpose of reading the quantity. This method returns the
quantity of floating-point numbers.
2) readNumbers(input,numOfElem) - the method asks the user to enter
floating-point numbers that will be stored in an array. The length of the array is the
same value as the quantity of floating-point numbers which is numOfElem. This
method receives a reference variable named input for reading the floating-point
numbers. This method returns the array filled with the floating-point numbers
inputted.
3) calcAverage(numArray) - the method calculates the average of the floating-point
numbers in numArray array. This method returns the average.
4) countAboveAverage(numArray, average) - the method counts the number of
elements in numArray array greater than the average value. This method returns
the number of elements.
5) printResult(average,count) – the method displays the following output values for
the average and the number of elements greater than average :

Answer the following question:


a) Produce an IPO chart for the problem above.
[CPS8][10M]

b) Draw flowcharts for calAverage and countAboveAverage methods.


[CPS8][10M]

c) Write a complete program for the problem above using Java.


[CPS4][20M]

Jawapan/Answer:

You might also like