[Buổi 24][Lớp & đối tượng][Lab] Bài 2: Method Behavior


LÀM BÀI

Points: 100
Time limit: 1.0s
Memory limit: 256M

Author:
Problem types
Allowed languages
C++

Method Behavior

Bối cảnh

Một object Rectangle nên tự biết cách tính area và perimeter từ state của chính nó.

B24 tập trung behavior gắn với object, chưa tập trung validation.

Yêu cầu

  1. Tạo class Rectangle với width,height và method area(), perimeter().
  2. Đọc w,h.
  3. In area và perimeter.

Yêu cầu tổ chức code

Phải dùng method của class để tính.

Online Judge chấm output. Giảng viên có thể review thêm cấu trúc code để xác nhận học viên luyện đúng kỹ năng OOP của buổi.

Input

Hai số nguyên w h.

Output

area perimeter.

Ràng buộc

0≤w,h≤10^9, kết quả vừa long long.

Ví dụ 1

Input

3 4

Output

12 14

Giải thích

Rectangle có width=3, height=4. Method area() dùng state object để tính 3*4=12; perimeter() tính 2*(3+4)=14. Hai method không cần nhận lại w,h qua tham số, nên output 12 14.

Ví dụ 2

Input

0 5

Output

0 10

Giải thích

Với width=0, height=5, area bằng 0 còn perimeter theo công thức vẫn là 2*(0+5)=10. Vì B24 chưa đặt invariant kích thước dương, object vẫn thực hiện behavior theo state đã nhận, output 0 10.

Thông tin học tập

  • Module: M07
  • Buổi: B24
  • Loại bài: LAB
  • Độ khó: Easy
  • Concepts: class, methods, object state, calculation
  • Giới hạn kiến thức: B01-B24
  • Time limit: 1 second(s)
  • Memory limit: 256 MB
  • Point: 100

Comments

There are no comments at the moment.

Zalo