# [程式]有請高手幫解c++題目

Create a class Rectangular_Solid with attributes length, width, and height, each of which defaults to 1.0. Provide member functions that calculate the perimeter, the area , and the volume of the rectangular solid. Also, provide set and get functions for the length, width, and height attributes. The set functions should verify that length, width, and height are each floating-point numbers larger than 0.0 and less than 100.0. Write a main function to test each member function of the Rectangle object. (Note: the default values of length, width, and height can be initialized by the constructor of Rectangular_Solid.)

Rating

這是你的作業吧？

要別人幫你寫作業　這樣不行唷 :D

2006-04-17 16:06:07 補充：

class Rectangular_solid

{

public:

Rectangular_solid()

{

length=1.0;

width=1.0;

height=1.0;

}

float calPerimeter()

{

return 4*(length+width+height);

}

float calArea()

{

return 2*(length*width+length*height+width*height);

}

float calVolume()

{

return length*width*height;

}

void set(float l,float w,float h)

{

if(l<0.0||l>100.0||w<0.0||w>100.0||h<0.0||h>100.0)

{

printf("Input error! The value should between 0.0 and 100.0!\n");

return;

}

length=l;

width=w;

height=h;

}

float getLength()

{

return length;

}

float getWidth()

{

return width;

}

float getHeight()

{

return height;

}

void test(float l,float w,float h)

{

set(l,w,h);

printf("Lentgh=%f, Width=%f, Height=%f\n",getLength(),getWidth(),getHeight());

printf("Perimeter=%f, Area=%f, Volume=%f\n",calPerimeter(),calArea(),calVolume());

}

private:

float length;

float width;

float height;

}

Source(s): 自己