0% found this document useful (0 votes)
38 views14 pages

Final Exam Question Paper FSPK0022 Foc July 2023-2024

Uploaded by

6fgc6xfdnd
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
38 views14 pages

Final Exam Question Paper FSPK0022 Foc July 2023-2024

Uploaded by

6fgc6xfdnd
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 14

FINAL EXAMINATION

SEMESTER JULY, SESSION 2023/2024


COURSE CODE : FSPK 0022

COURSE : FUNDAMENTALS OF COMPUTING

PROGRAMME : UTM FOUNDATION

DURATION : 2 HOURS

DATE : 4TH DECEMBER 2023

INSTRUCTION TO CANDIDATES:
1. This question paper consists of three parts:

PART A: 20 MULTIPLE CHOICE QUESTIONS (10 MARKS)


PART B: 5 STRUCTURED QUESTIONS (50 MARKS)
PART C: 1 PROGRAMMING QUESTIONS (20 MARKS)
TOTAL MARKS: 80 MARKS
2. Answer ALL questions in the answer booklet.

STUDENT NAME:
MATRIC NO:
SECTION:
LECTURER NAME:

WARNING!
Students caught copying/cheating during the examination will be liable for disciplinary actions and
SPACE may recommend the student to be expelled from the study.

This examination question consists of (14) printed pages only including this page.
PART A: MULTIPLE CHOICE QUESTIONS (20 MARKS)
Answer ALL the questions and write the correct answer the answer booklet.

1. Which of the following is NOT a computer language?

A. C
B. Basic
C. UNIX
D. Fortran

2. Keywords in programming also called____________.

A. Operators
B. Preprocessors
C. Punctuation marks
D. Reserved words

3. Which type of codes can be edited?

A. Object
B. Source
C. Library
D. Executable

2
4. What is the output given by the following code fragment?

15 int i = 2;
16 int j = 10;
17 int k = 25;
18 int temp = 0;
19
20 cout << (( i != j ) && (( i > 5) || ( j < 15)) && temp );

A. 0
B. 1
C. True
D. False

5. Given the following output, the first line presents the column for ease of reference.

Which of the following statement will instruct the compiler to display Hello at the
columns as demonstrated above?

A. cout << setfill (10) << “Hello”;


B. cout << setprecision (10) << “Hello”;
C. cout << setiosflag(10) << “Hello”;
D. cout << setw (10) << “Hello”;

6. What is the name of the header file that contains mathematical functions?

A. ctype
B. cmath
C. iomanip
D. iostream

3
7. The possible value for variable response is ‘Y’ or ‘N’. What is the data type that is
suitable for variable response?

A. int
B. char
C. bool
D. String

8. Which of the following is NOT a reserved word in C++?

A. int
B. char
C. three
D. double

9. What is the suitable data type for value 19.54 to be represented?

A. void

B. double

C. int

D. bool

4
10. How many types of looping are there in C++?

A. 1

B. 2

C. 3

D. 4

11. In your opinion, which Loop is faster in C++?

A. For

B. While

C. Do While

D. All work at same speed

12. Which loop is guaranteed to execute at-least once?

A. for loop

B. while loop

C. do-while loop

D. switch

5
13. How many minimum numbers of functions should be represent in a C++ program for its
execution?

A. 0
B. 1
C. 2
D. 3

14. What will be the output of the following C++ code?

#include <iostream>
using namespace std;
int main() {

if (0) {
cout << "Hello";
}
else
{
cout << "Good Bye";
}
return 0;
}

A. Hello
B. HelloGood by
C. Good Bye
D. Compilation Error

6
15. What will be the output of the following C++ code?

#include <iostream>
using namespace std;
int main() {
int n ;
for (n = 5; n < 0; n--)
{
cout << n;
if (n == 3)
break;
}
return 0;
}

A. 543
B. 54
C. 5432
D. 53

16. The following are the advantages of using function EXCEPT

A. It reduces coding time and easy to maintain.


B. The execution time is longer due to call and return.
C. Individual function is easier to be tested and modified.
D. It allows programmers to divide codes into a group of logical blocks.

17. Which of the following statements is TRUE?

A. A void function must have the statement return 0


B. A function allows codes to be reused many times.
C. Only main function can pass data to other functions.
D. A function definition statement is optional.

7
18. Which of the following statement is FALSE about local and global variables?

A. Local variables can only be used inside the function or code block in which they were
declared.
B. Variable declared outside of all functions are called global variables.
C. Global variables can be accessed within any function defined for the program.
D. Only main function can update or change the value of the global variable.

19. Which of the following is the default return value of functions in C++?

A. int
B. char
C. float
D. void

20. What will be the output of the following C++ code?

A. 10
B. 0
C. Error
D. Segmentation fault

-----------------------------------------------------------------------------------------------------------

8
PART B: STRUCTURED QUESTIONS (50 MARKS)

Answer ALL the questions and write the answers on the answer booklet provided.
Use a new page for each question.

QUESTION 1 (10 MARKS)


1. Based on coding fragment for if-else statements below, change and complete to
switch statement. (8 marks)
if - else switch

cout << “Enter gender (F / M):”; cout <<(a)__________________________;


cin >> gender; cin >>(b)___________________________;

if (gender == ‘F’) switch ((c)____________)


