Đa hình (polymorphism) trong C++
#include<iostream>
using namespace std;
//tao base class person
class person
{
public:
int id;
string name;
void input();
void output();
};
void person::input()
{
cout<<"id:";
cin>>id;
cin.ignore();
cout<<"Name:";
getline(cin,name);
}
void person::output()
{
cout<<id<<" "<<name<<endl;
}
//Tao sub-class student
class student:public person
{
public:
int studId;
float GPA;
void input()
{
//goi phuong thuc cua lop cha
person::input();
cout<<"student id:";
cin>>this->studId;
cout<<"GPA:";
cin>>this->GPA;
}
void output()
{
//goi phuong thuc cua lop cha
person::output();
cout<<this->studId<<" "<<this->GPA<<endl;
}
};
int main()
{
student st;
st.input();
st.output();
return 0;
}
Trương Đình Huy
- 5 Proven Strategies to Conquer B1 Sentence Transformation
- Effective Strategies for Developing Natural English Pronunciation among University Students
- Kĩ năng tự học của sinh viên năm nhất
- TỔNG QUAN PHƯƠNG PHÁP LUẬN VÀ ỨNG DỤNG CỦA PHÂN TÍCH TRẮC LƯỢNG THƯ MỤC (BIBLIOMETRICS) TRONG NGHIÊN CỨU KHOA HỌC HIỆN ĐẠI

