Week three-manipulating the rectangular column class with an array of objects

Source: Internet
Author: User

/**copyright (c) 2014, College of Computer and Control engineering, Yantai University *all rights reserved.* file name:   . cpp*    Creator: Lenkidong * Completion Date: March 29, 2014 * Version number: v1.0*/


Problem

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;

Code

#include <iostream>using namespace Std;class bulk{public:    Bulk (double x=1.0,double y=1.0,double z=1.0): Length (x), Width (y), height (z) {}    void get ();    void display ();p rivate:    double length;    Double width;    double height;}; void Bulk::get () {    cout<< "Please enter the length and width height:";    Cin>>length>>width>>height;} void Bulk::d isplay () {    cout<< "long" <<length<< "" << "Wide" <<width<< "" << "high" <


Operation Result:

Summary of Knowledge points:

Object array

Learning experience:

Good study Day Day up

Week 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.