cntFemale++; {
else if (gender == ‘M’) case (d)_______: cntFemale++;
cntMale++; (e)__________;
else (f)______ ‘M’ : (g)____________;
cout<<”Invalid input!”; break;
default : cout << (h)____________;

2. Given the code fragment below, what is the output for the following value of uniYear?
(2 marks)
20 switch (uniYear)
21 {
22 case 1: cout<<”Freshman.”<<end1;
23 case 2: cout<<”Sophomore..”<<end1; break;
24 case 3: cout<<”Junior..”<<end1;
25 case 4: cout<<”Senior.”<<end1; break;
26 Default: cout<<”Unrecognized.”;
27 }

Input value for variable uniYear Output


a) 1
b) 6

9
QUESTION 2 (10 MARKS)
1. Convert the following coding fragment into while loop structure. (8 marks)
Without a loop
18 cout << “ Enter a salary: “;
19 cin >> salary;
20 total = total + salary;
21
22 cout << “ Enter a salary: “;
23 cin >> salary;
24 total = total + salary;
25
26 cout << “ Enter a salary: “;
27 cin >> salary;
28 total = total + salary;
29
30 cout << “ Enter a salary: “;
31 cin >> salary;
32 total = total + salary;
33
34 cout << “ Enter a salary: “;
35 cin >> salary;
36 total = total + salary;
37
38 avgSal = total / 5;
39
40 cout << “\nThe average salary is: “;
41 cout << avgSal;

2. What is the output for the coding below and the correct value for variable cnt after
execution? (2 marks)
16 int cnt, total = 0;
17
18 cnt = 1;
19 while (cnt <= 5)
20 {
21 total += cnt;
22 cnt++;
23 }
24 cout << total << endl;

10
QUESTION 3 (10 MARKS)

1. Given the following function definition, complete the missing coding statement.
(8 marks)
16 // Average( )
17 // Accepts three floating point grades as parameters
18 //calculates and returns the average
19
20 float (a)________((b)_______ (c)________, (d)_______ test2, float (e)_________)
21 {
22 (f)________________; // declare avg and the type is float
23 avg = (g)__________________________; // calculate average of 3 tests
24 return (h)____________; //return average
25 }

2. Given the following function definition, write the function calling. (2 marks)
Function Definition Funtion Call
a) 13 float getSqrt (float a)
14 {
15 return sqrt (a);
16 }

b) 13 char grade (float s1, int n1)


14 {
15 Return letter;
16 }

11
QUESTION 4 (10 MARKS)

3. Write a C++ program fragment that converts the currency amount from Malaysian
Ringgit to Indonession Rupiah, Singapore Dollar, Thailand Baht, Brunei Dollar and
Philippine Peso. (10 marks)
a) Function ringgitToRupiah( ) that receives the amount in ringgit as parameter
and returns the equivalent value in rupiah. (Note: 1 ringgit = 3345.40 Rupiah)

b) Function ringgitToSingDollar( ) that receives the amount in ringgit as parameter


and returns the equivalent value in Singapore Dollar. (Note: 1 ringgit = 0.29
Singapore Dollar)

c) Function ringgitToBruneiDollar( ) that receives the amount in ringgit as


parameter and returns the equivalent value in Brunei Dollar. (Note: 1 ringgit =
0.29 Brunei Dollar)

d) Function ringgitToBaht( ) that receives the amount in ringgit as parameter and


returns the equivalent value in Thailand Bhat. (Note: 1 ringgit = 7.65 Baht)

e) Function ringgitToPeso( ) that receives the amount in ringgit as parameter and


returns the equivalent value in Philippine Peso . (Note: 1 ringgit = 11.92 Peso)

12
QUESTION 5 (10 MARKS)

1. Differentiate and give example between local variable and global variable (6 marks)
2. Refer to the C++ code segment below: (4 marks)

#include <iostream>
using namespace std;

int g = 0;
void fun ()
{
int a = 5;
g = g + a;
cout << g << endl;
}
int main ()
{
g = 15;
fun ();
g++;
cout << g << endl;
}

a) What is the output displayed?


b) Give ONE (1) local variable and ONE (1) global variable from the above program.

13
PART C: FULL PROGRAMMING QUESTIONS (20 MARKS)
Instruction: Write a complete C++ Program

Write a complete C++ program that calculate the payment for various fuels at a petrol
stations. This program contains the following:
1) The Function Prototype (3 Marks)
2) The Function Definitions (9 Marks)
(a) Function calcPetrol( ) that receives the amount in liters. Calculate and return the
total costs of petrol.
(b) Function calcDiesel( ) that receives the amount in liters. Calculate and return the
total costs of diesel.
(c) Function calcGas( ) that receives the amount in liters. Calculate and return the total
costs of gas.
3) The Main Function (8 Marks)
A main program that uses the above functions. The user will enter the amount of fuel in
liters and selects the desired fuel type from the following Table 1:
CHOICE FUEL TYPE
1 Petrol
2 Diesel
3 Gas
4 Exit
Table 1: Choice and Fuel Type
The program will compute and display the total cost of fuel purchased. Display the
appropriate message when the user enters any invalid choice. (Note: - 1 liter of petrol:
RM2.85, 1 liter of diesel: RM2.60, 1 liter of gas: RM0.50)

-END OF QUESTION PAPER-

14

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy