Advertisement
gosuodin

hình chữ nhật class

Jun 20th, 2016
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.31 KB | None | 0 0
  1. #include<iostream>
  2. using namespace std;
  3. class hinhchunhat {
  4. public :
  5. hinhchunhat();
  6. void set_cach(int, int);
  7. void get_canh();
  8. void dientich(int, int);
  9.  
  10. private :
  11. int chieudai;
  12. int chieurong;
  13. };
  14. class hinhhop: public hinhchunhat {
  15. private:
  16. int chieucao;
  17. int chieurong;
  18. int chieudai;
  19. public:
  20. hinhhop();
  21. void set_chieucao(int);
  22. void get_chieucao();
  23. void thetich(int, int, int);
  24. };
  25. hinhhop::hinhhop(){
  26. chieudai = 0;
  27. chieurong = 0;
  28. chieucao = 0;
  29.  
  30. }
  31. void hinhhop::set_chieucao(int chieucao) {
  32. this->chieucao = chieucao;
  33. }
  34. void hinhhop::get_chieucao() {
  35. cout << "chieu cao : " << chieucao;
  36. }
  37. void hinhhop::thetich(int chieudai, int chieurong, int chieucao) {
  38. cout << "thetich :" << chieudai*chieurong*chieucao;
  39. }
  40. hinhchunhat::hinhchunhat() {
  41. chieudai = 0;
  42. chieurong = 0;
  43. }
  44. void hinhchunhat::set_cach(int chieudai, int chieurong) {
  45. this->chieudai = chieudai;
  46. this->chieurong = chieurong;
  47. }
  48. void hinhchunhat::get_canh() {
  49. cout << chieudai << " " << chieurong;
  50. }
  51. void hinhchunhat::dientich(int chieudai, int chieurong) {
  52. cout << "dientich :" << chieudai*chieurong;
  53. }
  54.  
  55. void main() {
  56. hinhchunhat a;
  57. hinhhop b;
  58. a.set_cach(4, 6);
  59. a.get_canh();
  60. a.dientich(5, 7);
  61. b.set_cach(4, 5);
  62. b.set_chieucao(6);
  63. b.get_canh
  64. b.thetich(6, 7, 8);
  65.  
  66. system("pause");
  67. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement