01.#include <iostream> 02.#include <cmath> 03. 04.using namespace std; 05.class Box 06.{ 07.public: 08. void volume(); 09. void area(); 10. void set(); 11. Box (int h = 18,int w = 20,int len = 36):height(h),width(w),length(len){} 12.private: 13. double length; 14. double width; 15. double height; 16.}; 17.int main() 18.{ 19. Box a[5] = { 20. 21. Box(10,12,15), 22. Box(15,18,20), 23. Box(16,20,26), 24. }; 25. 26. a[4].set(); 27. 28. cout << "the volume of a[0] is: " << endl; 29. a[0].volume(); 30. cout << "the area of a[0] is: " << endl; 31. a[0].area(); 32. 33. cout << "the volume of a[0] is: " << endl; 34. a[1].volume(); 35. cout << "the area of a[0] is: " << endl; 36. a[1].area(); 37. 38. cout << "the volume of a[0] is: " << endl; 39. a[2].volume(); 40. cout << "the area of a[0] is: " << endl; 41. a[2].area(); 42. 43. cout << "the volume of a[0] is: " << endl; 44. a[3].volume(); 45. cout << "the area of a[0] is: " << endl; 46. a[3].area(); 47. 48. cout << "the volume of a[4] is: " << endl; 49. a[4].volume(); 50. cout << "the area of a[4] is: " << endl; 51. a[4].area(); 52. 53. system("pause"); 54. 55. return 0; 56.} 57. 58.void Box::area() 59.{ 60. double ar; 61. 62. ar=2*(length * height + length * width + height * width); 63. 64. cout << ar << endl; 65. 66.} 67. 68.void Box::volume() 69.{ 70. double vol; 71. 72. vol = height * width * length; 73. 74. cout << vol << endl; 75.} 76. 77.void Box::set() 78.{ 79. cin >> height >> length >> width; 80.}