Professional Documents
Culture Documents
FINAL EXAMINATION
SEMESTER I
SESSION2015/2016
ANSWER SCHEME
CONFIDENTIAL
SECTION A
Expression
Statements
SECTION B
2 CONFIDENTIAL
CONFIDENTIAL BFC 20802
Symbol Answer
Terminal
Process
Comment
On page Connector
Decision
Q2 Write a single C++ statement or line that accomplishes each of the following:
(d)Input four integer values from the keyboard into integer variables a, b, c and d.
cin>> a >> b >> c>> d;
(1 marks)
QX Based on the given flowchart, identify the output of the average of odd numbers from 1
to 9. Construct the algorithm based on the flow chart.
3 CONFIDENTIAL
CONFIDENTIAL BFC 20802
sum = 0
i =1
i < 11
True
sum = sum + i
False
i = i+2
av rg = sum /5
(10 marks)
Statement Function
# include <iostream> Preprocessor Directive
using namespace std;
/ / A typical C++ Program Comment
main ( ) Begin
{ Main function
Variables declaration
…….. ;
Statements;
} End
(5 marks)
cin>>a;
}
(2 marks)
Q6 Write a single C++ statement or line that accomplishes each of the following:
(b) A WHILE loop that will display the numbers from 500 to 550.
while (numbers=>500&& numbers <=550)
(1 marks)
5 CONFIDENTIAL
CONFIDENTIAL BFC 20802
false
(1 marks)
#include <iostream>
usingnamespacestd;
intmain()
{
double hours, rate, pay;
// Get the number of hours worked.
cout<< "How many hours did you work? ";
cin>> hours;
cin>> rate;
6 CONFIDENTIAL
CONFIDENTIAL BFC 20802
#include <iostream>
#include <math.h>
#include <iomanip>
using namespace std;
int main()
{
floatnew_sigma, new_tau, theta, A1, P;
floatcos_value = cos(theta);
floatsin_value = sin(theta);
Q8 cout<<"Enter
Fill in the blank value ofanswer:
with the correct P : \n";
cin>>P; (10 marks)
cout<<"Enter value of A1 : \n";
cin>>A1;
new_sigma=P*cos(theta)*cos(theta)/A1;
cout<<"answer, new_sigma =
\n"<<new_sigma<<"\n"<<"\n";
cin.get ();
new_tau=P*sin(theta)*cos(theta)/A1;
cout<<"Answer, new_tau = \n"<<new_tau<<"\n";
system("PAUSE");
return 0; 7 CONFIDENTIAL
}
CONFIDENTIAL BFC 20802
SECTION C
Instruction: Choose ONE (1) question only.
Q1 Construct i) a pseudo code based on the flowchart (refer to Figure Q1)and write ii) a
complete C++ code which will ask user to travel from Ayer Hitam to southern
inbounds using the PLUS Highway. The program will display the destinations, the toll
rates and distances according to the selection by the user.
Example of Output: refer to Figure Q1.
(30 marks)
Q2 A stone is thrown upwards with an initial velocity (u) of 30 m/s. The maximum peak
the stone could reach is calculated by the following calculation and conditions.
The acceleration, a = g = -9.81 m/s2
v 2−u2 02−302
a) The distance, s= = =45.87 m/s
2a 2 (−9.81 )
Then from the moment the stone is thrown upwards, the time needed for the stone to
retouches the earth surface is calculated according to the following condition
8 CONFIDENTIAL
CONFIDENTIAL BFC 20802
The total time requires for the stone to retouch the surface from the moment it is thrown
upwards is given as 6.12s. Within 6 seconds, the movement of the stone is illustrated as
a quadratic path and the displacement of the stone from the peak is shown in the
following table.
c) By referring the following equation, the calculation for the displacement could
be achieved by using a calculation loop.
1
s=ut+ at 2
2
Construct a pseudo code of a flowchart and write a complete C++ code to calculate
the condition as instructed in a), b) and c). The program will display the distance, time
needed to reach the peak and the displacement of the stone within 6 iterations or
seconds.
(30 marks)
START
-END OF QUESTION –
OUTPUT
"YOU ARE TRAVE LLING F ROM AYE R H ITAM"
OUTPUT
"SE LE CT YOUR DE STIN ATION "
FINAL EXAMINATION
SEMESTER / SESSION :SEM I / 2015/2016 PROGRAMME :2BFF/ 3 BFF
COURSE:COMPUTER PROGRAMMINGCOURSE CODE: BFC20802
P RE SS 1 P RE SS 2 P RE SS 3 P RE SS 4 P RE SS 5 P RE SS 6
MACHAP SIMPANG SE DE NAK KULAIJ AYA SE NAI (U) SKUDAI
RE NGGAM
FIGURE Q1
FINAL EXAMINATION
SEMESTER / SESSION : SEM I / 2015/2016 PROGRAMME: 2BFF/ 3 BFF
COURSE : COMPUTER PROGRAMMING COURSE CODE : BFC20802
TABLE 1
Time (second) Displacement
(meter)
1 25.095
2 40.380
3 45.855
4 41.520
5 27.375
6 3.420
Height (m)
10 CONFIDENTIAL
CONFIDENTIAL BFC 20802
FIGURE Q2
START
OUTP U T
"YOU ARE TRAVE LLING F ROM AYE R H ITAM"
P RE SS 1 P RE SS 2 P RE SS 3 P RE SS 4 P RE SS 5 P RE SS 6
MACHAP SIMPANG SE DENAK KULAIJ AYA SE NAI (U ) SKU DAI
RE NGGAM
ANSWER SECTION C Q1
//Program travel
#include <iostream>
using namespace std;
int main ( ) {
int press;
switch (press) {
case 1
cout<<"FROM AYER HITAM TO MACHAP"<<endl;
cout<<"THE TOLL RATE IS RM 1.20"<<endl;
cout<<"THE MILEAGE WILL BE 7.40 KM"<<endl;
break;
case 2
cout<<"FROM AYER HITAM TO SIMPANG RENGGAM"<<endl;
cout<<"THE TOLL RATE IS RM 3.10"<<endl;
cout<<"THE MILEAGE WILL BE 21.90 KM"<<endl;
break;
case 3
cout<<"FROM AYER HITAM TO SEDENAK"<<endl;
cout<<"THE TOLL RATE IS RM 5.70"<<endl;
cout<<"THE MILEAGE WILL BE 39.20 KM"<<endl;
break;
case 4
cout<<"FROM AYER HITAM TO KULAIJAYA"<<endl;
cout<<"THE TOLL RATE IS RM 7.50"<<endl;
cout<<"THE MILEAGE WILL BE 52.60 KM"<<endl;
break;
case 5
cout<<"FROM AYER HITAM TO SENAI (U)"<<endl;
12 CONFIDENTIAL
CONFIDENTIAL BFC 20802
return 0;
}
PSEUDO CODE
1. Start
2. Read i
3. Input the destination
Destination based on selection
Case 1
Print "YOU ARE TRAVELLING FROM AYER HITAM TO MACHAP"
Print "THE TOLL RATE IS RM 1.20"
Print "THE MILEAGE WILL BE 7.40 KM"
Case 2
Print "YOU ARE TRAVELLING FROM AYER HITAM TO SIMPANG RENGGAM"
Print "THE TOLL RATE IS RM 3.10"
Print "THE MILEAGE WILL BE 21.90 KM"
Case 3
Print "YOU ARE TRAVELLING FROM AYER HITAM TO SEDENAK"
Print "THE TOLL RATE IS RM 5.70"
Print "THE MILEAGE WILL BE 39.20 KM"
Case 4
Print "YOU ARE TRAVELLING FROM AYER HITAM TO KULAIJAYA"
Print "THE TOLL RATE IS RM 7.50"
Print "THE MILEAGE WILL BE 52.60 KM"
Case 5
Print "YOU ARE TRAVELLING FROM AYER HITAM TO SENAI (U)"
Print "THE TOLL RATE IS RM 8.70"
Print "THE MILEAGE WILL BE 61.10 KM"
13 CONFIDENTIAL
CONFIDENTIAL BFC 20802
Q2
int main() {
if (time1 > 0) {
cout<< "Time required to retouch =" << time1 <<endl;
}
else if (time2 > 0) {
cout<< "Time required to retouch =" << time2 <<endl;
}
for(int x = 1; x < 7; x++){
movement = u*x+0.5*(-g)*x*x;
14 CONFIDENTIAL
CONFIDENTIAL BFC 20802
cout<< "The movement for" << x << "second will be" <<endl;
cout<< movement <<endl;
}
return 0;
}
15 CONFIDENTIAL