Item 2 of the second week-long column type, item 2 of the second week-long column

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.