Documentos de Académico
Documentos de Profesional
Documentos de Cultura
TEST I
SEMESTER II
SESSION 2017/2018
(ANSWER SCHEME)
CONFIDENTIAL
CONFIDENTIAL BFC 20802
(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)
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.
int main()
{
char a;
float num1, num2;
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