当前位置:   article > 正文

c++day2

c++day2
  1. #include <iostream>
  2. using namespace std;
  3. class Rect
  4. {
  5. private:
  6. int width;
  7. int hight;
  8. public:
  9. void init(int w, int h);
  10. void set_w(int w);
  11. void set_h(int h);
  12. void show();
  13. };
  14. void Rect::init(int w, int h)
  15. {
  16. width = w;
  17. hight = h;
  18. }
  19. void Rect::set_w(int w)
  20. {
  21. width = w;
  22. }
  23. void Rect::set_h(int h)
  24. {
  25. hight = h;
  26. }
  27. void Rect::show()
  28. {
  29. cout << "width = " << width << "\t hight = " << hight << "\t周长 = " << 2*(width+hight) << endl;
  30. cout << "width = " << width << "\t hight = " << hight << "\t面积 = " << width*hight << endl;
  31. }
  32. int main()
  33. {
  34. Rect re;
  35. re.init(4, 5);
  36. re.show();
  37. re.set_h(10);
  38. re.show();
  39. re.set_w(10);
  40. re.show();
  41. return 0;
  42. }

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/article/detail/47851
推荐阅读
相关标签
  

闽ICP备14008679号