Beruflich Dokumente
Kultur Dokumente
(8 marks)
a) Name the two levels of programming languages and what is the major difference
between them.
ANSWER
Low-level: close to machine language
High-level: close to human language
(2 marks)
-11- SULIT
(BITP 1113) SULIT
iii. You cannot use any of the C++ __keywords/reserved words__ as an identifier.
b) CIRCLE the correct answer in the table below for questions (i) to (x).
ANSWER
i. A B C D
ii. A B C D
iii. A B C D
iv. A B C D
v. A B C D
vi. A B C D
vii. A B C D
viii. A B C D
iv. A B C D
x. A B C D
-12- SULIT
(BITP 1113) SULIT
i. What is the correct value to return to the operating system upon the successful
completion of a program?
A. -1
B. 1
C. 0
D. Program do not return a value.
ii. What punctuation is used to signal the beginning and end of code blocks?
A. { }
B. -> and <-
C. BEGIN and END
D. ( and )
iv. What is (are) the C++ command to take the cursor to the beginning of the next
line?
A. newline
B. \n
C. endl
D. B and C
-13- SULIT
(BITP 1113) SULIT
A. 31.0
B. 31
C. 31.00
D. Error
-14- SULIT
(BITP 1113) SULIT
int main()
{
int x = 5, y = 10, z = 2;
cout << x << ' ' << y << ' ' << z << endl;
printNumber (x, y, z);
cout << x << ' ' << y << ' ' << z << endl;
return 0;
}
(10 marks)
ANSWER
5 10 2 (3M)
10 30 -20 (3M)
10 30 2 (4M)
-15- SULIT
(BITP 1113) SULIT
b) Find and fix the error of the following program based on the output given:
Output
(5 marks)
ANSWER
-16- SULIT
(BITP 1113) SULIT
switch (x)
{
case 0:
x = 2;
y = 3;
case 1:
x = 4;
break;
default:
y = 3;
x = 1;
}
(6 marks)
ANSWER
x = 4, y = 3, z = 1 2m each = 6m
-17- SULIT
(BITP 1113) SULIT
if (selection == 1)
cout << "PI times radius squared\n";
else if (selection == 2)
cout << "Length times width\n";
else if (selection == 3)
cout << "PI times radius squared times height\n";
else if (selection == 4)
cout << "Well okay then, good bye!\n";
else
cout << "Not good with numbers, eh?\n";
return 0;
(9 marks)
ANSWER
-18- SULIT
(BITP 1113) SULIT
Based on the Pseudocode as shown below, design the possible solution for the problem by
using flowchart. The design must have one function; calculateCost().
(10 marks)
-19- SULIT
(BITP 1113) SULIT
ANSWER
Start calculateCost(p,
num, l, w)
totalCost = totalBathArea * p
totalCost< 5000
no
yes
return totalCost
Display message Bathroom tile
installation is Successful
End
-20- SULIT
(BITP 1113) SULIT
QUESTION 2 (5 MARKS)
Complete the following skeleton by writing appropriate selection statement that displays:
One if the user has entered 1
Two if the user has entered 2
Three if the has entered 3
If a number other that 1, 2 or 3 is entered, the program should display an error message.
void display_number()
{
int usernum;
cout << "Enter one number: ";
cin >> usernum;
if (usernum == 1) 1.5m
cout<<"One\n";
else if (usernum == 2) 1.5m
cout<<"Two\n";
else if (usernum == 1) 1m
cout<<"One\n";
else
cout<<"Error!\n"; 1m
}
(5 Marks)
-21- SULIT
(BITP 1113) SULIT
Refer to Figure 1. Write a program to ask a user to enter a value of a radius in main() function.
The value is pass to function perimeter() to calculate the perimeter of a circle. The
perimeter of a circle is given by the formula of 2 x PI x radius. Also, pass the radius to function
area() to calculate the area of a circle. An area of a circle is given by the formula of PI x
radius2. Next, pass both answers to function display() to print the results. The PI is define
as a constant variable of 3.142 and the value for radius must be greater than zero. If user enters
value less than zero, prompt an alert statement and end the program.
Perimeter = 2 x pi x r
Area = pi x r 2
Figure 1.
(15 marks)
-22- SULIT
(BITP 1113) SULIT
ANSWER
#include<iostream>
#define PI 3.142
using namespace std;
double perimeter(double);
double area (double);
void display (double,double);
void main()
{
double r,p,a;
double perimeter(double r)
{
double a= 2*PI*r;
return a;
}
-END-
-23- SULIT