Project three--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 is 1.0 for parameters not given)
    • The 4th Object B[3] is initialized with a default constructor;
    • The 5th rectangular column B[4] is defined without initialization, the design member function get_value, 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;
int main () {     Bulk b[5]={bulk (2.3,4.5,6.7), Bulk (1.5,3.4), Bulk (10.5)};     B[4].get_value ();     The following outputs the volume and surface area of these 5 long Fang respectively}

Reference Solutions (1):
/* All rights reserved. * File name: Test.cpp * Chen Dani * Completion Date: April 2, 2015 * version number: v1.0 */#include <iostream>using namespace Std;class bulk{public:< C0/>bulk (double x=1.0,double y=1.0,double z=1.0): Lengh (x), Width (y), height (z) {};    void Get_value ();    void display ();p rivate:    double lengh;    Double width;    double height;}; void Bulk::get_value () {    cout<< "Enter the length, width, and height of the box separately:" <<endl;    Cin>>lengh>>width>>height;} void Bulk::d isplay () {    cout<< "output long Fang Volume:" <<lengh*width*height<<endl;    cout<< "Output the surface area of the long Fang:" <<2* (lengh*width+width*height+lengh*height) <<endl;    Cout<<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 ();   B[0].display ();   B[1].display ();   B[2].display ();   B[3].display ();   B[4].display ();    return 0;}

Optimized reference Solutions (2):
<pre name= "code" class= "CPP" >/* All rights reserved.    * File name: Test.cpp * Chen Dani * Completion Date: April 2, 2015 * version number: v1.0 */#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 display ();p rivate:double lengh;    Double width; double height;};    void Bulk::get_value () {cout<< "Enter the length, width, and height of the box separately:" <<endl; Cin>>lengh>>width>>height;} void Bulk::d isplay () {cout<<, respectively, output long, wide, High: <<lengh<< "<<width<<" <

Experience: To dare to innovate, break their own, think more, continue to refuel!

Project three--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.