Professional Documents
Culture Documents
C++ Inheritance - Polymorphism
C++ Inheritance - Polymorphism
LopHHPhang.h
#include <iostream>
#include <vector>
#include <string>
#include <sstream>
class LopDaGiac{
private:
int socanh;
protected:
vector <double> cdCanh;
public:
LopDaGiac(int socanh){
this->socanh = socanh;
cdCanh.resize(socanh, 0);
}
// pure virtual function
virtual double tinhDienTich() = 0;
virtual double tinhChuVi() = 0;
};
int main()
{
LopHinhVuong hv;
cout << "Chu vi hinh vuong: " << hv.tinhChuVi() <<endl;
cout << "Dien tich hinh vuong: " << hv.tinhDienTich()<<endl;
LopHinhChuNhat hcn;
cout << "Chu vi hinh chu nhat: " << hcn.tinhChuVi() << endl;
cout << "Dien tich hinh chu nhat: " << hcn.tinhDienTich() << endl;
getchar();
return 0;
}