Ahad, 16 Januari 2011

latihan asas

Basic C++ Exercise

1. Which of the following is true?
A. 1
B. 66
C. .1
D. -1
E. All of the above

2. Which of the following is the boolean operator for logical-and?
A. &
B. &&
D. &

3. Evaluate !(1 && !(0 1)).
A. True
B. False
C. Unevaluatable

4. Which of the following shows the correct syntax for an if statement?
A. if expression
B. if { expression
C. if ( expression )
D. expression if

5. 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. Programs do not return a value.

6. What is the only function all C++ programs must contain?
A. start()
B. system()
C. main()
D. program()

7. What punctuation is used to signal the beginning and end of code blocks?
A. { }
B. -> and <-
D. ( and )
8. What punctuation ends most lines of C++ code?
A. .
B. ;
C. :
D. '
9. Which of the following is a correct comment?
A. */ Comments */
B. ** Comment **
C. /* Comment */
D. { Comment }
10. Which of the following is not a correct variable type?
A. float
B. real
C. int
D. Double
11. Which of the following is the correct operator to compare two variables?
A. :=
B. =
C. equal
D. ==
12. Which follows the case statement?
A. :
B. ;
C. -
D. A newline
13. What is required to avoid falling through from one case to the next?
A. end;
B. break;
C. Stop;
D. A semicolon.
14. What keyword covers unhandled possibilities?
A. all
B. contingency
C. default
D. Other
15. What is the result of the following code?
int x=0; switch(x)
case 1: cout<<"One";
case 0: cout<<"Zero";
case 2: cout<<"Hello World";
A. One
B. Zero
C. Hello WorlD
D. ZeroHello World
Section B:
1. Write a program to calculate area of triangle. User to key in the value of side of rectangle. (Hint: ½*width*height)
p/s: latihan ini adalah untuk menambahkan ilmu semata-mata dan persediaan midterm.
Good Luck on ur exam.

3 ulasan:

  1. 1. Which of the following is true?
    A. 1
    B. 66
    C. .1
    D. -1

    Untuk makluman.
    Dalam konsep true and false.
    Compiler memahami 1 sbg true dan 0 bg false.

  2. ohh.... ingat dia tnya apa laa...
    better soalan dia berbunyi begini..
    "Which of the following bring the meaning of true?"