100+ câu trắc nghiệm Lập trình nâng cao có đáp án phần 3

Anh (Chị) hãy cho biết kết quả của đoạn lệnh sau là gì?1. class CRect { 2. int height, width;3. public :4. void setGiatri(int a, int b) {5. height = a;6. width = b;7. }8. int DT() { return (

21/25

Anh (Chị) hãy cho biết kết quả của đoạn lệnh sau là gì?

1. class CRect {

2. int height, width;

3. public :

4. void setGiatri(int a, int b) {

5. height = a;

6. width = b;

7. }

8. int DT() { return (height * width); }

9. };

10. int main() {

11. CRect a, *b, *c, *d;

12. d = new CRect[2];

13. b = new CRect;

14. c = &a;

15. a.setGiatri(1,2);

16. b->setGiatri(3,4);

17. d->setGiatri(5,6);

18. d[1].setGiatri(7,8);

19. cout << c->DT() << endl;

20. delete b;

21. delete[] d;

22. return 0; 23. }

2

12

30

56

Giải thích

Chọn đáp án A