[Buổi 28][Kế thừa][Lab] Bài 1: Person → Student


LÀM BÀI

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

Author:
Problem types
Allowed languages
C++

Person → Student

Bối cảnh

Một Student là một Person có thêm studentId.

Bài tập tập trung vào quan hệ is-a và reuse field/method từ base.

Yêu cầu

  1. Tạo class Person giữ name và method introduce() trả name.
  2. Tạo class Student public kế thừa Person, thêm studentId.
  3. Đọc name, studentId và in name studentId thông qua object Student.

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

Phải có class Student : public Person.

Online Judge chấm output. Với bài nhạy về cấu trúc OOP, giảng viên review thêm source code để xác nhận học viên luyện đúng kỹ năng.

Input

Một dòng: name studentId (đều là token).

Output

Một dòng: name studentId.

Ràng buộc

1 ≤ độ dài mỗi token ≤ 30.

Ví dụ 1

Input

An S01

Output

An S01

Giải thích

Input tạo một Student với phần dữ liệu kế thừa từ Person là tên An và field riêng của lớp dẫn xuất là mã S01. Khi method/print của Student truy cập cả hai phần state, kết quả ghép đúng thành An S01. Ví dụ kiểm tra quan hệ is-a: Student vẫn mang đầy đủ dữ liệu Person nhưng bổ sung thông tin sinh viên.

Ví dụ 2

Input

Binh K62A01

Output

Binh K62A01

Giải thích

Với Binh K62A01, constructor lớp dẫn xuất nhận cả dữ liệu base và derived. Phần base giữ Binh, phần Student giữ K62A01; output Binh K62A01 xác nhận không làm mất state của lớp cha khi tạo object lớp con.

Thông tin học tập

  • Module: M08
  • Buổi: B28
  • Loại bài: LAB
  • Độ khó: Easy
  • Concepts: inheritance, base class, derived class, is-a
  • Giới hạn kiến thức: B01-B28
  • Time limit: 1 second(s)
  • Memory limit: 256 MB
  • Point: 100

Comments

There are no comments at the moment.

Zalo