Nguyên An SMod
Tổng số bài gửi : 674 Experience : 1220 Danh Vọng : 19
| Tiêu đề: Ôn thi OOP lần 2 Thu May 19, 2011 11:35 pm | |
| - Code:
-
Phong.h class Phong { protected: bool status; public: Phong(); void xuat(); void datPhong(); void traPhong(); float giaPhong(); int dungLuong(); bool KT_Trong(); bool KT_Vip(); };
PhongThuong.h #include "Phong.h" class PhongThuong : public Phong { private: int coPhong; public: PhongThuong(int coPhong); void xuat(); float giaPhong(); int dungLuong(); //bool KT_Trong(); bool KT_Vip(); };
PhongVip.h #include "Phong.h" class PhongVip : public Phong { private: int hangPhong; public: PhongVip(int hangPhong); void xuat(); float giaPhong(); float khuyenMai(); int dungLuong(); //bool KT_Trong(); bool KT_Vip(); };
Phong.cpp
#include <iostream> using namespace std;
#include "Phong.h"
Phong :: Phong() { this -> status = true; }
void Phong ::datPhong() { this -> status = false; }
void Phong :: traPhong() { this ->status = true; }
bool Phong ::KT_Trong() { return this -> status; }
void Phong :: xuat() { cout << "Tinh trang: "; if(this -> status ==true) { cout << "Trong" << endl; } else cout << "Co khach" << endl; }
float Phong :: giaPhong() { return -1; }
int Phong ::dungLuong() { return 0; }
bool Phong ::KT_Vip() { return false; }
PhongThuong.cpp
#include <iostream> using namespace std;
#include "PhongThuong.h"
PhongThuong :: PhongThuong(int coPhong) :Phong() { this -> coPhong = coPhong; }
void PhongThuong :: xuat() { this ->Phong::xuat(); cout << "Co phong" << this ->coPhong << endl; }
float PhongThuong :: giaPhong() { return 5+5*this->coPhong; }
int PhongThuong ::dungLuong() { return this->coPhong; }
bool PhongThuong ::KT_Vip() { return false; }
PhongVip.cpp
#include <iostream> using namespace std;
#include "PhongVip.h"
PhongVip :: PhongVip(int hangPhong) :Phong() { this -> hangPhong = hangPhong; }
void PhongVip :: xuat() { this ->Phong::xuat(); cout << "Hang phong" << this ->hangPhong << endl; }
float PhongVip :: giaPhong() { switch (this ->hangPhong) { case 1: return 100; case 2: return 80; case 3: return 50; default: return -1; } }
int PhongVip ::dungLuong() { return this->hangPhong; }
bool PhongVip ::KT_Vip() { return false; }
main.cpp
void main() {}
Gởi đến các mem thi lần 2 môn OOP tham khảo thêm, đề thi lại giống như bài PhongKhachSan mà thầy đã ôn. Chúc mọi người thi tốt!!! |
|