Professional Documents
Culture Documents
Contoh2 Soalan Chapter1 and 2 - 1
Contoh2 Soalan Chapter1 and 2 - 1
Exercises:
Chapter 1 and Chapter 2
PART1 :
1. Which of the following is NOT a high level programming language?
A. Machine Language
B. Java
C. Pascal
D. C++
2. A/An _________ is a program that translates the source code into object code.
A. editor
B. linker
C. operating System
D. compiler
3. Missing a colon (:) at the end of the if statement will cause a ______ error.
A. logic
B. syntax
C. runtime
D. typing
A. i and ii
B. i and iv
C. ii and iii
D. ii and iv
PAGE \* MERGEFORMAT 1
Copyright©Zainab Othman
6. Which of the identifiers are VALID?
i. 1001Night
ii. distanceInKM
iii. my_name
iv. RM109.00
A. i and ii
B. ii and iii
C. i, ii and iii
D. ii, iii and iv
int x = 3, y = 5, z = 2;
cout<< (x % y + y * z * z % 6);
A. 5
B. 3
C. 2
D. 0
8. Which of the following describes the activities done in the design phase in the
Software Development Life Cycle (SDLC)?
9. Listed below are the three common types of error while constructing a program,
EXCEPT
A. logic error
B. parsing error
C. run-time error
D. syntax error
PAGE \* MERGEFORMAT 1
Copyright©Zainab Othman
10. Identify which of the following statements are TRUE about comments in C++.
I. A single line comment begins with the symbol / / and continues to the end of
the line.
II. Block comments begin the symbol /and end with the symbols /.
III. Comments are placed in the program to improve its readability.
IV. Comments can be placed anywhere within a program and they will not be
executed by the compiler.
11. Choose the BEST elaboration for the given statement written in C++.
A. It declares a variable of type float and assigns the variable to an initial value of
2.71
B. It declares a variable to store any number with the name LENGTH.
C. It defines a constant of type float named LENGTH with value of 2 . 7 1.
D. It defines a variable named LENGTH and assigns the variable with an initial
value Of 2.71
PAGE \* MERGEFORMAT 1
Copyright©Zainab Othman
A. Translator
B. Editor
C. Interpreter
D. Compiler
16. What are the processes involve in Program Development Life Cycle?
17. There are three main sections to do the algorithm. What is the section that required
to accomplish the task?
A. Processing
B. Output
C. Input
D. flowchart
PAGE \* MERGEFORMAT 1
Copyright©Zainab Othman
PART2 :
1. What is a correct syntax to output "Hello World" in C++?
b. Calculate the total of five numbers. The first three numbers are 34, 92 and
55 .
c. Calculate the total area and volume of a cylinder with diameter 14.5m.
area = [ s(s-a)(s-b)(s-c)]
where s = a + b + c
2
a, b and c are triangle measurements.
e. Calculate the total commission for the first six months that will be paid to En
Halim. En Halim is a salesman in Syarikat ABC. The company pays monthly
commission based on the monthly sales. The commission rate is 5% of
monthly sales.
f. Calculate the net salary for a worker. The net salary is the different of gross
salary and total deduction. The gross salary is the total of basic salary and
total allowances. The allowances are housing allowance, telephone
allowance and transportation. The allowance are RM500, RM700 and
RM750. The worker has to contribute to EPF deduction 9% of gross salary
and contribution for SOCSO 2% of gross salary.
PAGE \* MERGEFORMAT 1
Copyright©Zainab Othman
Total loan = loan amount + total interest
Total interest = 2 * loan amount * 2% + 13 * loan amount * 5%
Loan amount = price of the house – deposit
6. Write a program that takes as input the purchase price of an item (P), its
expected number of years of service (Y) and its expected salvage value (S).
Then outputs the yearly depreciation for the item (D). Use the formula: D = (P - S)
Y.
PAGE \* MERGEFORMAT 1
Copyright©Zainab Othman
vi) Display the total salary including the allowance.
10. Write a C++ assignment statement for each of the following algebraic equations:
i) E= MC2 a(rn-1)
ii) Sum = 2r + 1 + 15e
iii) P = 4m – n
iv) A = 2x2 + 4x + 2y2
v) C = 34x + 4(32x)
vi) Y = (2 – 3x2)a
vii) A = 5xy – 3x(y – (2 – 5x))2x 2
a.
b.
c.
d.
f.
PAGE \* MERGEFORMAT 1
Copyright©Zainab Othman
12. Given is the compound assignment statement and answer the question:
Compound Equivalent to
assignment
c += 7 Example: c = c + 7;
c-=3
c*=4
c/=2
c^=2
14. Explain the order of precedence for the following arithmetic expressions:
3*7–6+2*5/4+6
PAGE \* MERGEFORMAT 1
Copyright©Zainab Othman
a. Calculate the price after discount . The company offers 20% off for each
product.You need to insert the price of a product and the quantity of that
product.
b. Calculate the commission will be paid to a salesman. The company pays
15% commission of total sales made by the salesman. The total sales is item
price sold multiply how many item sold.
c. Ask ther user to enter his/her monthly salary. Calculate the yearly salary.
Then calculate the tax. The tax rate is 2.5% of yearly salary.
d. Calculate the deduction will be earned by a tax payer. The tax deduction for
a RM500 per child, RM8000 for his self and RM5000 for his wife. Assume
that the tax payer is a man with a wife and few children.
Prompt the user to enter the radius and height separately for the 5 steel
cylinders given density is the same for all cylinder which is 0.284.
f. A block of iron that is 9 cm long, 4.5 cm wide and 5 cm thick has a mass of
1800 g. Calculate its density in g cm-3.
mass
Given the formula for density is : density = and
volume
17. Write a C++ program to find the area of shaded region in the figure above.
Triangles A and B have exactly the same dimensions and area, where both
the length and width are equal. The user will be required to enter the
area of a triangle.
You are given the following formula for the above diagram:
PAGE \* MERGEFORMAT 1
Copyright©Zainab Othman
b) Write the complete code to solve this problem.
18. The following code contains a few syntax errors, make correction to the
errors
int main()
float a, b; int C;
return 0
PAGE \* MERGEFORMAT 1