Está en la página 1de 4

CONFIDENTIAL

UNIVERSITI TUN HUSSEIN ONN MALAYSIA

TEST I
SEMESTER II
SESSION 2017/2018
(ANSWER SCHEME)

COURSE NAME : COMPUTER PROGRAMMING


COURSE CODE : BFC 20802
PROGRAMME : BFF
EXAMINATION : 26TH OCTOBER 2017
DATE
DURATION : 1 HOURS
INSTRUCTION : ANSWER ALL QUESTIONS

THIS QUESTION PAPER CONSISTS OF EIGHT (8) PAGES

CONFIDENTIAL
CONFIDENTIAL BFC 20802

Q1 Determine the types of programming elements according to the provided examples.

Programming elements Examples


Pre-processor directive <iostream>
Keyword cout
Variable int_main
Integer 23

(2 marks)

Q2 Given that: x=3, y=4, and z=2; What is the value of each of the following
expression? All variables are declared in int data type, including the output variable.

Expression Answer
x*z+y-x 8
pow(z,y)+y*x 28
5*y%x*3*z 12
sqrt(y*z*3*x*11) 28

(8 marks)

Q3 Explain the followings questions:

a) Explain how computer run a program.


(2 marks)

b) Describe the definition of pseudocode.


(2 marks)

c) Give FOUR (4) examples of stream manipulator, including their function.


(4 marks)

d) Differentiate between the prefix and postfix mode with the examples.

(4 marks)

2 CONFIDENTIAL
CONFIDENTIAL BFC 20802

Q4 Write a correct C++ expression using pre-function from math library (cmath or math.h)
that are equivalent to the following equation.

Ix  Iy  Ix  Iy
2

a) I min      I xy2
2  2 
1 2
b) u
2E
(a 2  b 2 )TL
c) 
a 3b 3G
1  sin x cos x
d) 
cos x 1  sin x
 1.00 2

e) Q   AR 3 S 
 n 

(5 marks)

3 CONFIDENTIAL
CONFIDENTIAL BFC 20802

Q5 Complete the program segment with appropriate command by applying switch statement.
Program need to be able to operate on two operands. The output of program should be as
Figure Q5.

//if and else program


#include <iostream>
using namespace std;

int main()
{
char a;
float num1, num2;

cout << "Enter an operator (+, -, *, /): ";


cin >> a;

switch (a)
{
case '+':
cout << num1 << " + " << num2 << " = " << num1+num2;
break;
case '-':
cout << num1 << " - " << num2 << " = " << num1-num2;
break;
case '*':
cout << num1 << " * " << num2 << " = " << num1*num2;
break;
case '/':
cout << num1 << " / " << num2 << " = " << num1/num2;
break;

default:
// operator is doesn't match any case constant (+, -,
// *, /)
cout << "Error! operator is not correct";
break;

return 0;

(8 marks)

- END OF QUESTION -

4 CONFIDENTIAL

También podría gustarte