Week 3-Manipulating the Rectangular column class with an array of objects

Source: Internet
Author: User

write an object-based program to find the volume and surface area of 5 long Fang. The data members of rectangular column class bulk include length, width (width), height (heigth) and so on.
The work and requirements to be done against the code already given are:
• You need to define a rectangular column class, and the code has given an array of objects consisting of 5 rectangular column objects B;
· The first 3 objects in the B array b[0], b[1], b[2] Direct parameters are initially initialized, the constructor needs to be defined, whereas in initialization, each object provides a different number of arguments and requires a constructor with default arguments (default to 1.0 for parameters not given)
• The 4th object B[3] is initialized with a default constructor;
• The 5th rectangular column B[4] is not initialized when defined, the design member function get_value, by the keyboard input is long, wide, high;

· The design member function output, in main, calls out the volume and surface area of these 5 long Fang;


#include <iostream>using namespace Std;class bulk{public:    Bulk (double x=1.0,double y=1.0,double z=1.0): Lengh (x), Width (y), height (z) {};    void Get_value ();    void Show ();p rivate:    double lengh;    Double width;    double height;}; void Bulk::get_value () {    cout<< "Please enter the length, width, height of the box:";    Cin>>lengh>>width>>height;} void Bulk::show () {    cout<< "surface area is:" <<2* (lengh*width+lengh*height+width*height) <<endl;    cout<< "Volume:" <<LENGH*WIDTH*HEIGHT<<ENDL;} int main () {    Bulk b[5]= {Bulk (2.3,4.5,6.7), Bulk (1.5,3.4), Bulk (10.5)};    B[4].get_value ();    for (int i=0; i<5; ++i)    {        cout<< "<<i+1<<" box "<<endl;        B[i].show ();    }    return 0;}
Operation Result:

Week 3-Manipulating the Rectangular column class with an array of objects

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.