Item 2 of the second week-long column type, item 2 of the second week-long column
Compile an object-based program and calculate the volume of three Bulk columns. Data members include length, width, heigth, and size. The following functions are required:
(1) input the length, width, and height of three square columns on the keyboard;
(2) Calculate the volume and surface area of the rectangular column (areas );
(3) output the volume and surface area of the three long square columns;
/** Copyright (c) 2015, School of Computer Science, Yantai University * All right reserved. * Author: Shao Shuai * file: Demo. cpp * completion time: July 15, March 14, 2015 * version: v1.0 */# include <iostream> using namespace std; class Bulk {public: double volume (); // volume double areas (); // surface area void setnum (double, double, double); private: double length; double width; double heigth ;}; double Bulk: volume () {return (length * width * heigth);} double Bulk: areas () {return (2 * length * width + 2 * length * heig Th + 2 * width * heigth);} void Bulk: setnum (double l, double w, double h) {length = l; width = w; heigth = h ;} int main () {Bulk b1, b2, b3; double l, w, h; cout <"Enter the length, width, and height of the first cube :"; cin> l> w> h; b1.setnum (l, w, h); cout <"Enter the length, width, and height of the second cube :"; cin> l> w> h; b2.setnum (l, w, h); cout <"Enter the length, width, and height of the third Cube :"; cin> l> w> h; b3.setnum (l, w, h); cout <"the first cuboid volume is:" <b1.volume () <", the surface area is: "<b1.areas () <". "<Endl; cout <" the second cuboid volume is: "<b2.volume () <", and the surface area is: "<b2.areas () <". "<Endl; cout <" the third cuboid volume is: "<b3.volume () <". The surface area is: "<b3.areas () <". "<Endl; return 0 ;}
Running result:
@ Mayuko